Skip to content

Commit

Permalink
schematic rotation fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 5, 2021
1 parent 7746cf8 commit 00c751b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
Expand Up @@ -73,6 +73,7 @@ public void run(ReplaceableTagEvent event) {
// The 'create' option requires a cuboid region and a center location as input. This will create a new schematic in memory based on world data.
//
// The "rotate" and "flip_x/y/z" options will apply the change to the copy of the schematic in memory, to later be pasted or saved.
// This will rotate the set of blocks itself, the relative origin, and any directional blocks inside the schematic.
//
// The "delayed" option makes the command non-instant. This is recommended for large schematics.
// For 'save', 'load', and 'rotate', this processes async to prevent server lockup.
Expand Down
Expand Up @@ -169,11 +169,11 @@ public void rotateOne() {
int index = 0;
int cx = center_x;
center_x = center_z;
center_z = cx;
center_z = x_width - cx;
for (int x = 0; x < z_height; x++) {
for (int y = 0; y < y_length; y++) {
for (int z = x_width - 1; z >= 0; z--) {
bd[index++] = blockAt(z, y, x);
bd[index++] = blockAt(z, y, x).rotateOne();
}
}
}
Expand Down
Expand Up @@ -2,8 +2,10 @@

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import org.bukkit.Axis;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.*;

public class FullBlockData {

Expand All @@ -16,6 +18,102 @@ public FullBlockData(BlockData data) {
this.data = data;
}

public static BlockFace rotateFaceOne(BlockFace face) {
switch (face) {
case NORTH:
return BlockFace.WEST;
case EAST:
return BlockFace.NORTH;
case SOUTH:
return BlockFace.EAST;
case WEST:
return BlockFace.SOUTH;
case NORTH_EAST:
return BlockFace.NORTH_WEST;
case NORTH_WEST:
return BlockFace.SOUTH_WEST;
case SOUTH_WEST:
return BlockFace.SOUTH_EAST;
case SOUTH_EAST:
return BlockFace.NORTH_EAST;
case NORTH_NORTH_EAST:
return BlockFace.WEST_NORTH_WEST;
case NORTH_NORTH_WEST:
return BlockFace.WEST_SOUTH_WEST;
case SOUTH_SOUTH_WEST:
return BlockFace.EAST_SOUTH_EAST;
case SOUTH_SOUTH_EAST:
return BlockFace.EAST_NORTH_EAST;
case EAST_NORTH_EAST:
return BlockFace.NORTH_NORTH_WEST;
case WEST_NORTH_WEST:
return BlockFace.SOUTH_SOUTH_WEST;
case WEST_SOUTH_WEST:
return BlockFace.SOUTH_SOUTH_EAST;
case EAST_SOUTH_EAST:
return BlockFace.NORTH_NORTH_EAST;
}
return face;
}

public static Rail.Shape rotateRailShapeOne(Rail.Shape shape) {
switch (shape) {
case NORTH_SOUTH:
return Rail.Shape.EAST_WEST;
case EAST_WEST:
return Rail.Shape.NORTH_SOUTH;
case ASCENDING_EAST:
return Rail.Shape.ASCENDING_NORTH;
case ASCENDING_WEST:
return Rail.Shape.ASCENDING_SOUTH;
case ASCENDING_NORTH:
return Rail.Shape.ASCENDING_WEST;
case ASCENDING_SOUTH:
return Rail.Shape.ASCENDING_EAST;
case SOUTH_EAST:
return Rail.Shape.NORTH_EAST;
case SOUTH_WEST:
return Rail.Shape.SOUTH_EAST;
case NORTH_WEST:
return Rail.Shape.SOUTH_WEST;
case NORTH_EAST:
return Rail.Shape.NORTH_WEST;
}
return shape;
}

public FullBlockData rotateOne() {
if (data instanceof Orientable) {
BlockData newData = data.clone();
switch (((Orientable) data).getAxis()) {
case X:
((Orientable) newData).setAxis(Axis.Z);
break;
case Z:
((Orientable) newData).setAxis(Axis.X);
break;
}
return new FullBlockData(newData);
}
else if (data instanceof Rotatable) {
BlockData newData = data.clone();
((Rotatable) newData).setRotation(rotateFaceOne(((Rotatable) data).getRotation()));
return new FullBlockData(newData);
}
else if (data instanceof Directional) {
BlockData newData = data.clone();
((Directional) newData).setFacing(rotateFaceOne(((Directional) data).getFacing()));
return new FullBlockData(newData);

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

public BlockData data;

public CompoundTag tileEntityData;
Expand Down

0 comments on commit 00c751b

Please sign in to comment.