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