diff options
| author | Martin Robertz <dream-master@gmx.net> | 2021-12-15 16:11:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-15 16:11:54 +0100 |
| commit | 128c74faa99dfef8d056c1d82c6e4388b9d470e8 (patch) | |
| tree | 2c84162154ba681232f86dffd4106db530236814 /src/main/java/gtPlusPlus/api/objects/minecraft | |
| parent | 47ce336f288a45aa3244c8ae1177499fa5080942 (diff) | |
| parent | ff4b8c7068c2ea7d654e9beda00646d23e62b314 (diff) | |
| download | GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.gz GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.tar.bz2 GT5-Unofficial-128c74faa99dfef8d056c1d82c6e4388b9d470e8.zip | |
Merge pull request #65 from GTNewHorizons/unified-build-script2
Move sources and resources
Diffstat (limited to 'src/main/java/gtPlusPlus/api/objects/minecraft')
22 files changed, 2190 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java b/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java new file mode 100644 index 0000000000..722ac00b64 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java @@ -0,0 +1,65 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.core.util.minecraft.EntityUtils; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +/** + * Generates an AABB around an entity. + * @author Alkalus + * + */ +public class AABB { + + private final AxisAlignedBB mAabb; + private final World mWorld; + + /** + * Creates a AxisAlignedBB based around an Entity. + * @param aEntity - The Entity to work with. + * @param x - Maximum X from origin. + * @param y - Maximum Y from origin. + * @param z - Maximum Z from origin. + */ + public AABB(Entity aEntity, int x, int y, int z) { + if (aEntity == null) { + mAabb = null; + mWorld = null; + } + else { + mWorld = aEntity.worldObj; + BlockPos aEntityLocation = EntityUtils.findBlockPosUnderEntity(aEntity); + int xMin, xMax, yMin, yMax, zMin, zMax; + xMin = aEntityLocation.xPos; + yMin = aEntityLocation.yPos; + zMin = aEntityLocation.zPos; + xMax = aEntityLocation.xPos + x; + yMax = aEntityLocation.yPos + y; + zMax = aEntityLocation.zPos + z; + mAabb = AxisAlignedBB.getBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax); + } + + } + + /** + * Used to get the AxisAlignedBB from this class. + * @return + */ + public AxisAlignedBB get() { + return mAabb; + } + + /** + * Used to determine if this object is valid or not. + * @return + */ + public boolean valid() { + return mAabb != null && mWorld != null; + } + + public World world() { + return mWorld; + } + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_FluidTank.java b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_FluidTank.java new file mode 100644 index 0000000000..0b8f97b378 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_FluidTank.java @@ -0,0 +1,188 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.core.util.minecraft.FluidUtils; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; + +public class BTF_FluidTank extends FluidTank { + + public FluidStack mFluid; + + public BTF_FluidTank(int capacity) { + super(capacity); + } + + /** + * Let's replace the Default handling with GT's own handling code, because it's probably better, right? + * @author Alkalus/GregoriusT + */ + + + public FluidStack getFluid() { + return this.getDrainableStack(); + } + + public int getFluidAmount() { + return this.getDrainableStack() != null ? this.getDrainableStack().amount : 0; + } + + public NBTTagCompound writeToNBT(NBTTagCompound aNBT) { + super.writeToNBT(aNBT); + if (this.mFluid != null) { + aNBT.setTag("mFluid", this.mFluid.writeToNBT(new NBTTagCompound())); + } + return aNBT; + } + + public FluidTank readFromNBT(NBTTagCompound aNBT) { + this.mFluid = FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mFluid")); + return this; + } + +/* public abstract boolean isLiquidInput(byte arg0); + + public abstract boolean isLiquidOutput(byte arg0); + + public abstract boolean doesFillContainers(); + + public abstract boolean doesEmptyContainers();*/ + + public boolean canTankBeFilled() { + return true; + } + + public boolean canTankBeEmptied() { + return true; + } + + + public boolean isFluidInputAllowed(FluidStack aFluid) { + return true; + } + + public FluidStack getFillableStack() { + return this.mFluid; + } + + public FluidStack setFillableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + public FluidStack getDrainableStack() { + return this.mFluid; + } + + public FluidStack setDrainableStack(FluidStack aFluid) { + this.mFluid = aFluid; + return this.mFluid; + } + + public FluidStack getDisplayedFluid() { + return this.getDrainableStack(); + } + + public boolean isFluidChangingAllowed() { + return true; + } + + public int fill(FluidStack aFluid, boolean doFill) { + if (aFluid != null && aFluid.getFluid().getID() > 0 && aFluid.amount > 0 && this.canTankBeFilled() + && this.isFluidInputAllowed(aFluid)) { + if (this.getFillableStack() != null && this.getFillableStack().getFluid().getID() > 0) { + if (!this.getFillableStack().isFluidEqual(aFluid)) { + return 0; + } else { + int space = this.getCapacity() - this.getFillableStack().amount; + if (aFluid.amount <= space) { + if (doFill) { + FluidStack arg9999 = this.getFillableStack(); + arg9999.amount += aFluid.amount; + } + + return aFluid.amount; + } else { + if (doFill) { + this.getFillableStack().amount = this.getCapacity(); + } + + return space; + } + } + } else if (aFluid.amount <= this.getCapacity()) { + if (doFill) { + this.setFillableStack(aFluid.copy()); + } + + return aFluid.amount; + } else { + if (doFill) { + this.setFillableStack(aFluid.copy()); + this.getFillableStack().amount = this.getCapacity(); + } + + return this.getCapacity(); + } + } else { + return 0; + } + } + + public FluidStack drain(int maxDrain, boolean doDrain) { + if (this.getDrainableStack() != null && this.canTankBeEmptied()) { + if (this.getDrainableStack().amount <= 0 && this.isFluidChangingAllowed()) { + this.setDrainableStack((FluidStack) null); + return null; + } else { + int used = maxDrain; + if (this.getDrainableStack().amount < maxDrain) { + used = this.getDrainableStack().amount; + } + + if (doDrain) { + FluidStack arg9999 = this.getDrainableStack(); + arg9999.amount -= used; + } + + FluidStack drained = this.getDrainableStack().copy(); + drained.amount = used; + if (this.getDrainableStack().amount <= 0 && this.isFluidChangingAllowed()) { + this.setDrainableStack((FluidStack) null); + } + + return drained; + } + } else { + return null; + } + } + + @Override + public int getCapacity() { + return super.getCapacity(); + } + + @Override + public FluidTankInfo getInfo() { + return new FluidTankInfo(this); + } + + @Override + public void setFluid(FluidStack fluid) { + setFillableStack(fluid); + } + + @Override + public void setCapacity(int capacity) { + super.setCapacity(capacity); + } + + public FluidStack drain(FluidStack aFluid, boolean doDrain) { + return drain(aFluid.amount, doDrain); + } + + + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java new file mode 100644 index 0000000000..04ce0dff19 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java @@ -0,0 +1,228 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.ArrayList; + +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.tileentities.base.TileEntityBase; +import gtPlusPlus.core.util.data.ArrayUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; + +public class BTF_Inventory implements ISidedInventory{ + + public final ItemStack[] mInventory; + public final TileEntityBase mTile; + + public BTF_Inventory(int aSlots, TileEntityBase tile) { + this.mInventory = new ItemStack[aSlots]; + this.mTile = tile; + } + + public ItemStack[] getRealInventory() { + purgeNulls(); + return this.mInventory; + } + + public int getSizeInventory() { + return this.mInventory.length; + } + + public ItemStack getStackInSlot(int aIndex) { + return aIndex >= 0 && aIndex < this.mInventory.length ? this.mInventory[aIndex] : null; + } + + public void setInventorySlotContents(int aIndex, ItemStack aStack) { + if (aIndex >= 0 && aIndex < this.mInventory.length) { + this.mInventory[aIndex] = aStack; + } + } + + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + public boolean isValidSlot(int aIndex) { + return true; + } + + public int getInventoryStackLimit() { + return 64; + } + + + public boolean setStackToZeroInsteadOfNull(int aIndex) { + return false; +} + + public boolean isItemValidForSlot(int aIndex, ItemStack aStack) { + return isValidSlot(aIndex); + } + + public ItemStack decrStackSize(int aIndex, int aAmount) { + ItemStack tStack = this.getStackInSlot(aIndex); + ItemStack rStack = GT_Utility.copy(new Object[]{tStack}); + if (tStack != null) { + if (tStack.stackSize <= aAmount) { + if (this.setStackToZeroInsteadOfNull(aIndex)) { + tStack.stackSize = 0; + } else { + this.setInventorySlotContents(aIndex, (ItemStack) null); + } + } else { + rStack = tStack.splitStack(aAmount); + if (tStack.stackSize == 0 && !this.setStackToZeroInsteadOfNull(aIndex)) { + this.setInventorySlotContents(aIndex, (ItemStack) null); + } + } + } + + return rStack; + } + + public int[] getAccessibleSlotsFromSide(int aSide) { + ArrayList<Integer> tList = new ArrayList<Integer>(); + TileEntityBase tTileEntity = this.mTile; + boolean tSkip = tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, + tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, + tTileEntity) + || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, + tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), -2, + tTileEntity); + + for (int rArray = 0; rArray < this.getSizeInventory(); ++rArray) { + if (this.isValidSlot(rArray) && (tSkip + || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsOut((byte) aSide, + tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), + rArray, tTileEntity) + || tTileEntity.getCoverBehaviorAtSide((byte) aSide).letsItemsIn((byte) aSide, + tTileEntity.getCoverIDAtSide((byte) aSide), tTileEntity.getCoverDataAtSide((byte) aSide), + rArray, tTileEntity))) { + tList.add(Integer.valueOf(rArray)); + } + } + + int[] arg6 = new int[tList.size()]; + + for (int i = 0; i < arg6.length; ++i) { + arg6[i] = ((Integer) tList.get(i)).intValue(); + } + + return arg6; + } + + public boolean canInsertItem(int aIndex, ItemStack aStack, int aSide) { + return this.isValidSlot(aIndex) && aStack != null && aIndex < this.mInventory.length + && (this.mInventory[aIndex] == null || GT_Utility.areStacksEqual(aStack, this.mInventory[aIndex])) + && this.allowPutStack(this.mTile, aIndex, (byte) aSide, aStack); + } + + public boolean canExtractItem(int aIndex, ItemStack aStack, int aSide) { + return this.isValidSlot(aIndex) && aStack != null && aIndex < this.mInventory.length + && this.allowPullStack(this.mTile, aIndex, (byte) aSide, aStack); + } + + public boolean allowPullStack(TileEntityBase mTile2, int aIndex, byte aSide, ItemStack aStack) { + return aIndex >= 0 && aIndex < this.getSizeInventory(); + } + + public boolean allowPutStack(TileEntityBase aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return (aIndex >= 0 && aIndex < this.getSizeInventory()) && (this.mInventory[aIndex] == null || GT_Utility.areStacksEqual(this.mInventory[aIndex], aStack)); + } + + public ItemStack getStackInSlotOnClosing(int i) { + return null; + } + + public final boolean hasCustomInventoryName() { + return mTile != null ? mTile.hasCustomInventoryName() : false; + } + + + public void markDirty() { + if (mTile != null) { + purgeNulls(); + mTile.markDirty(); + } + } + + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return true; + } + + public void openInventory() { + + } + + public void closeInventory() { + + } + + @Override + public final String getInventoryName() { + return this.mTile != null ? mTile.getInventoryName() : ""; + } + + public boolean isFull() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null || slot.stackSize != slot.getMaxStackSize()) { + return false; + } + } + return true; + } + + public boolean isEmpty() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null) { + continue; + } + else { + return false; + } + } + return true; + } + + public boolean addItemStack(ItemStack aInput) { + if (aInput != null & (isEmpty() || !isFull())) { + for (int s = 0; s < this.getSizeInventory(); s++) { + if (mInventory != null && mInventory[s] != null) { + ItemStack slot = mInventory[s]; + if (slot == null || (slot != null && GT_Utility.areStacksEqual(aInput, slot) && slot.stackSize != slot.getItem().getItemStackLimit(slot))) { + if (slot == null) { + slot = aInput.copy(); + } else { + slot.stackSize++; + } + this.setInventorySlotContents(s, slot); + return true; + } + } + } + } + return false; + } + + public final void purgeNulls() { + ItemStack[] aTemp = ArrayUtils.removeNulls(this.mInventory); + for (int g=0;g<this.getSizeInventory();g++) { + if (aTemp.length < this.getSizeInventory()) { + if (g <= aTemp.length-1) { + this.mInventory[g] = aTemp[g]; + } + else { + this.mInventory[g] = null; + } + } + else { + this.mInventory[g] = aTemp[g]; + } + } + + } + + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java new file mode 100644 index 0000000000..ab359c3853 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -0,0 +1,250 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraftforge.common.DimensionManager; + +public class BlockPos implements Serializable{ + + private static final long serialVersionUID = -7271947491316682006L; + public final int xPos; + 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("@"); + return new BlockPos(s2); + } + + public BlockPos(String[] s){ + 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; + + if (dim != null) { + this.dim = dim.provider.dimensionId; + this.world = dim; + } + else { + this.dim = 0; + this.world = null; + } + + } + + 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+"]"; + } + + public String getUniqueIdentifier() { + String S = ""+this.dim+"@"+this.xPos+"@"+this.yPos+"@"+this.zPos; + return S; + } + + @Override + public int hashCode() { + int hash = 5; + hash += (13 * this.xPos); + hash += (19 * this.yPos); + hash += (31 * this.zPos); + hash += (17 * this.dim); + return hash; + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other == this) { + return true; + } + if(!(other instanceof BlockPos)) { + return false; + } + BlockPos otherPoint = (BlockPos)other; + return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos && 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 AutoMap<BlockPos> getSurroundingBlocks(){ + AutoMap<BlockPos> sides = new AutoMap<BlockPos>(); + sides.put(getUp()); + sides.put(getDown()); + sides.put(getXPos()); + sides.put(getXNeg()); + sides.put(getZPos()); + sides.put(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().values()) { + if (getBlockAtPos(g) == getBlockAtPos()) { + if (!strict) { + return true; + } + else { + if (getMetaAtPos() == getMetaAtPos(g)) { + return true; + } + } + } + } + return false; + } + + public AutoMap<BlockPos> getSimilarNeighbour() { + return getSimilarNeighbour(false); + } + + /** + * @param strict - Does this check Meta Data? + * @return - Does this block have a neighbour that is the same? + */ + public AutoMap<BlockPos> getSimilarNeighbour(boolean strict) { + AutoMap<BlockPos> sides = new AutoMap<BlockPos>(); + for (BlockPos g : getSurroundingBlocks().values()) { + if (getBlockAtPos(g) == getBlockAtPos()) { + if (!strict) { + sides.put(g); + } + else { + if (getMetaAtPos() == getMetaAtPos(g)) { + sides.put(g); + } + } + } + } + return sides; + } + + public Set<BlockPos> getValidNeighboursAndSelf(){ + AutoMap<BlockPos> h = getSimilarNeighbour(true); + h.put(this); + Set<BlockPos> result = new HashSet<BlockPos>(); + for (BlockPos f : h.values()) { + result.add(f); + } + return result; + } + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java b/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java new file mode 100644 index 0000000000..8c76513d09 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java @@ -0,0 +1,62 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraftforge.common.util.ForgeDirection; + +public class CubicObject<T> { + + public final T NORTH; + public final T SOUTH; + + public final T WEST; + public final T EAST; + + public final T UP; + public final T DOWN; + + public CubicObject(AutoMap<T> aDataSet) { + this(aDataSet.get(0), aDataSet.get(1), aDataSet.get(2), aDataSet.get(3), aDataSet.get(4), aDataSet.get(5)); + } + + public CubicObject(T[] aDataSet) { + this(aDataSet[0], aDataSet[1], aDataSet[2], aDataSet[3], aDataSet[4], aDataSet[5]); + } + + public CubicObject(T aDOWN, T aUP, T aNORTH, T aSOUTH, T aWEST, T aEAST) { + DOWN = aDOWN; + UP = aUP; + NORTH = aNORTH; + SOUTH = aSOUTH; + WEST = aWEST; + EAST = aEAST; + } + + public T get(int aSide) { + return get(ForgeDirection.getOrientation(aSide)); + } + + public T get(ForgeDirection aSide) { + if (aSide == ForgeDirection.DOWN) { + return DOWN; + } + else if (aSide == ForgeDirection.UP) { + return UP; + } + else if (aSide == ForgeDirection.NORTH) { + return NORTH; + } + else if (aSide == ForgeDirection.SOUTH) { + return SOUTH; + } + else if (aSide == ForgeDirection.WEST) { + return WEST; + } + else if (aSide == ForgeDirection.EAST) { + return EAST; + } + else { + return null; + } + } + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java b/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java new file mode 100644 index 0000000000..010e522a14 --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java @@ -0,0 +1,52 @@ +package gtPlusPlus.api.objects.minecraft; + +import net.minecraft.client.Minecraft; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class DimChunkPos { + + public final int dimension; + public final int xPos; + public final int zPos; + public final Chunk mainChunk; + + + public DimChunkPos(World world, BlockPos block){ + this.dimension = world.provider.dimensionId; + this.mainChunk = world.getChunkFromBlockCoords(block.xPos, block.zPos); + this.xPos = this.mainChunk.xPosition; + this.zPos = this.mainChunk.zPosition; + } + + + public DimChunkPos(TileEntity tile){ + this.dimension = tile.getWorldObj().provider.dimensionId; + this.mainChunk = tile.getWorldObj().getChunkFromBlockCoords(tile.xCoord, tile.zCoord); + this.xPos = this.mainChunk.xPosition; + this.zPos = this.mainChunk.zPosition; + } + + public DimChunkPos(int dim, int x, int z){ + this.dimension = dim; + this.xPos = x; + this.zPos = z; + Chunk h = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(dim).getChunkFromChunkCoords(xPos, zPos); + if (h == null) { + this.mainChunk = null; + } + else { + this.mainChunk = h; + } + } + + public Chunk getChunk() { + if (this.mainChunk != null) { + return this.mainChunk; + } + Chunk h = Minecraft.getMinecraft().getIntegratedServer().worldServerForDimension(this.dimension).getChunkFromChunkCoords(xPos, zPos); + return h; + } + +} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java b/src/main/java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java new file mode 100644 index 0000000000..d5db8081dc --- /dev/null +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java @@ -0,0 +1,253 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.HashSet; +import java.util.Set; + +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +public class FakeBlockPos extends BlockPos { + + private static final long serialVersionUID = -6442245826092414593L; + private transient Block aBlockAtPos; + private int aBlockMetaAtPos = 0; + + public static FakeBlockPos generateBlockPos(String sUUID) { + String[] s2 = sUUID.split("@"); + return new FakeBlockPos(s2); + } + + public FakeBlockPos(String[] s){ + this(Integer.parseInt(s[1]), Integer.parseInt(s[2]), Integer.parseInt(s[3]), Integer.parseInt(s[0])); + } + + public FakeBlockPos(int x, int y, int z, Block aBlock, int aMeta){ + this(x, y, z, 0); + aBlockAtPos = aBlock; + aBlockMetaAtPos = aMeta; + } + |
