Skip to content

Commit

Permalink
Schematic rotation: retain tile entity data, ignore angle:0 properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 18, 2021
1 parent 02b4c7f commit 2414ced
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,22 @@ public void execute(final ScriptEntry scriptEntry) {
scriptEntry.setFinished(true);
return;
}
final int angleRaw = angle.asInt();
final CuboidBlockSet schematic = schematics.get(name.asString().toUpperCase());
Runnable rotateRunnable = () -> {
int ang = angle.asInt();
int ang = angleRaw;
while (ang < 0) {
ang = 360 + ang;
}
while (ang >= 360) {
ang -= 360;
}
ang = 360 - ang;
while (ang > 0) {
ang -= 90;
schematics.get(name.asString().toUpperCase()).rotateOne();
if (ang != 0) {
ang = 360 - ang;
while (ang > 0) {
ang -= 90;
schematic.rotateOne();
}
}
Bukkit.getScheduler().runTask(Denizen.getInstance(), () -> scriptEntry.setFinished(true));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public FullBlockData(BlockData data) {
this.data = data;
}

public FullBlockData(BlockData data, CompoundTag tileEntityData, MapTag flags) {
this.data = data;
this.tileEntityData = tileEntityData;
this.flags = flags;
}

public static BlockFace rotateFaceOne(BlockFace face) {
switch (face) {
case NORTH:
Expand Down Expand Up @@ -115,23 +121,23 @@ public FullBlockData rotateOne() {
((Orientable) newData).setAxis(Axis.X);
break;
}
return new FullBlockData(newData);
return new FullBlockData(newData, tileEntityData, flags);
}
else if (data instanceof Rotatable) {
BlockData newData = data.clone();
((Rotatable) newData).setRotation(rotateFaceOne(((Rotatable) data).getRotation()));
return new FullBlockData(newData);
return new FullBlockData(newData, tileEntityData, flags);
}
else if (data instanceof Directional) {
BlockData newData = data.clone();
((Directional) newData).setFacing(rotateFaceOne(((Directional) data).getFacing()));
return new FullBlockData(newData);
return new FullBlockData(newData, tileEntityData, flags);

}
else if (data instanceof Rail) {
BlockData newData = data.clone();
((Rail) newData).setShape(rotateRailShapeOne(((Rail) data).getShape()));
return new FullBlockData(newData);
return new FullBlockData(newData, tileEntityData, flags);
}
return this;
}
Expand Down

0 comments on commit 2414ced

Please sign in to comment.