diff options
3 files changed, 60 insertions, 251 deletions
diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java index 8145a2d3e9..d3e7f71eaf 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -1,14 +1,8 @@ package gtPlusPlus.api.objects.minecraft; import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; -import net.minecraft.block.Block; -import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -19,7 +13,6 @@ public class BlockPos implements Serializable { public final int yPos; public final int zPos; public final int dim; - public final transient World world; public static BlockPos generateBlockPos(String sUUID) { String[] s2 = sUUID.split("@"); @@ -30,36 +23,21 @@ public class BlockPos implements Serializable { this(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[0])); } - public BlockPos(int x, int y, int z) { - this(x, y, z, 0); - } - public BlockPos(int x, int y, int z, int dim) { - this(x, y, z, DimensionManager.getWorld(dim)); - } - - public BlockPos(int x, int y, int z, World dim) { this.xPos = x; this.yPos = y; this.zPos = z; + this.dim = dim; + } - if (dim != null) { - this.dim = dim.provider.dimensionId; - this.world = dim; - } else { - this.dim = 0; - this.world = null; - } + public BlockPos(int x, int y, int z, World world) { + this(x, y, z, world == null ? 0 : world.provider.dimensionId); } public BlockPos(IGregTechTileEntity b) { this(b.getXCoord(), b.getYCoord(), b.getZCoord(), b.getWorld()); } - public BlockPos(TileEntity b) { - this(b.xCoord, b.yCoord, b.zCoord, b.getWorldObj()); - } - public String getLocationString() { return "[X: " + this.xPos + "][Y: " + this.yPos + "][Z: " + this.zPos + "][Dim: " + this.dim + "]"; } @@ -94,147 +72,8 @@ public class BlockPos implements Serializable { && this.dim == otherPoint.dim; } - public int distanceFrom(BlockPos target) { - if (target.dim != this.dim) { - return Short.MIN_VALUE; - } - return distanceFrom(target.xPos, target.yPos, target.zPos); - } - - /** - * - * @param x X coordinate of target. - * @param y Y coordinate of target. - * @param z Z coordinate of target. - * @return square of distance - */ - public int distanceFrom(int x, int y, int z) { - int distanceX = this.xPos - x; - int distanceY = this.yPos - y; - int distanceZ = this.zPos - z; - return distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ; - } - - public boolean isWithinRange(BlockPos target, int range) { - if (target.dim != this.dim) { - return false; - } - return isWithinRange(target.xPos, target.yPos, target.zPos, range); - } - - public boolean isWithinRange(int x, int y, int z, int range) { - return distanceFrom(x, y, z) <= (range * range); - } - public BlockPos getUp() { return new BlockPos(this.xPos, this.yPos + 1, this.zPos, this.dim); } - public BlockPos getDown() { - return new BlockPos(this.xPos, this.yPos - 1, this.zPos, this.dim); - } - - public BlockPos getXPos() { - return new BlockPos(this.xPos + 1, this.yPos, this.zPos, this.dim); - } - - public BlockPos getXNeg() { - return new BlockPos(this.xPos - 1, this.yPos, this.zPos, this.dim); - } - - public BlockPos getZPos() { - return new BlockPos(this.xPos, this.yPos, this.zPos + 1, this.dim); - } - - public BlockPos getZNeg() { - return new BlockPos(this.xPos, this.yPos, this.zPos - 1, this.dim); - } - - public ArrayList<BlockPos> getSurroundingBlocks() { - ArrayList<BlockPos> sides = new ArrayList<>(); - sides.add(getUp()); - sides.add(getDown()); - sides.add(getXPos()); - sides.add(getXNeg()); - sides.add(getZPos()); - sides.add(getZNeg()); - return sides; - } - - public Block getBlockAtPos() { - return getBlockAtPos(this); - } - - public Block getBlockAtPos(BlockPos pos) { - return getBlockAtPos(world, pos); - } - - public Block getBlockAtPos(World world, BlockPos pos) { - return world.getBlock(pos.xPos, pos.yPos, pos.zPos); - } - - public int getMetaAtPos() { - return getMetaAtPos(this); - } - - public int getMetaAtPos(BlockPos pos) { - return getMetaAtPos(world, pos); - } - - public int getMetaAtPos(World world, BlockPos pos) { - return world.getBlockMetadata(pos.xPos, pos.yPos, pos.zPos); - } - - public boolean hasSimilarNeighbour() { - return hasSimilarNeighbour(false); - } - - /** - * @param strict - Does this check Meta Data? - * @return - Does this block have a neighbour that is the same? - */ - public boolean hasSimilarNeighbour(boolean strict) { - for (BlockPos g : getSurroundingBlocks()) { - if (getBlockAtPos(g) == getBlockAtPos()) { - if (!strict) { - return true; - } else { - if (getMetaAtPos() == getMetaAtPos(g)) { - return true; - } - } - } - } - return false; - } - - public ArrayList<BlockPos> getSimilarNeighbour() { - return getSimilarNeighbour(false); - } - - /** - * @param strict - Does this check Meta Data? - * @return - Does this block have a neighbour that is the same? - */ - public ArrayList<BlockPos> getSimilarNeighbour(boolean strict) { - ArrayList<BlockPos> sides = new ArrayList<>(); - for (BlockPos g : getSurroundingBlocks()) { - if (getBlockAtPos(g) == getBlockAtPos()) { - if (!strict) { - sides.add(g); - } else { - if (getMetaAtPos() == getMetaAtPos(g)) { - sides.add(g); - } - } - } - } - return sides; - } - - public Set<BlockPos> getValidNeighboursAndSelf() { - ArrayList<BlockPos> h = getSimilarNeighbour(true); - h.add(this); - return new HashSet<>(h); - } } diff --git a/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java b/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java index cf6ad5b663..61e0e1569a 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java +++ b/src/main/java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java @@ -21,7 +21,6 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import gtPlusPlus.api.objects.minecraft.BTF_FluidTank; -import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.tileentities.base.TileEntityBase; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; @@ -33,7 +32,6 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem private boolean needsUpdate = false; private int updateTimer = 0; private long internalTickCounter = 0; - private BlockPos internalBlockLocation; public TileEntityBaseFluidCollector(int aInvSlotCount, int aTankCapcity) { super(aInvSlotCount); @@ -158,39 +156,25 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem return; } if (internalTickCounter % getBaseTickRate() == 0) { - if (internalBlockLocation == null) { - internalBlockLocation = new BlockPos(this); - } - BlockPos p = internalBlockLocation; - if (p != null) { - if (p.world != null) { - World w = this.worldObj; - if (w == null) { - return; - } - Chunk c = w.getChunkFromBlockCoords(p.xPos, p.zPos); - if (c != null) { - if (c.isChunkLoaded) { - int startX = p.xPos - 2; - int startY = p.yPos; - int startZ = p.zPos - 2; - int endX = p.xPos + 3; - int endY = p.yPos + 5; - int endZ = p.zPos + 3; - AxisAlignedBB box = AxisAlignedBB.getBoundingBox(startX, startY, startZ, endX, endY, endZ); - if (box != null) { - for (Class c2 : aThingsToLookFor()) { - tickEntityType(w, box, c2); - } - } else { - return; - } + final World w = this.getWorldObj(); + if (w != null) { + Chunk c = w.getChunkFromBlockCoords(this.xCoord, this.zCoord); + if (c != null) { + if (c.isChunkLoaded) { + int startX = this.xCoord - 2; + int startY = this.yCoord; + int startZ = this.zCoord - 2; + int endX = this.xCoord + 3; + int endY = this.yCoord + 5; + int endZ = this.zCoord + 3; + AxisAlignedBB box = AxisAlignedBB.getBoundingBox(startX, startY, startZ, endX, endY, endZ); + for (Class c2 : aThingsToLookFor()) { + tickEntityType(w, box, c2); } } } } } - internalTickCounter++; } diff --git a/src/main/java/gtPlusPlus/everglades/block/BlockEvergladesPortal.java b/src/main/java/gtPlusPlus/everglades/block/BlockEvergladesPortal.java index 5afc3dc569..f636bb9100 100644 --- a/src/main/java/gtPlusPlus/everglades/block/BlockEvergladesPortal.java +++ b/src/main/java/gtPlusPlus/everglades/block/BlockEvergladesPortal.java @@ -20,7 +20,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.api.interfaces.ITileTooltip; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.core.util.Utils; import gtPlusPlus.everglades.dimension.DimensionEverglades; @@ -42,7 +41,6 @@ public class BlockEvergladesPortal extends BlockBreakable implements ITileToolti @SideOnly(Side.CLIENT) @Override public IIcon getIcon(int ordinalSide, int meta) { - if (ordinalSide == 0) return gor; else if (ordinalSide == 1) return dol; else if (ordinalSide == 2) return st1; @@ -67,23 +65,29 @@ public class BlockEvergladesPortal extends BlockBreakable implements ITileToolti * Ticks the block if it's been scheduled */ @Override - public void updateTick(World par1World, int x, int y, int z, Random par5Random) { - super.updateTick(par1World, x, y, z, par5Random); + public void updateTick(World world, int x, int y, int z, Random random) { + super.updateTick(world, x, y, z, random); + validatePortalStructure(world, x, y, z); + } + private static void validatePortalStructure(World world, int x, int y, int z) { int blockCount = 0; - BlockPos portal = new BlockPos(x, y, z, par1World.provider.dimensionId); - - for (BlockPos side : portal.getSurroundingBlocks()) { - Block b = side.getBlockAtPos(); - if (b == DimensionEverglades.blockPortalFrame || b == DimensionEverglades.portalBlock) { - blockCount++; - } - } + blockCount += isPortalBlock(world.getBlock(x, y + 1, z)); + blockCount += isPortalBlock(world.getBlock(x, y - 1, z)); + blockCount += isPortalBlock(world.getBlock(x + 1, y, z)); + blockCount += isPortalBlock(world.getBlock(x - 1, y, z)); + blockCount += isPortalBlock(world.getBlock(x, y, z + 1)); + blockCount += isPortalBlock(world.getBlock(x, y, z - 1)); if (blockCount < 4) { - par1World.setBlockToAir(x, y, z); + world.setBlockToAir(x, y, z); } } + private static int isPortalBlock(Block b) { + final boolean validBlock = b == DimensionEverglades.blockPortalFrame || b == DimensionEverglades.portalBlock; + return validBlock ? 1 : 0; + } + /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) @@ -181,72 +185,54 @@ public class BlockEvergladesPortal extends BlockBreakable implements ITileToolti * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor blockID */ - public void onNeighborBlockChange(BlockPos pos) { - int x = pos.xPos, y = pos.yPos, z = pos.zPos; + public void onNeighborBlockChange(World world, int x, int y, int z) { Logger.INFO("Trigger"); - int blockCount = 0; - World par1World = pos.world; - for (BlockPos side : pos.getSurroundingBlocks()) { - Block b = side.getBlockAtPos(); - if (b == DimensionEverglades.blockPortalFrame || b == DimensionEverglades.portalBlock) { - blockCount++; - } - } - if (blockCount < 4) { - par1World.setBlockToAir(x, y, z); - par1World.scheduleBlockUpdate(x, y, z, pos.getBlockAtPos(), 0); - } + validatePortalStructure(world, x, y, z); byte b0 = 0; byte b1 = 1; - if (par1World.getBlock(x - 1, y, z) == this || par1World.getBlock(x + 1, y, z) == this) { + if (world.getBlock(x - 1, y, z) == this || world.getBlock(x + 1, y, z) == this) { b0 = 1; b1 = 0; } int i1; - for (i1 = y; par1World.getBlock(x, i1 - 1, z) == this; --i1) {} - if (par1World.getBlock(x, i1 - 1, z) != DimensionEverglades.blockPortalFrame) { - par1World.setBlockToAir(x, y, z); + for (i1 = y; world.getBlock(x, i1 - 1, z) == this; --i1) {} + if (world.getBlock(x, i1 - 1, z) != DimensionEverglades.blockPortalFrame) { + world.setBlockToAir(x, y, z); } else { int j1; - for (j1 = 1; j1 < 4 && par1World.getBlock(x, i1 + j1, z) == this; ++j1) {} - if (j1 == 3 && par1World.getBlock(x, i1 + j1, z) == DimensionEverglades.blockPortalFrame) { - boolean flag = par1World.getBlock(x - 1, y, z) == this || par1World.getBlock(x + 1, y, z) == this; - boolean flag1 = par1World.getBlock(x, y, z - 1) == this || par1World.getBlock(x, y, z + 1) == this; + for (j1 = 1; j1 < 4 && world.getBlock(x, i1 + j1, z) == this; ++j1) {} + if (j1 == 3 && world.getBlock(x, i1 + j1, z) == DimensionEverglades.blockPortalFrame) { + boolean flag = world.getBlock(x - 1, y, z) == this || world.getBlock(x + 1, y, z) == this; + boolean flag1 = world.getBlock(x, y, z - 1) == this || world.getBlock(x, y, z + 1) == this; if (flag && flag1) { - par1World.setBlockToAir(x, y, z); + world.setBlockToAir(x, y, z); } else { - if ((par1World.getBlock(x + b0, y, z + b1) != DimensionEverglades.blockPortalFrame - || par1World.getBlock(x - b0, y, z - b1) != this) - && (par1World.getBlock(x - b0, y, z - b1) != DimensionEverglades.blockPortalFrame - || par1World.getBlock(x + b0, y, z + b1) != this)) { - par1World.setBlockToAir(x, y, z); + if ((world.getBlock(x + b0, y, z + b1) != DimensionEverglades.blockPortalFrame + || world.getBlock(x - b0, y, z - b1) != this) + && (world.getBlock(x - b0, y, z - b1) != DimensionEverglades.blockPortalFrame + || world.getBlock(x + b0, y, z + b1) != this)) { + world.setBlockToAir(x, y, z); } } } else { - par1World.setBlockToAir(x, y, z); + world.setBlockToAir(x, y, z); } } } @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { - onNeighborBlockChange(new BlockPos(x, y, z, world.provider.dimensionId)); + onNeighborBlockChange(world, x, y, z); super.onNeighborBlockChange(world, x, y, z, block); } - /* - * @Override public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) - * { onNeighborBlockChange(new BlockPos(x, y, z, world.)); super.onNeighborChange(world, x, y, z, tileX, tileY, - * tileZ); } - */ - - @Override - @SideOnly(Side.CLIENT) /** * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given * coordinates. Args: blockAccess, x, y, z, side */ + @Override + @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { if (par1IBlockAccess.getBlock(par2, par3, par4) == this) { return false; @@ -301,20 +287,20 @@ public class BlockEvergladesPortal extends BlockBreakable implements ITileToolti } } - @Override - @SideOnly(Side.CLIENT) /** * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha */ + @Override + @SideOnly(Side.CLIENT) public int getRenderBlockPass() { return 1; } - @Override - @SideOnly(Side.CLIENT) /** * A randomly called display update to be able to add particles or other items for display */ + @Override + @SideOnly(Side.CLIENT) public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) { if (GTPPCore.RANDOM.nextInt(100) == 0) { par1World.playSound( @@ -357,10 +343,10 @@ public class BlockEvergladesPortal extends BlockBreakable implements ITileToolti } } - @SideOnly(Side.CLIENT) /** * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) */ + @SideOnly(Side.CLIENT) public int idPicked(World par1World, int par2, int par3, int par4) { return 0; } |