diff options
author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-10-25 19:57:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-25 17:57:25 +0000 |
commit | 4b855e815f5584313254151d36b168d53668400b (patch) | |
tree | d390306d5f837aef8d71856b0eabea7eae82272d /src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java | |
parent | 5304c190cf303c4c355ebeafdb63f84470be350e (diff) | |
download | GT5-Unofficial-4b855e815f5584313254151d36b168d53668400b.tar.gz GT5-Unofficial-4b855e815f5584313254151d36b168d53668400b.tar.bz2 GT5-Unofficial-4b855e815f5584313254151d36b168d53668400b.zip |
Fix World leak caused by BlockPos class from GT++ (#3414)
Diffstat (limited to 'src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java')
-rw-r--r-- | src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java | 169 |
1 files changed, 4 insertions, 165 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); - } } |