diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index 0cdfc596..e92bd303 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -31,137 +31,139 @@ public class BatteryUpdateProtocol */ public void loopThrough(TileEntity tile) { - World worldObj = tile.worldObj; - - int origX = tile.xCoord, origY = tile.yCoord, origZ = tile.zCoord; - - boolean isCorner = true; - boolean rightBlocks = true; - - Set locations = new HashSet(); - - int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0; - - int x = 0, y = 0, z = 0; - - if((isViableNode(origX + 1, origY, origZ) && isViableNode(origX - 1, origY, origZ)) || - (isViableNode(origX, origY + 1, origZ) && isViableNode(origX, origY - 1, origZ)) || - (isViableNode(origX, origY, origZ + 1) && isViableNode(origX, origY, origZ - 1))) + if(structureFound == null) { - isCorner = false; - } - - if(isCorner) - { - if(isViableNode(origX+1, origY, origZ)) - { - xmin = 0; - - while(isViableNode(origX+x+1, origY, origZ)) - { - x++; - } - - xmax = x; - } - else { - xmax = 0; - - while(isViableNode(origX+x-1, origY, origZ)) - { - x--; - } - - xmin = x; - } - - if(isViableNode(origX, origY+1, origZ)) - { - ymin = 0; - - while(isViableNode(origX, origY+y+1, origZ)) - { - y++; - } - - ymax = y; - } - else { - ymax = 0; - - while(isViableNode(origX, origY+y-1 ,origZ)) - { - y--; - } - - ymin = y; - } - - if(isViableNode(origX, origY, origZ+1)) - { - zmin = 0; - - while(isViableNode(origX, origY, origZ+z+1)) - { - z++; - } - - zmax = z; - } - else { - zmax = 0; - - while(isViableNode(origX, origY, origZ+z-1)) - { - z--; - } - - zmin = z; - } - - for(x = xmin; x <= xmax; x++) - { - for(y = ymin; y <= ymax; y++) - { - for(z = zmin; z <= zmax; z++) - { - if(!isViableNode(origX+x, origY+y, origZ+z)) - { - rightBlocks = false; - break; - } - else { - locations.add(new Vector3(tile).translate(new Vector3(x, y, z))); - } - } - - if(!rightBlocks) - { - break; - } - } - - if(!rightBlocks) - { - break; - } - } - } - - if(locations.size() >= 1 && locations.size() < 512) - { - if(rightBlocks && isCorner) + World worldObj = tile.worldObj; + + int origX = tile.xCoord, origY = tile.yCoord, origZ = tile.zCoord; + + boolean isCorner = true; + boolean rightBlocks = true; + + Set locations = new HashSet(); + + int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0; + + int x = 0, y = 0, z = 0; + + if((isBattery(origX + 1, origY, origZ) && isBattery(origX - 1, origY, origZ)) || + (isBattery(origX, origY + 1, origZ) && isBattery(origX, origY - 1, origZ)) || + (isBattery(origX, origY, origZ + 1) && isBattery(origX, origY, origZ - 1))) { - SynchronizedBatteryData structure = new SynchronizedBatteryData(); - structure.locations = locations; - structure.length = Math.abs(xmax-xmin)+1; - structure.height = Math.abs(ymax-ymin)+1; - structure.width = Math.abs(zmax-zmin)+1; - - if(structure.locations.contains(new Vector3(pointer))) + isCorner = false; + } + + if(isCorner) + { + if(isBattery(origX+1, origY, origZ)) + { + xmin = 0; + + while(isBattery(origX+x+1, origY, origZ)) + { + x++; + } + + xmax = x; + } + else { + xmax = 0; + + while(isBattery(origX+x-1, origY, origZ)) + { + x--; + } + + xmin = x; + } + + if(isBattery(origX, origY+1, origZ)) + { + ymin = 0; + + while(isBattery(origX, origY+y+1, origZ)) + { + y++; + } + + ymax = y; + } + else { + ymax = 0; + + while(isBattery(origX, origY+y-1 ,origZ)) + { + y--; + } + + ymin = y; + } + + if(isBattery(origX, origY, origZ+1)) + { + zmin = 0; + + while(isBattery(origX, origY, origZ+z+1)) + { + z++; + } + + zmax = z; + } + else { + zmax = 0; + + while(isBattery(origX, origY, origZ+z-1)) + { + z--; + } + + zmin = z; + } + + for(x = xmin; x <= xmax; x++) + { + for(y = ymin; y <= ymax; y++) + { + for(z = zmin; z <= zmax; z++) + { + if(!isBattery(origX+x, origY+y, origZ+z)) + { + rightBlocks = false; + break; + } + else { + locations.add(new Vector3(tile).translate(new Vector3(x, y, z))); + } + } + + if(!rightBlocks) + { + break; + } + } + + if(!rightBlocks) + { + break; + } + } + } + + if(locations.size() >= 1 && locations.size() < 512) + { + if(rightBlocks && isCorner) { - structureFound = structure; - return; + SynchronizedBatteryData structure = new SynchronizedBatteryData(); + structure.locations = locations; + structure.length = Math.abs(xmax-xmin)+1; + structure.height = Math.abs(ymax-ymin)+1; + structure.width = Math.abs(zmax-zmin)+1; + + if(structure.locations.contains(new Vector3(pointer))) + { + structureFound = structure; + } } } } @@ -182,7 +184,7 @@ public class BatteryUpdateProtocol } } - private boolean isViableNode(int x, int y, int z) + private boolean isBattery(int x, int y, int z) { if(pointer.worldObj.getBlockTileEntity(x, y, z) instanceof TileEntityBattery) {