Optimize schematics

This commit is contained in:
boy0001 2015-07-16 13:09:10 +10:00
parent 3000aa371f
commit ad85749c38
2 changed files with 137 additions and 22 deletions

View File

@ -98,31 +98,147 @@ public class BukkitSchematicHandler extends SchematicHandler {
World worldObj = Bukkit.getWorld(world); 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 z = 0; z < length; z++) {
for (int y = 0; y < height; y++) { int i2 = i1 + (z * width);
final int index = (y * width * length) + (z * width) + x; for (int x = 0; x < width; x++) {
final int index = i2 + x;
Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z); Block block = worldObj.getBlockAt(sx + x, sy + y, sz + z);
BlockState state = block.getState(); int id = block.getTypeId();
if (state != null) { switch(id) {
StateWrapper wrapper = new StateWrapper(state); case 0:
CompoundTag rawTag = wrapper.getTag(); case 2:
if (rawTag != null) { case 4:
Map<String, Tag> values = new HashMap<String, Tag>(); case 13:
for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) { case 14:
values.put(entry.getKey(), entry.getValue()); 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<String, Tag> values = new HashMap<String, Tag>();
for (Entry<String, Tag> 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)); default: {
values.put("y", new IntTag("y", y)); blockData[index] = block.getData();
values.put("z", new IntTag("z", z));
CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
} }
} }
int id = block.getTypeId();
byte data = block.getData();
if (id > 255) { if (id > 255) {
if (addBlocks == null) { if (addBlocks == null) {
addBlocks = new byte[(blocks.length >> 1) + 1]; 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)); 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; blocks[index] = (byte) id;
blockData[index] = data;
} }
} }
} }

View File

@ -512,7 +512,7 @@ public abstract class SchematicHandler {
* *
* @author Citymonstret * @author Citymonstret
*/ */
public class Dimension { public static class Dimension {
private final int x; private final int x;
private final int y; private final int y;
private final int z; private final int z;