mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-22 05:02:39 +00:00
Smeltery broken into components
This commit is contained in:
1 parent
9a6ace2f69
commit
349b124ac3
156 files changed
+4862
-665
No files matched your search
@@ -1,12 +1,11 @@
|
||||
package tconstruct.library.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import tconstruct.library.util.CoordTuple;
|
||||
import tconstruct.library.util.IFacingLogic;
|
||||
import tconstruct.library.util.IMasterLogic;
|
||||
@@ -14,29 +13,30 @@ import tconstruct.library.util.IServantLogic;
|
||||
|
||||
public class TankLayerScan extends LogicComponent
|
||||
{
|
||||
TileEntity master;
|
||||
IMasterLogic imaster;
|
||||
World world;
|
||||
Block[] scanBlocks;
|
||||
protected TileEntity master;
|
||||
protected IMasterLogic imaster;
|
||||
protected Block[] scanBlocks;
|
||||
|
||||
public boolean completeStructure;
|
||||
protected boolean completeStructure;
|
||||
|
||||
int bricks = 0;
|
||||
int airBlocks = 0;
|
||||
HashSet<CoordTuple> tempBlockCoords = new HashSet<CoordTuple>();
|
||||
HashSet<CoordTuple> tempAirCoords = new HashSet<CoordTuple>();
|
||||
protected int bricks = 0;
|
||||
protected int airBlocks = 0;
|
||||
protected TreeSet<CoordTuple> tempBlockCoords = new TreeSet<CoordTuple>();
|
||||
protected TreeSet<CoordTuple> tempAirCoords = new TreeSet<CoordTuple>();
|
||||
|
||||
public HashSet<CoordTuple> blockCoords = new HashSet<CoordTuple>();
|
||||
public HashSet<CoordTuple> airCoords = new HashSet<CoordTuple>();
|
||||
ArrayList<int[]> validAirCoords = new ArrayList<int[]>();
|
||||
CoordTuple returnStone;
|
||||
public TreeSet<CoordTuple> blockCoords = new TreeSet<CoordTuple>();
|
||||
public TreeSet<CoordTuple> airCoords = new TreeSet<CoordTuple>();
|
||||
protected ArrayList<int[]> validAirCoords = new ArrayList<int[]>();
|
||||
protected CoordTuple returnStone;
|
||||
|
||||
private boolean debug = false;
|
||||
|
||||
public TankLayerScan(TileEntity te, Block... id)
|
||||
public TankLayerScan(TileEntity te, Block... ids)
|
||||
{
|
||||
assert te instanceof IMasterLogic : "TileEntity must be an instance of IMasterLogic";
|
||||
master = te;
|
||||
imaster = (IMasterLogic) te;
|
||||
scanBlocks = id;
|
||||
scanBlocks = ids;
|
||||
validAirCoords.add(new int[] { 1, 0 });
|
||||
validAirCoords.add(new int[] { -1, 0 });
|
||||
validAirCoords.add(new int[] { 0, 1 });
|
||||
@@ -99,14 +99,14 @@ public class TankLayerScan extends LogicComponent
|
||||
xPos = -1;
|
||||
break;
|
||||
}
|
||||
if (!world.isRemote)
|
||||
if (!world.isRemote && debug)
|
||||
System.out.println("Bricks in recursion: " + blockCoords.size());
|
||||
blockCoords.clear();
|
||||
bricks = 0;
|
||||
|
||||
//Does the actual adding of blocks in the ring
|
||||
boolean sealed = floodTest(master.xCoord + xPos, master.yCoord, master.zCoord + zPos);
|
||||
if (!world.isRemote)
|
||||
if (!world.isRemote && debug)
|
||||
{
|
||||
System.out.println("Air in ring: " + airBlocks);
|
||||
System.out.println("Bricks in ring: " + bricks);
|
||||
@@ -114,15 +114,15 @@ public class TankLayerScan extends LogicComponent
|
||||
|
||||
if (sealed)
|
||||
{
|
||||
tempAirCoords = new HashSet<CoordTuple>(airCoords);
|
||||
tempBlockCoords = new HashSet<CoordTuple>(blockCoords);
|
||||
tempAirCoords = new TreeSet<CoordTuple>(airCoords);
|
||||
tempBlockCoords = new TreeSet<CoordTuple>(blockCoords);
|
||||
|
||||
if (recurseStructureDown(master.yCoord - 1))
|
||||
{
|
||||
completeStructure = true;
|
||||
recurseStructureUp(master.yCoord + 1);
|
||||
|
||||
if (!world.isRemote)
|
||||
if (!world.isRemote && debug)
|
||||
{
|
||||
System.out.println("Air in structure: " + airCoords.size());
|
||||
System.out.println("Bricks in structure: " + blockCoords.size());
|
||||
@@ -130,7 +130,25 @@ public class TankLayerScan extends LogicComponent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (completeStructure)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isComplete ()
|
||||
{
|
||||
return completeStructure;
|
||||
}
|
||||
|
||||
public int getAirSize()
|
||||
{
|
||||
return airBlocks;
|
||||
}
|
||||
|
||||
private byte getDirection ()
|
||||
@@ -152,7 +170,7 @@ public class TankLayerScan extends LogicComponent
|
||||
protected boolean checkServant (int x, int y, int z)
|
||||
{
|
||||
Block block = Block.blocksList[world.getBlockId(x, y, z)];
|
||||
if (block == null || block.isAirBlock(world, x, y, z))
|
||||
if (block == null || block.isAirBlock(world, x, y, z) || !isValidBlock(x, y, z))
|
||||
return false;
|
||||
|
||||
if (!block.hasTileEntity(world.getBlockMetadata(x, y, z)))
|
||||
@@ -160,14 +178,14 @@ public class TankLayerScan extends LogicComponent
|
||||
|
||||
TileEntity be = world.getBlockTileEntity(x, y, z);
|
||||
if (be instanceof IServantLogic)
|
||||
return ((IServantLogic) be).setPotentialMaster(this.imaster, x, y, z);
|
||||
return ((IServantLogic) be).setPotentialMaster(this.imaster, this.world, x, y, z);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean initialRecurseLayer (int x, int y, int z)
|
||||
{
|
||||
if (bricks >= 4095)
|
||||
if (bricks > 4000)
|
||||
return false;
|
||||
|
||||
CoordTuple keystone = new CoordTuple(x, y, z);
|
||||
@@ -210,7 +228,7 @@ public class TankLayerScan extends LogicComponent
|
||||
|
||||
protected boolean floodTest (int x, int y, int z)
|
||||
{
|
||||
if (airBlocks >= 4095)
|
||||
if (airBlocks > 4000)
|
||||
return false;
|
||||
|
||||
for (int[] offset : validAirCoords)
|
||||
@@ -220,7 +238,6 @@ public class TankLayerScan extends LogicComponent
|
||||
{
|
||||
if (checkAir(x + offset[0], y, z + offset[1]))
|
||||
{
|
||||
airCoords.add(coord);
|
||||
addAirBlock(coord.x, y, coord.z);
|
||||
floodTest(x + offset[0], y, z + offset[1]);
|
||||
}
|
||||
@@ -237,100 +254,19 @@ public class TankLayerScan extends LogicComponent
|
||||
public boolean recurseStructureDown (int y)
|
||||
{
|
||||
Iterator i = tempAirCoords.iterator();
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
if (checkAir(coord.x, y, coord.z))
|
||||
if (i.hasNext())
|
||||
{
|
||||
boolean valid = true;
|
||||
|
||||
//Air blocks
|
||||
while (i.hasNext())
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
if (checkAir(coord.x, y, coord.z))
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkAir(coord.x, y, coord.z))
|
||||
{
|
||||
airCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
addAirBlock(coord.x, y, coord.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean valid = true;
|
||||
|
||||
//Bricks
|
||||
i = tempBlockCoords.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
return recurseStructureDown(y - 1);
|
||||
}
|
||||
else if (checkServant(coord.x, y, coord.z))
|
||||
{
|
||||
//Bottom floor. All blocks, please vacate the elevator
|
||||
boolean valid = true;
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void recurseStructureUp (int y)
|
||||
{
|
||||
Iterator i = tempBlockCoords.iterator();
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
{
|
||||
boolean valid = true;
|
||||
|
||||
//Bricks
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Air blocks
|
||||
if (valid)
|
||||
{
|
||||
i = tempAirCoords.iterator();
|
||||
//Air blocks
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkAir(coord.x, y, coord.z))
|
||||
{
|
||||
airCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
addAirBlock(coord.x, y, coord.z);
|
||||
}
|
||||
else
|
||||
@@ -339,16 +275,114 @@ public class TankLayerScan extends LogicComponent
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
recurseStructureUp(y + 1);
|
||||
//Bricks
|
||||
i = tempBlockCoords.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
return recurseStructureDown(y - 1);
|
||||
}
|
||||
else if (checkServant(coord.x, y, coord.z))
|
||||
{
|
||||
//Bottom floor. All blocks, please vacate the elevator
|
||||
boolean valid = true;
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void recurseStructureUp (int y)
|
||||
{
|
||||
Iterator i = tempBlockCoords.iterator();
|
||||
if (i.hasNext())
|
||||
{
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
{
|
||||
boolean valid = true;
|
||||
|
||||
//Bricks
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkServant(coord.x, y, coord.z))
|
||||
blockCoords.add(new CoordTuple(coord.x, y, coord.z));
|
||||
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Air blocks
|
||||
if (valid)
|
||||
{
|
||||
i = tempAirCoords.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
coord = (CoordTuple) i.next();
|
||||
if (checkAir(coord.x, y, coord.z))
|
||||
{
|
||||
addAirBlock(coord.x, y, coord.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
recurseStructureUp(y + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addAirBlock (int x, int y, int z)
|
||||
{
|
||||
airBlocks++;
|
||||
//world.setBlock(x + offset[0], y, z + offset[1], Block.leaves.blockID);
|
||||
airCoords.add(new CoordTuple(x, y, z));
|
||||
}
|
||||
|
||||
/** Do any necessary cleanup here. Remove air blocks, invalidate servants, etc */
|
||||
public void cleanup ()
|
||||
{
|
||||
Iterator i = blockCoords.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
CoordTuple coord = (CoordTuple) i.next();
|
||||
IServantLogic servant = (IServantLogic) world.getBlockTileEntity(coord.x, coord.y, coord.z);
|
||||
if (servant != null)
|
||||
servant.invalidateMaster(imaster, world, master.xCoord, master.yCoord, master.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user