mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 12:29:20 +00:00
@@ -22,15 +22,17 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.AxisAlignedBB;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Data
|
||||
public class PlannedPiece {
|
||||
private IrisPosition position;
|
||||
@@ -45,6 +47,12 @@ public class PlannedPiece {
|
||||
private AxisAlignedBB box;
|
||||
@EqualsAndHashCode.Exclude
|
||||
private PlannedStructure structure;
|
||||
@EqualsAndHashCode.Exclude
|
||||
@Setter(AccessLevel.NONE)
|
||||
private ParentConnection parent = null;
|
||||
@EqualsAndHashCode.Exclude
|
||||
@Setter(AccessLevel.NONE)
|
||||
private KMap<IrisJigsawPieceConnector, IrisPosition> realPositions;
|
||||
|
||||
public PlannedPiece(PlannedStructure structure, IrisPosition position, IrisJigsawPiece piece) {
|
||||
this(structure, position, piece, 0, 0, 0);
|
||||
@@ -66,6 +74,7 @@ public class PlannedPiece {
|
||||
this.object.setLoadKey(piece.getObject());
|
||||
this.ogObject.setLoadKey(piece.getObject());
|
||||
this.connected = new KList<>();
|
||||
this.realPositions = new KMap<>();
|
||||
|
||||
}
|
||||
|
||||
@@ -124,11 +133,21 @@ public class PlannedPiece {
|
||||
return c;
|
||||
}
|
||||
|
||||
public boolean connect(IrisJigsawPieceConnector c) {
|
||||
if (piece.getConnectors().contains(c)) {
|
||||
return connected.addIfMissing(c);
|
||||
}
|
||||
public KList<IrisJigsawPieceConnector> getChildConnectors() {
|
||||
ParentConnection pc = getParent();
|
||||
KList<IrisJigsawPieceConnector> c = getConnected().copy();
|
||||
if (pc != null) c.removeIf(i -> i.equals(pc.connector));
|
||||
return c;
|
||||
}
|
||||
|
||||
public boolean connect(IrisJigsawPieceConnector c, PlannedPiece p, IrisJigsawPieceConnector pc) {
|
||||
if (piece.getConnectors().contains(c) && p.getPiece().getConnectors().contains(pc)) {
|
||||
if (connected.contains(c) || p.connected.contains(pc)) return false;
|
||||
connected.add(c);
|
||||
p.connected.add(pc);
|
||||
p.parent = new ParentConnection(this, c, p, pc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -162,4 +181,27 @@ public class PlannedPiece {
|
||||
public boolean isFull() {
|
||||
return connected.size() >= piece.getConnectors().size();
|
||||
}
|
||||
|
||||
public void setRealPositions(int x, int y, int z, IObjectPlacer placer) {
|
||||
boolean isUnderwater = piece.getPlacementOptions().isUnderwater();
|
||||
for (IrisJigsawPieceConnector c : piece.getConnectors()) {
|
||||
var pos = c.getPosition().add(new IrisPosition(x, 0, z));
|
||||
if (y < 0) {
|
||||
pos.setY(pos.getY() + placer.getHighest(pos.getX(), pos.getZ(), getData(), isUnderwater) + (object.getH() / 2));
|
||||
} else {
|
||||
pos.setY(pos.getY() + y);
|
||||
}
|
||||
realPositions.put(c, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public record ParentConnection(PlannedPiece parent, IrisJigsawPieceConnector parentConnector, PlannedPiece self, IrisJigsawPieceConnector connector) {
|
||||
public IrisPosition getTargetPosition() {
|
||||
var pos = parent.realPositions.get(parentConnector);
|
||||
if (pos == null) return null;
|
||||
return pos.add(new IrisPosition(parentConnector.getDirection().toVector()))
|
||||
.sub(connector.getPosition())
|
||||
.sub(new IrisPosition(self.object.getCenter()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public class PlannedStructure {
|
||||
options = i.getPiece().getPlacementOptions();
|
||||
options.getRotation().setEnabled(false);
|
||||
options.setRotateTowardsSlope(false);
|
||||
options.setWarp(new IrisGeneratorStyle(NoiseStyle.FLAT));
|
||||
} else {
|
||||
options.setMode(i.getPiece().getPlaceMode());
|
||||
}
|
||||
@@ -125,6 +126,17 @@ public class PlannedStructure {
|
||||
height = i.getStructure().getStructure().getLockY();
|
||||
}
|
||||
|
||||
PlannedPiece.ParentConnection connection = i.getParent();
|
||||
if (connection != null && connection.connector().isLockY()) {
|
||||
var pos = connection.getTargetPosition();
|
||||
if (pos != null) {
|
||||
height = pos.getY();
|
||||
offset = 0;
|
||||
} else {
|
||||
Iris.warn("Failed to get target position for " + v.getLoadKey());
|
||||
}
|
||||
}
|
||||
|
||||
height += offset + (v.getH() / 2);
|
||||
|
||||
if (options.getMode().equals(ObjectPlaceMode.PAINT)) {
|
||||
@@ -133,6 +145,7 @@ public class PlannedStructure {
|
||||
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
JigsawPieceContainer container = JigsawPieceContainer.toContainer(i.getPiece());
|
||||
i.setRealPositions(xx, height, zz, placer);
|
||||
return v.place(xx, height, zz, placer, options, rng, (b, data) -> {
|
||||
e.set(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||
e.set(b.getX(), b.getY(), b.getZ(), container);
|
||||
@@ -247,8 +260,7 @@ public class PlannedStructure {
|
||||
return false;
|
||||
}
|
||||
|
||||
piece.connect(pieceConnector);
|
||||
test.connect(testConnector);
|
||||
piece.connect(pieceConnector, test, testConnector);
|
||||
pieces.add(test);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -79,6 +79,9 @@ public class IrisJigsawPieceConnector {
|
||||
@Required
|
||||
private IrisDirection direction = IrisDirection.UP_POSITIVE_Y;
|
||||
|
||||
@Desc("Lock the Y position of this connector")
|
||||
private boolean lockY = false;
|
||||
|
||||
public String toString() {
|
||||
return direction.getFace().name() + "@(" + position.getX() + "," + position.getY() + "," + position.getZ() + ")";
|
||||
}
|
||||
|
||||
@@ -101,6 +101,11 @@ public class IrisObjectRotation {
|
||||
i.setPosition(rotate(i.getPosition()));
|
||||
i.setDirection(rotate(i.getDirection()));
|
||||
}
|
||||
try {
|
||||
var translate = piece.getPlacementOptions().getTranslate();
|
||||
var pos = rotate(new IrisPosition(translate.getX(), translate.getY(), translate.getZ()));
|
||||
translate.setX(pos.getX()).setY(pos.getY()).setZ(pos.getZ());
|
||||
} catch (NullPointerException ignored) {}
|
||||
|
||||
return piece;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ libraries:
|
||||
- commons-io:commons-io:2.13.0
|
||||
- io.timeandspace:smoothie-map:2.0.2
|
||||
- com.google.guava:guava:31.0.1-jre
|
||||
- com.google.code.gson:gson:2.8.9
|
||||
- com.google.code.gson:gson:2.10.1
|
||||
- org.zeroturnaround:zt-zip:1.14
|
||||
- it.unimi.dsi:fastutil:8.5.6
|
||||
- org.ow2.asm:asm:9.2
|
||||
|
||||
Reference in New Issue
Block a user