From ad85749c38f397a611ac54e067d0faebb0fcaeed Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 16 Jul 2015 13:09:10 +1000 Subject: [PATCH] Optimize schematics --- .../plot/util/BukkitSchematicHandler.java | 157 +++++++++++++++--- .../plot/util/SchematicHandler.java | 2 +- 2 files changed, 137 insertions(+), 22 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java index 632f0638d..f1634316a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BukkitSchematicHandler.java @@ -97,32 +97,148 @@ public class BukkitSchematicHandler extends SchematicHandler { List tileEntities = new ArrayList(); World worldObj = Bukkit.getWorld(world); - - for (int x = 0; x < width; x++) { + + for (int y = 0; y < height; y++) { + int i1 = (y * width * length); for (int z = 0; z < length; z++) { - for (int y = 0; y < height; y++) { - final int index = (y * width * length) + (z * width) + x; + int i2 = i1 + (z * width); + for (int x = 0; x < width; x++) { + final int index = i2 + x; Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z); - BlockState state = block.getState(); - if (state != null) { - StateWrapper wrapper = new StateWrapper(state); - CompoundTag rawTag = wrapper.getTag(); - if (rawTag != null) { - Map values = new HashMap(); - for (Entry entry : rawTag.getValue().entrySet()) { - values.put(entry.getKey(), entry.getValue()); + int id = block.getTypeId(); + switch(id) { + case 0: + case 2: + case 4: + case 13: + case 14: + case 15: + case 20: + case 21: + case 22: + case 24: + case 30: + case 32: + case 37: + case 39: + case 40: + case 41: + case 42: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 55: + case 56: + case 57: + case 58: + case 60: + case 7: + case 8: + case 9: + case 10: + case 11: + case 73: + case 74: + case 75: + case 76: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 85: + case 87: + case 88: + case 101: + case 102: + case 103: + case 110: + case 112: + case 113: + case 121: + case 122: + case 129: + case 133: + case 165: + case 166: + case 169: + case 170: + case 172: + case 173: + case 174: + case 181: + case 182: + case 188: + case 189: + case 190: + case 191: + case 192: { + break; + } + case 54: + case 130: + case 142: + case 27: + case 137: + case 52: + case 154: + case 84: + case 25: + case 144: + case 138: + case 176: + case 177: + case 63: + case 68: + case 323: + case 117: + case 116: + case 28: + case 66: + case 157: + case 61: + case 62: + case 140: + case 146: + case 149: + case 150: + case 158: + case 23: + case 123: + case 124: + case 29: + case 33: + case 151: + case 178: { + // TODO implement fully + BlockState state = block.getState(); + if (state != null) { + StateWrapper wrapper = new StateWrapper(state); + CompoundTag rawTag = wrapper.getTag(); + if (rawTag != null) { + Map values = new HashMap(); + for (Entry entry : rawTag.getValue().entrySet()) { + values.put(entry.getKey(), entry.getValue()); + } + values.put("id", new StringTag("id", wrapper.getId())); + values.put("x", new IntTag("x", x)); + values.put("y", new IntTag("y", y)); + values.put("z", new IntTag("z", z)); + CompoundTag tileEntityTag = new CompoundTag(values); + tileEntities.add(tileEntityTag); + } } - values.put("id", new StringTag("id", wrapper.getId())); - values.put("x", new IntTag("x", x)); - values.put("y", new IntTag("y", y)); - values.put("z", new IntTag("z", z)); - CompoundTag tileEntityTag = new CompoundTag(values); - tileEntities.add(tileEntityTag); + } + default: { + blockData[index] = block.getData(); } } - int id = block.getTypeId(); - byte data = block.getData(); if (id > 255) { if (addBlocks == null) { addBlocks = new byte[(blocks.length >> 1) + 1]; @@ -130,7 +246,6 @@ public class BukkitSchematicHandler extends SchematicHandler { addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? (addBlocks[index >> 1] & 0xF0) | ((id >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((id >> 8) & 0xF) << 4)); } blocks[index] = (byte) id; - blockData[index] = data; } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 4443ab87e..2663382d2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -512,7 +512,7 @@ public abstract class SchematicHandler { * * @author Citymonstret */ - public class Dimension { + public static class Dimension { private final int x; private final int y; private final int z;