如何将原理图旋转90度或180度?我创建了生成器,我想制作自动原理图粘贴。标准旋转的粘贴原理图非常简单,但我需要旋转90度或180度。
public static void SyncPaste(World world, Location loc, File file, boolean air) {
try {
FileInputStream stream = new FileInputStream(file);
NBTInputStream nbtStream = new NBTInputStream(stream);
CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
stream.close();
nbtStream.close();
if (!schematicTag.getName().equals("Schematic")) {
throw new Exception("Tag \"Schematic\" does not exist or is not first");
}
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) {
throw new Exception("Schematic file is missing a \"Blocks\" tag");
}
String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
if (!materials.equals("Alpha")) {
throw new Exception("Schematic file is not an Alpha schematic");
}
short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
int offsetX = getChildTag(schematic, "WEOffsetX", IntTag.class).getValue();
int offsetY = getChildTag(schematic, "WEOffsetY", IntTag.class).getValue();
int offsetZ = getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue();
byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
byte[] rot = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
AffineTransform at = new AffineTransform();
at.translate(-(width/2), -(height/2));
Block block = new Location(world, at.getTranslateX() + offsetX + loc.getX(), at.getTranslateY() + offsetY + loc.getY(), z + offsetZ + loc.getZ()).getBlock();
if (air == false && Material.getMaterial(blockData[index]) != Material.AIR) {
if (blocks[index] != 0) {
block.setTypeIdAndData(blocks[index], blockData[index], true);
} else {
throw new Exception("Blocks can't be 0");
}
} else {
}
}
}
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected)
throws Exception {
if (!items.containsKey(key)) {
throw new Exception("Schematic file is missing a \"" + key + "\" tag");
}
Tag tag = items.get(key);
if (!expected.isInstance(tag)) {
throw new Exception(key + " tag is not of tag type " + expected.getName());
}
return expected.cast(tag);
}
}