fixed gate rotation in schematic, close #1930

This commit is contained in:
SpaceToad 2014-07-05 15:15:15 +02:00
parent 72b1a3cfe6
commit f60595c821

View file

@ -26,6 +26,7 @@ import buildcraft.api.blueprints.SchematicTile;
import buildcraft.api.gates.IStatement; import buildcraft.api.gates.IStatement;
import buildcraft.api.gates.StatementManager; import buildcraft.api.gates.StatementManager;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.Gate;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe.SideProperties; import buildcraft.transport.TileGenericPipe.SideProperties;
@ -58,9 +59,38 @@ public class SchematicPipe extends SchematicTile {
BptPipeExtension.get(pipeItem).rotateLeft(this, context); BptPipeExtension.get(pipeItem).rotateLeft(this, context);
} }
NBTTagCompound gateNBT = tileNBT.getCompoundTag("Gate"); if (tileNBT.hasKey("Gate")) {
// This code is handling specifically BuildCraft 6.0 gates. Sided
// gates starting BuildCraft 6.1 work differently.
for (int i = 0; i < 8; ++i) { NBTTagCompound gateNBT = tileNBT.getCompoundTag("Gate");
rotateGateLeft(gateNBT);
} else {
// Post 6.1 treatment
NBTTagCompound gatesNBT[] = new NBTTagCompound[6];
for (int i = 0; i < 6; ++i) {
if (tileNBT.hasKey("Gate[" + i + "]")) {
gatesNBT[i] = tileNBT.getCompoundTag("Gate[" + i + "]");
}
}
for (int i = 0; i < 6; ++i) {
int newI = ForgeDirection.values()[i].getRotation(ForgeDirection.UP).ordinal();
if (gatesNBT[i] != null) {
rotateGateLeft(gatesNBT[i]);
tileNBT.setTag("Gate[" + newI + "]", gatesNBT[i]);
} else {
tileNBT.removeTag("Gate[" + newI + "]");
}
}
}
}
private void rotateGateLeft(NBTTagCompound gateNBT) {
for (int i = 0; i < Gate.MAX_STATEMENTS; ++i) {
if (gateNBT.hasKey("trigger[" + i + "]")) { if (gateNBT.hasKey("trigger[" + i + "]")) {
IStatement t = StatementManager.statements.get(gateNBT.getString("trigger[" + i + "]")); IStatement t = StatementManager.statements.get(gateNBT.getString("trigger[" + i + "]"));
t = t.rotateLeft(); t = t.rotateLeft();
@ -73,6 +103,12 @@ public class SchematicPipe extends SchematicTile {
gateNBT.setString("action[" + i + "]", a.getUniqueTag()); gateNBT.setString("action[" + i + "]", a.getUniqueTag());
} }
} }
if (gateNBT.hasKey("direction")) {
gateNBT.setInteger("direction",
ForgeDirection.values()[gateNBT.getInteger("direction")].
getRotation(ForgeDirection.UP).ordinal());
}
} }
@Override @Override