diff --git a/src/tconstruct/TConstruct.java b/src/tconstruct/TConstruct.java index 7977fafb..f5073819 100644 --- a/src/tconstruct/TConstruct.java +++ b/src/tconstruct/TConstruct.java @@ -47,7 +47,7 @@ import cpw.mods.fml.relauncher.Side; * @dependencies: IC2 API, MFR API */ -@Mod(modid = "TConstruct", name = "TConstruct", version = "1.6.4_1.4.6d1", dependencies = "required-after:Forge@[8.9,)") +@Mod(modid = "TConstruct", name = "TConstruct", version = "1.6.4_1.4.7d", dependencies = "required-after:Forge@[8.9,)") @NetworkMod(serverSideRequired = false, clientSideRequired = true, channels = { "TConstruct" }, packetHandler = tconstruct.util.network.TPacketHandler.class) public class TConstruct { diff --git a/src/tconstruct/blocks/logic/MultiServantLogic.java b/src/tconstruct/blocks/logic/MultiServantLogic.java index fc94dca3..79bb5a09 100644 --- a/src/tconstruct/blocks/logic/MultiServantLogic.java +++ b/src/tconstruct/blocks/logic/MultiServantLogic.java @@ -36,12 +36,6 @@ public class MultiServantLogic extends TileEntity implements IServantLogic } } - @Override - public boolean canBeMaster (IMasterLogic logic, int x, int y, int z) - { - return true; - } - public CoordTuple getMasterPosition () { return master; @@ -71,6 +65,13 @@ public class MultiServantLogic extends TileEntity implements IServantLogic return false; } + @Override + public boolean setPotentialMaster (IMasterLogic master, int x, int y, int z) + { + // TODO Auto-generated method stub + return true; + } + public boolean setMaster (int x, int y, int z) { if (!hasMaster || worldObj.getBlockId(master.x, master.y, master.z) != masterID || (worldObj.getBlockMetadata(master.x, master.y, master.z) != masterMeat)) diff --git a/src/tconstruct/blocks/logic/TowerFurnaceLogic.java b/src/tconstruct/blocks/logic/TowerFurnaceLogic.java index c6c5aebd..338c7f69 100644 --- a/src/tconstruct/blocks/logic/TowerFurnaceLogic.java +++ b/src/tconstruct/blocks/logic/TowerFurnaceLogic.java @@ -79,4 +79,11 @@ public class TowerFurnaceLogic extends AdaptiveInventoryLogic implements IActive return null; } + @Override + protected boolean isValidBlock (int x, int y, int z) + { + // TODO Auto-generated method stub + return false; + } + } diff --git a/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java b/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java index b48e5be1..f82a8576 100644 --- a/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java +++ b/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java @@ -2,6 +2,7 @@ package tconstruct.library.blocks; import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.Random; import net.minecraft.block.Block; @@ -17,7 +18,7 @@ import tconstruct.library.util.IServantLogic; public abstract class AdaptiveInventoryLogic extends InventoryLogic implements IFacingLogic, IMasterLogic { Random random = new Random(); - protected boolean validStructure; + protected boolean completeStructure; protected int inventorySize; protected boolean needsUpdate; protected int tick = 0; @@ -141,6 +142,9 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I int bricks = 0; int airBlocks = 0; + HashSet tempBlockCoords = new HashSet(); + HashSet tempAirCoords = new HashSet(); + HashSet blockCoords = new HashSet(); HashSet airCoords = new HashSet(); ArrayList validAirCoords = new ArrayList(); @@ -171,7 +175,7 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I //Check for at least two connected blocks boolean validBlocks = false; - + //Recurse the structure int xPos = 0, zPos = 0; if (dir == 2) @@ -184,7 +188,7 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I zPos = 1; returnStone = new CoordTuple(xCoord - xPos, yCoord, zCoord - zPos); - if (recurseLayer(xCoord + xPos, yCoord, zCoord + zPos)) + if (initialRecurseLayer(xCoord + xPos, yCoord, zCoord + zPos)) { xPos = 0; zPos = 0; @@ -203,11 +207,38 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I xPos = -1; break; } - boolean air = floodTest(xCoord + xPos, yCoord, zCoord + zPos); - System.out.println("Air blocks: " + airBlocks); + if (!worldObj.isRemote) + System.out.println("Bricks in recursion: " + blockCoords.size()); + blockCoords.clear(); + bricks = 0; + + //Does the actual adding of blocks in the ring + boolean sealed = floodTest(xCoord + xPos, yCoord, zCoord + zPos); + if (!worldObj.isRemote) + { + System.out.println("Air in ring: " + airBlocks); + System.out.println("Bricks in ring: " + bricks); + } + + if (sealed) + { + tempAirCoords = new HashSet(airCoords); + tempBlockCoords = new HashSet(blockCoords); + + if (recurseStructureDown(yCoord - 1)) + { + completeStructure = true; + recurseStructureUp(yCoord + 1); + + if (!worldObj.isRemote) + { + System.out.println("Air in structure: " + airCoords.size()); + System.out.println("Bricks in structure: " + blockCoords.size()); + } + } + } } - System.out.println("Bricks: " + blockCoords.size()); } protected boolean checkAir (int x, int y, int z) @@ -230,12 +261,12 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I TileEntity be = worldObj.getBlockTileEntity(x, y, z); if (be instanceof IServantLogic) - return ((IServantLogic)be).canBeMaster(this, x, y, z); + return ((IServantLogic) be).setPotentialMaster(this, x, y, z); return false; } - protected boolean recurseLayer (int x, int y, int z) + protected boolean initialRecurseLayer (int x, int y, int z) { if (bricks >= 4095) return false; @@ -251,12 +282,11 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I CoordTuple coord = new CoordTuple(x + xPos, y, z + zPos); if (!blockCoords.contains(coord)) { - int blockID = worldObj.getBlockId(x + xPos, y, z + zPos); - if (blockID == Block.stoneBrick.blockID) //TContent.smeltery.blockID, Needs different checking + if (isValidBlock(x + xPos, y, z + zPos)) { bricks++; blockCoords.add(coord); - return recurseLayer(x + xPos, y, z + zPos); + return initialRecurseLayer(x + xPos, y, z + zPos); } } } @@ -265,11 +295,13 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I return false; } + protected abstract boolean isValidBlock (int x, int y, int z); + protected boolean floodTest (int x, int y, int z) { if (airBlocks >= 4095) return false; - + for (int[] offset : validAirCoords) { CoordTuple coord = new CoordTuple(x + offset[0], y, z + offset[1]); @@ -282,16 +314,126 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I //worldObj.setBlock(x + offset[0], y, z + offset[1], Block.leaves.blockID); 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; } - - public void cleanup() + + public boolean recurseStructureDown (int y) + { + Iterator i = tempAirCoords.iterator(); + CoordTuple coord = (CoordTuple) i.next(); + if (checkAir(coord.x, y, coord.z)) + { + boolean valid = true; + + //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)); + + else + { + valid = false; + break; + } + } + + //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 = tempAirCoords.iterator(); + CoordTuple coord = (CoordTuple) i.next(); + if (checkAir(coord.x, y, coord.z)) + { + boolean valid = true; + + //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)); + + else + { + valid = false; + break; + } + } + + //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) + recurseStructureUp(y + 1); + } + } + + public void cleanup () { for (CoordTuple coord : airCoords) { - worldObj.setBlockToAir(coord.x, coord.y, coord.z); + worldObj.setBlockToAir(coord.x, coord.y, coord.z); } } diff --git a/src/tconstruct/library/util/IMasterLogic.java b/src/tconstruct/library/util/IMasterLogic.java index 1ca17169..e6421367 100644 --- a/src/tconstruct/library/util/IMasterLogic.java +++ b/src/tconstruct/library/util/IMasterLogic.java @@ -2,5 +2,11 @@ package tconstruct.library.util; public interface IMasterLogic { + /** Called when servants change their state + * + * @param x Servant X + * @param y Servant Y + * @param z Servant Z + */ public void notifyChange (int x, int y, int z); } diff --git a/src/tconstruct/library/util/IServantLogic.java b/src/tconstruct/library/util/IServantLogic.java index a3e4c640..5aa0cb2e 100644 --- a/src/tconstruct/library/util/IServantLogic.java +++ b/src/tconstruct/library/util/IServantLogic.java @@ -4,17 +4,32 @@ public interface IServantLogic { public CoordTuple getMasterPosition (); + /** The block should already have a valid master */ public void notifyMasterOfChange (); - /** Used to check whether a given master can own this servant + /** Checks if this block can be tied to this master + * + * @param master + * @param x xCoord of master + * @param y yCoord of master + * @param z zCoord of master + * @return whether the servant can be tied to this master */ - public boolean canBeMaster(IMasterLogic master, int x, int y, int z); + public boolean setPotentialMaster(IMasterLogic master, int x, int y, int z); - /** Checks whether the given master and coords are valid + /** Used to set and verify that this is the block's master + * + * @param master + * @param x xCoord of master + * @param y yCoord of master + * @param z zCoord of master + * @return Is this block tied to this master? */ public boolean verifyMaster (IMasterLogic master, int x, int y, int z); + /* Deprecated in favor of setPotentialMaster and verifyMaster */ + @Deprecated public boolean setMaster (int x, int y, int z); } diff --git a/test/XinStick.java b/test/XinStick.java index 3f263b96..1ef4affd 100644 --- a/test/XinStick.java +++ b/test/XinStick.java @@ -8,7 +8,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.world.World; -import bastion.entity.friendly.GardeSlime; +import bastion.entity.WoodMinecartEntity; /* * mDiyo's development testing item @@ -32,8 +32,8 @@ public class XinStick extends Item public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player) { //clearInventoryExeptHotbar(player); - GardeSlime entity = new GardeSlime(world); - entity.setLeader(player); + WoodMinecartEntity entity = new WoodMinecartEntity(world); + //entity.setLeader(player); //entity.setCustomNameTag("Cutie"); spawnEntity(player.posX, player.posY + 1, player.posZ, entity, world, player); /*EntityChicken chicken = new EntityChicken(world);