2013-09-29 19:38:20 -07:00
|
|
|
package tconstruct.library.component;
|
|
|
|
|
|
2014-02-05 10:28:54 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
2013-12-01 19:46:08 -05:00
|
|
|
|
2014-02-05 10:28:54 -05:00
|
|
|
import mantle.blocks.iface.IFacingLogic;
|
|
|
|
|
import mantle.blocks.iface.IMasterLogic;
|
|
|
|
|
import mantle.blocks.iface.IServantLogic;
|
|
|
|
|
import mantle.world.CoordTuple;
|
|
|
|
|
import mantle.world.CoordTupleSort;
|
2013-09-29 19:38:20 -07:00
|
|
|
import net.minecraft.block.Block;
|
2014-02-05 10:28:54 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagIntArray;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2013-09-29 19:38:20 -07:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-10-12 23:46:35 +01:00
|
|
|
import tconstruct.TConstruct;
|
2013-12-06 13:33:55 -05:00
|
|
|
|
2013-09-29 19:38:20 -07:00
|
|
|
public class TankLayerScan extends LogicComponent
|
|
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
protected TileEntity master;
|
|
|
|
|
protected IMasterLogic imaster;
|
|
|
|
|
protected Block[] scanBlocks;
|
2013-10-05 22:49:39 -07:00
|
|
|
protected CoordTuple masterCoord;
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
protected boolean completeStructure;
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
protected int bricks = 0;
|
|
|
|
|
protected int airBlocks = 0;
|
2013-11-04 19:28:01 -08:00
|
|
|
protected int structureTop = 0;
|
2013-10-05 22:49:39 -07:00
|
|
|
protected HashSet<CoordTuple> layerBlockCoords = new HashSet<CoordTuple>();
|
|
|
|
|
protected HashSet<CoordTuple> layerAirCoords = new HashSet<CoordTuple>();
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-07 20:49:55 -07:00
|
|
|
public ArrayList<CoordTuple> blockCoords = new ArrayList<CoordTuple>();
|
|
|
|
|
public ArrayList<CoordTuple> airCoords = new ArrayList<CoordTuple>();
|
2013-10-01 19:44:04 -07:00
|
|
|
protected ArrayList<int[]> validAirCoords = new ArrayList<int[]>();
|
|
|
|
|
protected CoordTuple returnStone;
|
2013-10-05 11:21:32 -07:00
|
|
|
|
2013-10-18 16:29:21 +01:00
|
|
|
private static boolean debug = System.getenv("DBG_MANTLE_TankLayerScan") != null;
|
2014-02-16 14:23:50 -05:00
|
|
|
private static int MAX_LAYER_RECURSION_DEPTH = System.getProperty("os.arch").equals("amd64") ? 4000 : 2000; // Recursion
|
|
|
|
|
// causes
|
|
|
|
|
// overflows
|
|
|
|
|
// on
|
|
|
|
|
// 32-bit,
|
|
|
|
|
// so reduce
|
|
|
|
|
// if not
|
|
|
|
|
// 64-bit
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
public TankLayerScan(TileEntity te, Block... ids)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
|
|
|
|
assert te instanceof IMasterLogic : "TileEntity must be an instance of IMasterLogic";
|
|
|
|
|
master = te;
|
|
|
|
|
imaster = (IMasterLogic) te;
|
2013-10-01 19:44:04 -07:00
|
|
|
scanBlocks = ids;
|
2014-02-05 08:28:53 -05:00
|
|
|
masterCoord = new CoordTuple(te.xCoord, te.yCoord, te.zCoord);
|
2013-09-29 19:38:20 -07:00
|
|
|
validAirCoords.add(new int[] { 1, 0 });
|
|
|
|
|
validAirCoords.add(new int[] { -1, 0 });
|
|
|
|
|
validAirCoords.add(new int[] { 0, 1 });
|
|
|
|
|
validAirCoords.add(new int[] { 0, -1 });
|
2013-10-18 16:29:21 +01:00
|
|
|
if (debug)
|
|
|
|
|
{
|
|
|
|
|
TConstruct.logger.info("In debug mode: " + this);
|
|
|
|
|
TConstruct.logger.info("Using recursion size " + MAX_LAYER_RECURSION_DEPTH + " on JVM arch " + System.getProperty("os.arch"));
|
|
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void checkValidStructure ()
|
|
|
|
|
{
|
|
|
|
|
bricks = 0;
|
|
|
|
|
airBlocks = 0;
|
|
|
|
|
blockCoords.clear();
|
|
|
|
|
airCoords.clear();
|
|
|
|
|
boolean validAir = false;
|
2014-02-16 14:23:50 -05:00
|
|
|
// Check for air space in front of and behind the structure
|
2013-09-29 19:38:20 -07:00
|
|
|
byte dir = getDirection();
|
|
|
|
|
switch (getDirection())
|
|
|
|
|
{
|
|
|
|
|
case 2: // +z
|
|
|
|
|
case 3: // -z
|
2014-02-05 08:28:53 -05:00
|
|
|
if (checkAir(master.xCoord, master.yCoord, master.zCoord - 1) && checkAir(master.xCoord, master.yCoord, master.zCoord + 1))
|
2013-09-29 19:38:20 -07:00
|
|
|
validAir = true;
|
|
|
|
|
break;
|
|
|
|
|
case 4: // +x
|
|
|
|
|
case 5: // -x
|
2014-02-05 08:28:53 -05:00
|
|
|
if (checkAir(master.xCoord - 1, master.yCoord, master.zCoord) && checkAir(master.xCoord + 1, master.yCoord, master.zCoord))
|
2013-09-29 19:38:20 -07:00
|
|
|
validAir = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Recurse the structure
|
2013-09-29 19:38:20 -07:00
|
|
|
boolean validBlocks = false;
|
|
|
|
|
|
|
|
|
|
int xPos = 0, zPos = 0;
|
|
|
|
|
if (dir == 2)
|
|
|
|
|
xPos = 1;
|
|
|
|
|
if (dir == 3)
|
|
|
|
|
xPos = -1;
|
|
|
|
|
if (dir == 4)
|
|
|
|
|
zPos = -1;
|
|
|
|
|
if (dir == 5)
|
|
|
|
|
zPos = 1;
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
returnStone = new CoordTuple(master.xCoord - xPos, master.yCoord, master.zCoord - zPos);
|
|
|
|
|
if (initialRecurseLayer(master.xCoord + xPos, master.yCoord, master.zCoord + zPos))
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
|
|
|
|
xPos = 0;
|
|
|
|
|
zPos = 0;
|
|
|
|
|
switch (dir)
|
|
|
|
|
{
|
|
|
|
|
case 2: // +z
|
|
|
|
|
zPos = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 3: // -z
|
|
|
|
|
zPos = -1;
|
|
|
|
|
break;
|
|
|
|
|
case 4: // +x
|
|
|
|
|
xPos = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 5: // -x
|
|
|
|
|
xPos = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-10-01 19:44:04 -07:00
|
|
|
if (!world.isRemote && debug)
|
2013-10-12 23:46:35 +01:00
|
|
|
TConstruct.logger.info("Bricks in recursion: " + blockCoords.size());
|
2013-09-29 19:38:20 -07:00
|
|
|
blockCoords.clear();
|
|
|
|
|
bricks = 0;
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Does the actual adding of blocks in the ring
|
2014-02-05 08:28:53 -05:00
|
|
|
boolean sealed = floodTest(master.xCoord + xPos, master.yCoord, master.zCoord + zPos);
|
2013-10-01 19:44:04 -07:00
|
|
|
if (!world.isRemote && debug)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-12 23:46:35 +01:00
|
|
|
TConstruct.logger.info("Air in ring: " + airBlocks);
|
|
|
|
|
TConstruct.logger.info("Bricks in ring: " + bricks);
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sealed)
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
blockCoords.add(new CoordTuple(master.xCoord, master.yCoord, master.zCoord)); // Don't forget me!
|
2013-10-05 22:49:39 -07:00
|
|
|
layerAirCoords = new HashSet<CoordTuple>(airCoords);
|
|
|
|
|
layerBlockCoords = new HashSet<CoordTuple>(blockCoords);
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
int lowY = recurseStructureDown(master.yCoord - 1);
|
2013-10-05 11:21:32 -07:00
|
|
|
if (lowY != -1)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
|
|
|
|
completeStructure = true;
|
2014-02-05 08:28:53 -05:00
|
|
|
structureTop = recurseStructureUp(master.yCoord + 1);
|
2013-10-06 09:24:58 -07:00
|
|
|
finalizeStructure();
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
if (!world.isRemote && debug)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-12 23:46:35 +01:00
|
|
|
TConstruct.logger.info("Air in structure: " + airCoords.size());
|
|
|
|
|
TConstruct.logger.info("Bricks in structure: " + blockCoords.size());
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-01 19:44:04 -07:00
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// @SuppressWarnings({ "unchecked" })
|
2013-10-06 09:24:58 -07:00
|
|
|
protected void finalizeStructure ()
|
2013-10-05 22:49:39 -07:00
|
|
|
{
|
2013-11-04 19:28:01 -08:00
|
|
|
Collections.sort(blockCoords, new CoordTupleSort());
|
2013-10-05 22:49:39 -07:00
|
|
|
Collections.sort(airCoords, new CoordTupleSort());
|
2013-10-09 22:21:19 -07:00
|
|
|
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
2013-10-09 22:21:19 -07:00
|
|
|
if (servant instanceof IServantLogic)
|
2014-02-05 08:28:53 -05:00
|
|
|
((IServantLogic) servant).verifyMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
2013-10-09 22:21:19 -07:00
|
|
|
}
|
2013-10-05 22:49:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
public boolean isComplete ()
|
|
|
|
|
{
|
|
|
|
|
return completeStructure;
|
|
|
|
|
}
|
2013-10-05 11:21:32 -07:00
|
|
|
|
2013-10-07 20:49:55 -07:00
|
|
|
public int getAirLayerSize ()
|
|
|
|
|
{
|
|
|
|
|
return layerAirCoords.size();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-05 11:21:32 -07:00
|
|
|
public int getAirSize ()
|
2013-10-01 19:44:04 -07:00
|
|
|
{
|
|
|
|
|
return airBlocks;
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
2013-10-07 20:49:55 -07:00
|
|
|
public CoordTuple getAirByIndex (int index)
|
|
|
|
|
{
|
|
|
|
|
if (index >= airCoords.size() || index < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return airCoords.get(index);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-29 19:38:20 -07:00
|
|
|
private byte getDirection ()
|
|
|
|
|
{
|
|
|
|
|
if (master instanceof IFacingLogic)
|
|
|
|
|
return ((IFacingLogic) master).getRenderDirection();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean checkAir (int x, int y, int z)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
Block block = world.getBlock(x, y, z);
|
2014-02-16 14:23:50 -05:00
|
|
|
if (block == null || world.isAirBlock(x, y, z))// || block ==
|
|
|
|
|
// TContent.tankAir)
|
2013-09-29 19:38:20 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean checkServant (int x, int y, int z)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
Block block = world.getBlock(x, y, z);
|
2014-02-16 14:23:50 -05:00
|
|
|
if (block == null || world.isAirBlock(x, y, z) || !isValidBlock(x, y, z))
|
2013-09-29 19:38:20 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!block.hasTileEntity(world.getBlockMetadata(x, y, z)))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity be = world.getTileEntity(x, y, z);
|
2013-09-29 19:38:20 -07:00
|
|
|
if (be instanceof IServantLogic)
|
2013-10-01 19:44:04 -07:00
|
|
|
return ((IServantLogic) be).setPotentialMaster(this.imaster, this.world, x, y, z);
|
2013-09-29 19:38:20 -07:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean initialRecurseLayer (int x, int y, int z)
|
|
|
|
|
{
|
2013-10-18 16:02:34 +01:00
|
|
|
if (bricks > MAX_LAYER_RECURSION_DEPTH)
|
2013-09-29 19:38:20 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CoordTuple keystone = new CoordTuple(x, y, z);
|
|
|
|
|
if (keystone.equals(returnStone))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
for (int xPos = -1; xPos <= 1; xPos++)
|
|
|
|
|
{
|
|
|
|
|
for (int zPos = -1; zPos <= 1; zPos++)
|
|
|
|
|
{
|
|
|
|
|
CoordTuple coord = new CoordTuple(x + xPos, y, z + zPos);
|
|
|
|
|
if (!blockCoords.contains(coord))
|
|
|
|
|
{
|
|
|
|
|
if (isValidBlock(x + xPos, y, z + zPos))
|
|
|
|
|
{
|
|
|
|
|
bricks++;
|
|
|
|
|
blockCoords.add(coord);
|
|
|
|
|
return initialRecurseLayer(x + xPos, y, z + zPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean isValidBlock (int x, int y, int z)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
Block block = world.getBlock(x, y, z);
|
2013-09-29 19:38:20 -07:00
|
|
|
if (block != null)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < scanBlocks.length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (block == scanBlocks[i])
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean floodTest (int x, int y, int z)
|
|
|
|
|
{
|
2013-10-15 21:14:23 +01:00
|
|
|
if (airBlocks > MAX_LAYER_RECURSION_DEPTH)
|
2013-09-29 19:38:20 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (int[] offset : validAirCoords)
|
|
|
|
|
{
|
|
|
|
|
CoordTuple coord = new CoordTuple(x + offset[0], y, z + offset[1]);
|
|
|
|
|
if (!airCoords.contains(coord))
|
|
|
|
|
{
|
|
|
|
|
if (checkAir(x + offset[0], y, z + offset[1]))
|
|
|
|
|
{
|
2013-12-05 00:29:59 -05:00
|
|
|
addAirBlock(coord.x, y, coord.z);
|
2013-09-29 19:38:20 -07:00
|
|
|
floodTest(x + offset[0], y, z + offset[1]);
|
|
|
|
|
}
|
|
|
|
|
else if (!blockCoords.contains(coord) && checkServant(x + offset[0], y, z + offset[1]))
|
|
|
|
|
{
|
|
|
|
|
bricks++;
|
|
|
|
|
blockCoords.add(coord);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-05 11:21:32 -07:00
|
|
|
public int recurseStructureDown (int y)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-05 11:21:32 -07:00
|
|
|
Iterator i = layerAirCoords.iterator();
|
2013-10-01 19:44:04 -07:00
|
|
|
if (i.hasNext())
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
CoordTuple coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkAir(coord.x, y, coord.z))
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
boolean valid = true;
|
2014-02-16 14:23:50 -05:00
|
|
|
addAirBlock(coord.x, y, coord.z); // Don't skip first one
|
2013-10-01 19:44:04 -07:00
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Air blocks
|
2013-10-01 19:44:04 -07:00
|
|
|
while (i.hasNext())
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkAir(coord.x, y, coord.z))
|
2013-10-01 19:44:04 -07:00
|
|
|
{
|
2013-12-05 00:29:59 -05:00
|
|
|
addAirBlock(coord.x, y, coord.z);
|
2013-10-01 19:44:04 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Bricks
|
2013-10-05 11:21:32 -07:00
|
|
|
i = layerBlockCoords.iterator();
|
2013-10-01 19:44:04 -07:00
|
|
|
while (i.hasNext())
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkServant(coord.x, y, coord.z))
|
|
|
|
|
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
2013-10-01 19:44:04 -07:00
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
if (valid)
|
|
|
|
|
return recurseStructureDown(y - 1);
|
|
|
|
|
}
|
2013-12-05 00:29:59 -05:00
|
|
|
else if (checkServant(coord.x, y, coord.z))
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
// Bottom floor. All blocks, please vacate the elevator
|
2013-10-01 19:44:04 -07:00
|
|
|
boolean valid = true;
|
|
|
|
|
while (i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
coord = (CoordTuple) i.next();
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkServant(coord.x, y, coord.z))
|
|
|
|
|
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2013-10-01 19:44:04 -07:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
2013-10-05 11:21:32 -07:00
|
|
|
if (valid)
|
2013-10-05 22:49:39 -07:00
|
|
|
return y + 1;
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-05 11:21:32 -07:00
|
|
|
return -1;
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-04 19:28:01 -08:00
|
|
|
public int recurseStructureUp (int y)
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-05 11:21:32 -07:00
|
|
|
Iterator i = layerBlockCoords.iterator();
|
2013-10-01 19:44:04 -07:00
|
|
|
if (i.hasNext())
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
CoordTuple coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkServant(coord.x, y, coord.z))
|
2013-09-29 19:38:20 -07:00
|
|
|
{
|
2013-10-01 19:44:04 -07:00
|
|
|
boolean valid = true;
|
2013-09-29 19:38:20 -07:00
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Bricks
|
2013-09-29 19:38:20 -07:00
|
|
|
while (i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkServant(coord.x, y, coord.z))
|
|
|
|
|
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
2013-10-01 19:44:04 -07:00
|
|
|
|
2013-09-29 19:38:20 -07:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// Air blocks
|
2013-10-01 19:44:04 -07:00
|
|
|
if (valid)
|
|
|
|
|
{
|
2013-10-05 11:21:32 -07:00
|
|
|
i = layerAirCoords.iterator();
|
2013-10-01 19:44:04 -07:00
|
|
|
while (i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
coord = (CoordTuple) i.next();
|
2013-12-05 00:29:59 -05:00
|
|
|
if (checkAir(coord.x, y, coord.z))
|
2013-10-01 19:44:04 -07:00
|
|
|
{
|
2013-12-05 00:29:59 -05:00
|
|
|
addAirBlock(coord.x, y, coord.z);
|
2013-10-01 19:44:04 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valid)
|
|
|
|
|
recurseStructureUp(y + 1);
|
|
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
2013-11-04 19:28:01 -08:00
|
|
|
return y - 1;
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void addAirBlock (int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
airBlocks++;
|
2013-10-01 19:44:04 -07:00
|
|
|
airCoords.add(new CoordTuple(x, y, z));
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-04 19:28:01 -08:00
|
|
|
/* Checking for valid structures */
|
|
|
|
|
|
|
|
|
|
public void recheckStructure ()
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Rechecking structure");
|
|
|
|
|
int height = -1;
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
2013-11-04 19:28:01 -08:00
|
|
|
boolean canPass = false;
|
|
|
|
|
if (servant instanceof IServantLogic)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
canPass = ((IServantLogic) servant).verifyMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
2013-11-04 19:28:01 -08:00
|
|
|
if (canPass)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!canPass)
|
|
|
|
|
{
|
2013-11-10 13:57:35 -08:00
|
|
|
System.out.println("Coord: " + coord);
|
2013-12-05 00:29:59 -05:00
|
|
|
height = coord.y;
|
2013-11-04 19:28:01 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (height != -1)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (height <= master.yCoord)
|
2013-11-04 19:28:01 -08:00
|
|
|
invalidateStructure();
|
|
|
|
|
else
|
|
|
|
|
invalidateBlocksAbove(height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
if (structureTop == 0) // Workaround for missing data
|
2013-11-04 19:28:01 -08:00
|
|
|
{
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
2013-12-05 00:29:59 -05:00
|
|
|
structureTop = coord.y;
|
2013-11-04 19:28:01 -08:00
|
|
|
}
|
|
|
|
|
structureTop = recurseStructureUp(structureTop + 1);
|
|
|
|
|
finalizeStructure();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void invalidateStructure ()
|
|
|
|
|
{
|
|
|
|
|
completeStructure = false;
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
2013-11-04 19:28:01 -08:00
|
|
|
if (servant instanceof IServantLogic)
|
2014-02-05 08:28:53 -05:00
|
|
|
((IServantLogic) servant).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
2013-11-04 19:28:01 -08:00
|
|
|
}
|
2014-02-05 08:28:53 -05:00
|
|
|
master.getWorldObj().markBlockForUpdate(master.xCoord, master.yCoord, master.zCoord);
|
2013-11-04 19:28:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void invalidateBlocksAbove (int height)
|
|
|
|
|
{
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
|
|
|
|
{
|
2013-12-05 00:29:59 -05:00
|
|
|
if (coord.y < height)
|
2013-11-04 19:28:01 -08:00
|
|
|
continue;
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity servant = world.getTileEntity(coord.x, coord.y, coord.z);
|
2013-11-04 19:28:01 -08:00
|
|
|
if (servant instanceof IServantLogic)
|
2014-02-05 08:28:53 -05:00
|
|
|
((IServantLogic) servant).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
2013-11-04 19:28:01 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
/**
|
|
|
|
|
* Do any necessary cleanup here. Remove air blocks, invalidate servants,
|
|
|
|
|
* etc
|
|
|
|
|
*/
|
2013-10-01 19:44:04 -07:00
|
|
|
public void cleanup ()
|
|
|
|
|
{
|
|
|
|
|
Iterator i = blockCoords.iterator();
|
|
|
|
|
while (i.hasNext())
|
|
|
|
|
{
|
|
|
|
|
CoordTuple coord = (CoordTuple) i.next();
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity te = world.getTileEntity(coord.x, coord.y, coord.z);
|
2013-10-05 22:49:39 -07:00
|
|
|
if (te != null && te instanceof IServantLogic)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
((IServantLogic) te).invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
2013-10-05 22:49:39 -07:00
|
|
|
}
|
2013-10-01 19:44:04 -07:00
|
|
|
}
|
2013-09-29 19:38:20 -07:00
|
|
|
}
|
2013-10-05 11:21:32 -07:00
|
|
|
|
2013-11-04 19:28:01 -08:00
|
|
|
/* NBT */
|
2013-11-04 00:29:07 -08:00
|
|
|
@Override
|
|
|
|
|
public void readFromNBT (NBTTagCompound tags)
|
2013-10-05 11:21:32 -07:00
|
|
|
{
|
2013-11-04 00:29:07 -08:00
|
|
|
super.readFromNBT(tags);
|
2014-02-13 23:03:13 -05:00
|
|
|
NBTTagList layerAir = tags.getTagList("AirLayer", 9);
|
2013-10-05 11:21:32 -07:00
|
|
|
if (layerAir != null)
|
|
|
|
|
{
|
|
|
|
|
layerAirCoords.clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < layerAir.tagCount(); ++i)
|
|
|
|
|
{
|
2014-02-01 14:18:17 -05:00
|
|
|
int[] coord = layerAir.func_150306_c(i);
|
2013-10-05 11:21:32 -07:00
|
|
|
layerAirCoords.add(new CoordTuple(coord[0], coord[1], coord[2]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-05 22:49:39 -07:00
|
|
|
|
2014-02-13 23:03:13 -05:00
|
|
|
NBTTagList blocks = tags.getTagList("Blocks", 9);
|
2013-10-05 11:21:32 -07:00
|
|
|
if (blocks != null)
|
|
|
|
|
{
|
|
|
|
|
blockCoords.clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < blocks.tagCount(); ++i)
|
|
|
|
|
{
|
2014-02-05 09:11:06 -05:00
|
|
|
int[] coord = blocks.func_150306_c(i);
|
2013-10-05 11:21:32 -07:00
|
|
|
blockCoords.add(new CoordTuple(coord[0], coord[1], coord[2]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-05 22:49:39 -07:00
|
|
|
|
2014-02-13 23:03:13 -05:00
|
|
|
NBTTagList air = tags.getTagList("Air", 9);
|
2013-10-05 11:21:32 -07:00
|
|
|
if (air != null)
|
|
|
|
|
{
|
|
|
|
|
airCoords.clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < air.tagCount(); ++i)
|
|
|
|
|
{
|
2014-02-01 14:18:17 -05:00
|
|
|
int[] coord = air.func_150306_c(i);
|
2013-10-05 11:21:32 -07:00
|
|
|
airCoords.add(new CoordTuple(coord[0], coord[1], coord[2]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-04 19:28:01 -08:00
|
|
|
structureTop = tags.getInteger("structureTop");
|
2013-11-04 00:29:07 -08:00
|
|
|
}
|
2013-10-07 20:49:55 -07:00
|
|
|
|
2013-11-04 00:29:07 -08:00
|
|
|
public void readNetworkNBT (NBTTagCompound tags)
|
|
|
|
|
{
|
|
|
|
|
completeStructure = tags.getBoolean("Complete");
|
2013-10-05 22:49:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-11-04 00:29:07 -08:00
|
|
|
@Override
|
2013-10-10 00:51:38 -07:00
|
|
|
public void writeToNBT (NBTTagCompound tags)
|
2013-10-05 22:49:39 -07:00
|
|
|
{
|
2013-10-10 00:51:38 -07:00
|
|
|
super.writeToNBT(tags);
|
2013-10-05 11:21:32 -07:00
|
|
|
NBTTagList layerAir = new NBTTagList();
|
|
|
|
|
for (CoordTuple coord : layerAirCoords)
|
|
|
|
|
{
|
2014-02-01 14:18:17 -05:00
|
|
|
layerAir.appendTag(new NBTTagIntArray(new int[] { coord.x, coord.y, coord.z }));
|
2013-10-05 11:21:32 -07:00
|
|
|
}
|
|
|
|
|
tags.setTag("AirLayer", layerAir);
|
2013-10-05 22:49:39 -07:00
|
|
|
|
2013-10-05 11:21:32 -07:00
|
|
|
NBTTagList blocks = new NBTTagList();
|
|
|
|
|
for (CoordTuple coord : blockCoords)
|
|
|
|
|
{
|
2014-02-01 14:18:17 -05:00
|
|
|
blocks.appendTag(new NBTTagIntArray(new int[] { coord.x, coord.y, coord.z }));
|
2013-10-05 11:21:32 -07:00
|
|
|
}
|
|
|
|
|
tags.setTag("Blocks", blocks);
|
2013-10-05 22:49:39 -07:00
|
|
|
|
2013-10-05 11:21:32 -07:00
|
|
|
NBTTagList air = new NBTTagList();
|
|
|
|
|
for (CoordTuple coord : airCoords)
|
|
|
|
|
{
|
2014-02-05 09:11:06 -05:00
|
|
|
air.appendTag(new NBTTagIntArray(new int[] { coord.x, coord.y, coord.z }));
|
2013-10-05 11:21:32 -07:00
|
|
|
}
|
|
|
|
|
tags.setTag("Air", air);
|
2013-11-04 19:28:01 -08:00
|
|
|
tags.setInteger("structureTop", structureTop);
|
2013-10-05 11:21:32 -07:00
|
|
|
}
|
2013-11-04 00:29:07 -08:00
|
|
|
|
|
|
|
|
public void writeNetworkNBT (NBTTagCompound tags)
|
|
|
|
|
{
|
|
|
|
|
tags.setBoolean("Complete", completeStructure);
|
|
|
|
|
}
|
2014-02-16 14:23:50 -05:00
|
|
|
}
|