Implement horizontal cutter

This commit is contained in:
Stone_Red
2022-05-20 15:44:26 +02:00
parent fa22fa23ff
commit a8eb398b0a
4 changed files with 87 additions and 10 deletions
@@ -0,0 +1,65 @@
package com.yes.yes.behaviours;
import com.yes.yes.utils.*;
public class CutItemBehaviour extends Component {
private final Orientation orientation;
private final String receiveDataKey;
private final String offerDataKey1;
private final String offerDataKey2;
private final int processingDuration;
private int progress = 0;
public CutItemBehaviour(Entity entity, BlockContainer blockContainer, Orientation orientation, String receiveDataKey, String offerDataKey1, String offerDataKey2, int processingDuration) {
super(entity, blockContainer);
this.orientation = orientation;
this.receiveDataKey = receiveDataKey;
this.offerDataKey1 = offerDataKey1;
this.offerDataKey2 = offerDataKey2;
this.processingDuration = processingDuration;
}
@Override
public void initialize() {
}
@Override
public void update() {
if (progress > processingDuration) {
if (parent.getData(offerDataKey1) != null || parent.getData(offerDataKey2) != null) return;
Item half1 = new Item();
Item half2 = new Item();
Item item = parent.getData(receiveDataKey);
for (int i = 0; i < 4; i++) {
if (orientation == Orientation.Horizontal) {
half1.setPart(i, 0, item.getPart(i, 0));
half1.setPart(i, 1, item.getPart(i, 1));
half2.setPart(i, 2, item.getPart(i, 2));
half2.setPart(i, 3, item.getPart(i, 3));
} else {
half1.setPart(i, 0, item.getPart(i, 0));
half1.setPart(i, 2, item.getPart(i, 2));
half2.setPart(i, 1, item.getPart(i, 1));
half2.setPart(i, 3, item.getPart(i, 3));
}
}
parent.setData(offerDataKey1, half1);
parent.setData(offerDataKey2, half2);
parent.setData(receiveDataKey, null);
progress = 0;
} else if (parent.getData(receiveDataKey) != null) {
progress++;
}
}
@Override
public void destroy() {
}
}
@@ -1,16 +1,17 @@
package com.yes.yes.entities.machines;
import com.yes.yes.behaviours.DestroyBehaviour;
import com.yes.yes.behaviours.CutItemBehaviour;
import com.yes.yes.behaviours.OfferBehaviour;
import com.yes.yes.behaviours.PlaceBehaviour;
import com.yes.yes.behaviours.ReceiveBehaviour;
import com.yes.yes.utils.BlockContainer;
import com.yes.yes.utils.Direction;
import com.yes.yes.utils.Entity;
import com.yes.yes.utils.Orientation;
import com.yes.yes.world.Chunk;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
public class Cutter extends Entity {
public Cutter() {
@@ -29,7 +30,6 @@ public class Cutter extends Entity {
p.setFill(new Color(1, 1, 1, 0.5));
this.getChildren().addAll(c, p);
}
@@ -38,6 +38,9 @@ public class Cutter extends Entity {
this();
this.addBehaviour(new PlaceBehaviour(this, blockContainer));
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "Item"));
//TODO: Add split/modify behaviour
this.addBehaviour(new CutItemBehaviour(this, blockContainer, Orientation.Horizontal, "ReceivedItem", "OfferItemLeft", "OfferItemRight", 5));
this.addBehaviour(new ReceiveBehaviour(this, blockContainer, Direction.DOWN, "ReceivedItem"));
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.LEFT, "OfferItemLeft"));
this.addBehaviour(new OfferBehaviour(this, blockContainer, Direction.RIGHT, "OfferItemRight"));
}
}
+5 -2
View File
@@ -14,11 +14,14 @@ public class Item extends javafx.scene.Group implements Cloneable {
this.getChildren().remove(parts[layer][section]);
}
part.rotate(section);
parts[layer][section] = part;
if (part == null) return;
part.rotate(section);
part.getTransforms().add(new Scale(-layer * 0.25f + 1f, -layer * 0.25f + 1f));
parts[layer][section] = part;
this.getChildren().add(part);
}
@@ -0,0 +1,6 @@
package com.yes.yes.utils;
public enum Orientation {
Horizontal,
Vertical
}