Improve rotation functionality

This commit is contained in:
Stone_Red
2022-05-07 14:23:46 +02:00
parent 6867f4ec10
commit 30d4d70ae8
5 changed files with 15 additions and 13 deletions
@@ -28,7 +28,6 @@ public class ConveyorBehaviour extends Component {
public void update() { public void update() {
if (count > delay) { if (count > delay) {
if (parent.getData(offerDataKey) != null) return; if (parent.getData(offerDataKey) != null) return;
if (parent.getData(receiveDataKey) == null) return;
parent.setData(offerDataKey, parent.getData(receiveDataKey)); parent.setData(offerDataKey, parent.getData(receiveDataKey));
count = 0; count = 0;
@@ -37,8 +36,7 @@ public class ConveyorBehaviour extends Component {
count++; count++;
} }
if(isConveyed && parent.getData(offerDataKey) == null) if (isConveyed && parent.getData(offerDataKey) == null) {
{
parent.setData(receiveDataKey, null); parent.setData(receiveDataKey, null);
parent.trigger(receiveDataKey + "Changed", null); parent.trigger(receiveDataKey + "Changed", null);
isConveyed = false; isConveyed = false;
@@ -20,13 +20,13 @@ public class ItemBehaviour extends Component {
} }
private void itemChanged(Item item) { private void itemChanged(Item item) {
System.out.println("Running item update"); //System.out.println("Running item update");
Platform.runLater(() -> { Platform.runLater(() -> {
this.itemGroup.getChildren().clear(); this.itemGroup.getChildren().clear();
if (item != null) if (item != null)
this.itemGroup.getChildren().add(item); this.itemGroup.getChildren().add(item);
}); });
System.out.println("Finished item update"); //System.out.println("Finished item update");
} }
@Override @Override
@@ -44,7 +44,7 @@ public class ItemBehaviour extends Component {
@Override @Override
public void update() { public void update() {
System.out.println("Destroyed:" + parent.getData("destroyed"));
} }
@Override @Override
@@ -52,11 +52,11 @@ public class GameManager {
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
System.out.println("Finished tick!"); //System.out.println("Finished tick!");
}, 0, 1, TimeUnit.SECONDS); }, 0, 1, TimeUnit.SECONDS);
GlobalEventHandler.addListener("timerTick", this, (__) -> { GlobalEventHandler.addListener("timerTick", this, (__) -> {
System.out.println("Tick!"); //System.out.println("Tick!");
}); });
GlobalEventHandler.addListener("closing", this, (__) -> executor.shutdown()); GlobalEventHandler.addListener("closing", this, (__) -> executor.shutdown());
} }
@@ -7,8 +7,6 @@ import com.yes.yes.world.World;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.*; import javafx.scene.input.*;
import java.util.Random;
public class PlayerManager { public class PlayerManager {
private static final KeyCombination LEFT_KEY = new KeyCodeCombination(KeyCode.A); private static final KeyCombination LEFT_KEY = new KeyCodeCombination(KeyCode.A);
@@ -19,6 +17,7 @@ public class PlayerManager {
private final World world; private final World world;
private final BuildBox buildBox; private final BuildBox buildBox;
private Coordinate chunkPos = new Coordinate(0, 0); private Coordinate chunkPos = new Coordinate(0, 0);
private int currentRotation = 0;
public PlayerManager(World world, BuildBox buildBox) { public PlayerManager(World world, BuildBox buildBox) {
this.world = world; this.world = world;
@@ -44,6 +43,7 @@ public class PlayerManager {
Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate); Coordinate chunkCoordinate = Coordinate.WorldToChunkCoordinate(mouseCoordinate);
Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate); Coordinate blockCoordinate = Coordinate.WorldToChunkBlock(mouseCoordinate);
try { try {
Class<?>[] types = new Class<?>[1]; Class<?>[] types = new Class<?>[1];
types[0] = BlockContainer.class; types[0] = BlockContainer.class;
@@ -59,10 +59,15 @@ public class PlayerManager {
Chunk chunk = world.getChunk(chunkCoordinate); Chunk chunk = world.getChunk(chunkCoordinate);
Entity oldEntity = chunk.getEntity(blockCoordinate); Entity oldEntity = chunk.getEntity(blockCoordinate);
if(oldEntity != null && oldEntity.getClass().getSimpleName() == entity.getClass().getSimpleName()) { if (oldEntity != null && oldEntity.getClass().getSimpleName() == entity.getClass().getSimpleName()) {
entity.setRotation(oldEntity.getRotation() + 1); if (mouse.getButton() == MouseButton.PRIMARY)
currentRotation = oldEntity.getRotation() + 1;
else
currentRotation = oldEntity.getRotation() - 1;
} }
entity.setRotation(currentRotation);
chunk.setEntity(entity, blockCoordinate); chunk.setEntity(entity, blockCoordinate);
entity.initialize(); entity.initialize();
@@ -47,7 +47,6 @@ public class Chunk extends GridPane {
Entity entity = getEntity(pos); Entity entity = getEntity(pos);
if (entity != null) { if (entity != null) {
entity.setData("destroyed", true);
entity.destroy(); entity.destroy();
} }
this.getChildren().remove(entity); this.getChildren().remove(entity);