mirror of
https://github.com/Stefan-5422/School-Programming-Projekt-022022.git
synced 2026-09-04 00:46:01 +02:00
Add Conveyor belts and only accept items when data is ´null`
The conveyor belts work, but they are also kind of broken at the moment. Have fun!
This commit is contained in:
@@ -23,7 +23,7 @@ public class ItemBehaviour extends Component {
|
|||||||
System.out.println("Running item update");
|
System.out.println("Running item update");
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
this.itemGroup.getChildren().clear();
|
this.itemGroup.getChildren().clear();
|
||||||
this.itemGroup.getChildren().add(this.parent.getData(dataKey));
|
this.itemGroup.getChildren().add(item);
|
||||||
});
|
});
|
||||||
System.out.println("Finished item update");
|
System.out.println("Finished item update");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ public class RecieveBehaviour extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void receive(Item item) {
|
void receive(Item item) {
|
||||||
if (offerer == null)
|
if (offerer == null) return;
|
||||||
return;
|
if(this.parent.getData(dataKey) != null) return;
|
||||||
|
|
||||||
this.parent.setData(dataKey, item);
|
this.parent.setData(dataKey, item);
|
||||||
this.parent.trigger(dataKey + "Changed", item);
|
this.parent.trigger(dataKey + "Changed", item);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.yes.yes.entities.machines;
|
||||||
|
|
||||||
|
import com.yes.yes.behaviours.*;
|
||||||
|
import com.yes.yes.utils.BlockContainer;
|
||||||
|
import com.yes.yes.utils.Direction;
|
||||||
|
import com.yes.yes.utils.Entity;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Polygon;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
|
public class ConveyorBelt extends Entity {
|
||||||
|
public ConveyorBelt() {
|
||||||
|
super();
|
||||||
|
Polygon t = new Polygon();
|
||||||
|
t.getPoints().addAll(
|
||||||
|
25.0,0.0,
|
||||||
|
0.0,50.0,
|
||||||
|
50.0,50.0);
|
||||||
|
t.setFill(new Color(0,0,0,1));
|
||||||
|
|
||||||
|
this.getChildren().addAll(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConveyorBelt(BlockContainer blockContainer) {
|
||||||
|
this();
|
||||||
|
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
|
||||||
|
this.addBehaviour(new ItemBehaviour(this, blockContainer,"Item"));
|
||||||
|
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
|
||||||
|
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "Item"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.yes.yes.managers;
|
package com.yes.yes.managers;
|
||||||
|
|
||||||
|
import com.yes.yes.entities.machines.ConveyorBelt;
|
||||||
import com.yes.yes.entities.machines.GeneratorMachine;
|
import com.yes.yes.entities.machines.GeneratorMachine;
|
||||||
import com.yes.yes.entities.machines.TestMachine;
|
import com.yes.yes.entities.machines.TestMachine;
|
||||||
import com.yes.yes.entities.machines.TestMachine2;
|
import com.yes.yes.entities.machines.TestMachine2;
|
||||||
@@ -36,6 +37,7 @@ public class GameManager {
|
|||||||
EntityRegistry.register(new RegistryEntry("test", "test receive machine", TestMachine.class));
|
EntityRegistry.register(new RegistryEntry("test", "test receive machine", TestMachine.class));
|
||||||
EntityRegistry.register(new RegistryEntry("test2", "test offer machine", TestMachine2.class));
|
EntityRegistry.register(new RegistryEntry("test2", "test offer machine", TestMachine2.class));
|
||||||
EntityRegistry.register(new RegistryEntry("generator", "generator", GeneratorMachine.class));
|
EntityRegistry.register(new RegistryEntry("generator", "generator", GeneratorMachine.class));
|
||||||
|
EntityRegistry.register(new RegistryEntry("conveyorBelt", "Conveyor Belt", ConveyorBelt.class));
|
||||||
} catch (AlreadyExistsException e) {
|
} catch (AlreadyExistsException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class PlayerManager {
|
|||||||
|
|
||||||
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
|
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
|
||||||
world.getChunk(chunkCoordinate).setEntity(entity, blockCoordinate);
|
world.getChunk(chunkCoordinate).setEntity(entity, blockCoordinate);
|
||||||
entity.setRotation(random.nextInt(0,4));
|
//entity.setRotation(random.nextInt(0,4));
|
||||||
entity.initialize();
|
entity.initialize();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
|||||||
Reference in New Issue
Block a user