Accept items from all directions (Conveyor belt) add simple rotation on place

This commit is contained in:
Stone_Red
2022-05-06 20:46:25 +02:00
parent a604ce10fe
commit 00c96a42b8
4 changed files with 20 additions and 9 deletions
@@ -26,7 +26,7 @@ public class ConveyorBehaviour extends Component {
@Override
public void update() {
if (count >= delay) {
if (count > delay) {
if (parent.getData(offerDataKey) != null) return;
if (parent.getData(receiveDataKey) == null) return;
@@ -40,6 +40,7 @@ public class ConveyorBehaviour extends Component {
if(isConveyed && parent.getData(offerDataKey) == null)
{
parent.setData(receiveDataKey, null);
parent.trigger(receiveDataKey + "Changed", null);
isConveyed = false;
}
}
@@ -43,5 +43,6 @@ public class ItemBehaviour extends Component {
@Override
public void update() {
System.out.println("Destroyed:" + parent.getData("destroyed"));
}
}
@@ -26,6 +26,8 @@ public class ConveyorBelt extends Entity {
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
this.addBehaviour(new ItemBehaviour(this, blockContainer,"ReceivedItem"));
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.DOWN, "ReceivedItem"));
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.LEFT, "ReceivedItem"));
this.addBehaviour(new RecieveBehaviour(this, blockContainer, Direction.RIGHT, "ReceivedItem"));
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.UP, "OfferItem"));
this.addBehaviour(new ConveyorBehaviour(this,blockContainer, "ReceivedItem","OfferItem", 1));
}
@@ -27,21 +27,19 @@ public class PlayerManager {
public void initialize() {
Scene scene = world.getScene();
scene.setOnKeyPressed(this::ProcessKeyPress);
scene.setOnKeyPressed(this::processKeyPress);
scene.widthProperty().addListener((e) -> redrawChunks());
scene.heightProperty().addListener((e) -> redrawChunks());
world.setOnMouseClicked(this::ProcessClick);
world.setOnMouseClicked(this::processClick);
world.setTranslateX(Integer.MAX_VALUE / -5000d);
world.setTranslateY(Integer.MAX_VALUE / -5000d);
redrawChunks();
}
Random random = new Random();
private void ProcessClick(MouseEvent mouse) {
private void processClick(MouseEvent mouse) {
Coordinate mouseCoordinate = new Coordinate((int) mouse.getX(), (int) mouse.getY());
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
@@ -57,15 +55,24 @@ public class PlayerManager {
return;
Entity entity = (Entity) registryEntry.getEntity().getConstructor(types).newInstance(blockContainer);
world.getChunk(chunkCoordinate).setEntity(entity, blockCoordinate);
//entity.setRotation(random.nextInt(0,4));
Chunk chunk = world.getChunk(chunkCoordinate);
Entity oldEntity = chunk.getEntity(blockCoordinate);
if(oldEntity != null && oldEntity.getClass().getSimpleName() == entity.getClass().getSimpleName()) {
oldEntity.setData("destroyed", true);
entity.setRotation(oldEntity.getRotation() + 1);
}
chunk.setEntity(entity, blockCoordinate);
entity.initialize();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void ProcessKeyPress(KeyEvent key) {
private void processKeyPress(KeyEvent key) {
if (LEFT_KEY.match(key)) {
world.setTranslateX(world.getTranslateX() + 45);
}