From 7d1f51a8937e0a86486267437d444696e81e8aa0 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:04:28 +0200 Subject: Buildscript + Spotless (#318) * Convert AES.java to readable class * Buildscript * Spotless --- .../gtPlusPlus/api/objects/minecraft/AABB.java | 97 ++--- .../api/objects/minecraft/BTF_FluidTank.java | 353 ++++++++------- .../api/objects/minecraft/BTF_Inventory.java | 446 +++++++++---------- .../gtPlusPlus/api/objects/minecraft/BlockPos.java | 473 ++++++++++----------- .../api/objects/minecraft/CubicObject.java | 101 ++--- .../api/objects/minecraft/DimChunkPos.java | 78 ++-- .../api/objects/minecraft/FakeBlockPos.java | 434 ++++++++++--------- .../api/objects/minecraft/FakeWorld.java | 292 ++++++------- .../gtPlusPlus/api/objects/minecraft/FluidGT6.java | 42 +- .../objects/minecraft/FormattedTooltipString.java | 38 +- .../api/objects/minecraft/GenericStack.java | 67 ++- .../api/objects/minecraft/ItemPackage.java | 97 +++-- .../api/objects/minecraft/ItemStackData.java | 50 ++- .../objects/minecraft/NoConflictGTRecipeMap.java | 225 +++++----- .../api/objects/minecraft/SafeTexture.java | 92 ++-- .../api/objects/minecraft/ShapedRecipe.java | 472 ++++++++++---------- .../api/objects/minecraft/TexturePackage.java | 89 ++-- .../api/objects/minecraft/ThreadPooCollector.java | 174 ++++---- .../minecraft/multi/NoEUBonusMultiBehaviour.java | 31 +- .../multi/NoOutputBonusMultiBehaviour.java | 31 +- .../multi/NoSpeedBonusMultiBehaviour.java | 31 +- .../minecraft/multi/SpecialMultiBehaviour.java | 57 ++- 22 files changed, 1861 insertions(+), 1909 deletions(-) (limited to 'src/main/java/gtPlusPlus/api/objects/minecraft') diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java b/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java index 722ac00b64..cefc4fce37 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/AABB.java @@ -11,55 +11,52 @@ import net.minecraft.world.World; * */ 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; - } - + 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 index 0b8f97b378..f7d29e1200 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_FluidTank.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_FluidTank.java @@ -1,6 +1,5 @@ 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; @@ -8,181 +7,179 @@ 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); - } - - - + 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 index 04ce0dff19..d23ea97072 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java @@ -1,228 +1,244 @@ 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 java.util.ArrayList; 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 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 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 tList = new ArrayList(); - 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= 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 tList = new ArrayList(); + 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 index ab359c3853..451d1aca77 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -1,250 +1,245 @@ package gtPlusPlus.api.objects.minecraft; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.api.objects.data.AutoMap; 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 getSurroundingBlocks(){ - AutoMap sides = new AutoMap(); - 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 getSimilarNeighbour() { - return getSimilarNeighbour(false); - } - - /** - * @param strict - Does this check Meta Data? - * @return - Does this block have a neighbour that is the same? - */ - public AutoMap getSimilarNeighbour(boolean strict) { - AutoMap sides = new AutoMap(); - 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 getValidNeighboursAndSelf(){ - AutoMap h = getSimilarNeighbour(true); - h.put(this); - Set result = new HashSet(); - for (BlockPos f : h.values()) { - result.add(f); - } - return result; - } - +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 getSurroundingBlocks() { + AutoMap sides = new AutoMap(); + 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 getSimilarNeighbour() { + return getSimilarNeighbour(false); + } + + /** + * @param strict - Does this check Meta Data? + * @return - Does this block have a neighbour that is the same? + */ + public AutoMap getSimilarNeighbour(boolean strict) { + AutoMap sides = new AutoMap(); + 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 getValidNeighboursAndSelf() { + AutoMap h = getSimilarNeighbour(true); + h.put(this); + Set result = new HashSet(); + 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 index 8c76513d09..04b1f2b59b 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java @@ -5,58 +5,51 @@ import net.minecraftforge.common.util.ForgeDirection; public class CubicObject { - 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 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; - } - } - + 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 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 index 010e522a14..492d0b3aeb 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java @@ -7,46 +7,48 @@ 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 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(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(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; - } + 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 index d5db8081dc..40f78763d0 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/FakeBlockPos.java @@ -1,9 +1,8 @@ package gtPlusPlus.api.objects.minecraft; +import gtPlusPlus.api.objects.data.AutoMap; 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; @@ -11,219 +10,217 @@ 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; - } - - private FakeBlockPos(int x, int y, int z, int dim){ - this(x, y, z, DimensionManager.getWorld(dim)); - } - - private FakeBlockPos(int x, int y, int z, World dim){ - super(x, y, z, null); - } - - public String getLocationString() { - String S = ""+this.xPos+"@"+this.yPos+"@"+this.zPos; - return S; - } - - public String getUniqueIdentifier() { - String S = ""+this.xPos+"@"+this.yPos+"@"+this.zPos+this.aBlockAtPos.getLocalizedName()+"@"+this.aBlockMetaAtPos; - 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 FakeBlockPos)) { - return false; - } - FakeBlockPos otherPoint = (FakeBlockPos) other; - return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos; - } - - public int distanceFrom(FakeBlockPos 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(FakeBlockPos 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 FakeBlockPos getUp() { - return new FakeBlockPos(this.xPos, this.yPos+1, this.zPos, this.dim); - } - - public FakeBlockPos getDown() { - return new FakeBlockPos(this.xPos, this.yPos-1, this.zPos, this.dim); - } - - public FakeBlockPos getXPos() { - return new FakeBlockPos(this.xPos+1, this.yPos, this.zPos, this.dim); - } - - public FakeBlockPos getXNeg() { - return new FakeBlockPos(this.xPos-1, this.yPos, this.zPos, this.dim); - } - - public FakeBlockPos getZPos() { - return new FakeBlockPos(this.xPos, this.yPos, this.zPos+1, this.dim); - } - - public FakeBlockPos getZNeg() { - return new FakeBlockPos(this.xPos, this.yPos, this.zPos-1, this.dim); - } - - public AutoMap getSurroundingBlocks(){ - AutoMap sides = new AutoMap(); - 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(FakeBlockPos pos) { - return getBlockAtPos(world, pos); - } - - public Block getBlockAtPos(World world, FakeBlockPos pos) { - return aBlockAtPos; - } - - public int getMetaAtPos() { - return getMetaAtPos(this); - } - - public int getMetaAtPos(FakeBlockPos pos) { - return getMetaAtPos(world, pos); - } - - public int getMetaAtPos(World world, FakeBlockPos pos) { - return aBlockMetaAtPos; - } - - 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 getSimilarNeighbour() { - return getSimilarNeighbour(false); - } - - /** - * @param strict - Does this check Meta Data? - * @return - Does this block have a neighbour that is the same? - */ - public AutoMap getSimilarNeighbour(boolean strict) { - AutoMap sides = new AutoMap(); - 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 getValidNeighboursAndSelf(){ - AutoMap h = getSimilarNeighbour(true); - h.put(this); - Set result = new HashSet(); - for (BlockPos f : h.values()) { - result.add(f); - } - return result; - } - + 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; + } + + private FakeBlockPos(int x, int y, int z, int dim) { + this(x, y, z, DimensionManager.getWorld(dim)); + } + + private FakeBlockPos(int x, int y, int z, World dim) { + super(x, y, z, null); + } + + public String getLocationString() { + String S = "" + this.xPos + "@" + this.yPos + "@" + this.zPos; + return S; + } + + public String getUniqueIdentifier() { + String S = "" + this.xPos + "@" + this.yPos + "@" + this.zPos + this.aBlockAtPos.getLocalizedName() + "@" + + this.aBlockMetaAtPos; + 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 FakeBlockPos)) { + return false; + } + FakeBlockPos otherPoint = (FakeBlockPos) other; + return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos; + } + + public int distanceFrom(FakeBlockPos 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(FakeBlockPos 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 FakeBlockPos getUp() { + return new FakeBlockPos(this.xPos, this.yPos + 1, this.zPos, this.dim); + } + + public FakeBlockPos getDown() { + return new FakeBlockPos(this.xPos, this.yPos - 1, this.zPos, this.dim); + } + + public FakeBlockPos getXPos() { + return new FakeBlockPos(this.xPos + 1, this.yPos, this.zPos, this.dim); + } + + public FakeBlockPos getXNeg() { + return new FakeBlockPos(this.xPos - 1, this.yPos, this.zPos, this.dim); + } + + public FakeBlockPos getZPos() { + return new FakeBlockPos(this.xPos, this.yPos, this.zPos + 1, this.dim); + } + + public FakeBlockPos getZNeg() { + return new FakeBlockPos(this.xPos, this.yPos, this.zPos - 1, this.dim); + } + + public AutoMap getSurroundingBlocks() { + AutoMap sides = new AutoMap(); + 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(FakeBlockPos pos) { + return getBlockAtPos(world, pos); + } + + public Block getBlockAtPos(World world, FakeBlockPos pos) { + return aBlockAtPos; + } + + public int getMetaAtPos() { + return getMetaAtPos(this); + } + + public int getMetaAtPos(FakeBlockPos pos) { + return getMetaAtPos(world, pos); + } + + public int getMetaAtPos(World world, FakeBlockPos pos) { + return aBlockMetaAtPos; + } + + 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 getSimilarNeighbour() { + return getSimilarNeighbour(false); + } + + /** + * @param strict - Does this check Meta Data? + * @return - Does this block have a neighbour that is the same? + */ + public AutoMap getSimilarNeighbour(boolean strict) { + AutoMap sides = new AutoMap(); + 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 getValidNeighboursAndSelf() { + AutoMap h = getSimilarNeighbour(true); + h.put(this); + Set result = new HashSet(); + for (BlockPos f : h.values()) { + result.add(f); + } + return result; + } + /** * Called when a plant grows on this block, only implemented for saplings using the WorldGen*Trees classes right now. * Modder may implement this for custom plants. @@ -241,13 +238,10 @@ public class FakeBlockPos extends BlockPos { * @param sourceY Plant growth location Y * @param sourceZ Plant growth location Z */ - public void onPlantGrow(FakeWorld world, int x, int y, int z, int sourceX, int sourceY, int sourceZ) - { - if (getBlockAtPos() == Blocks.grass || getBlockAtPos() == Blocks.farmland) - { + public void onPlantGrow(FakeWorld world, int x, int y, int z, int sourceX, int sourceY, int sourceZ) { + if (getBlockAtPos() == Blocks.grass || getBlockAtPos() == Blocks.farmland) { this.aBlockAtPos = Blocks.dirt; this.aBlockMetaAtPos = 0; } } - } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/FakeWorld.java b/src/main/java/gtPlusPlus/api/objects/minecraft/FakeWorld.java index 8ee033a341..2a55282623 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/FakeWorld.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/FakeWorld.java @@ -1,12 +1,10 @@ package gtPlusPlus.api.objects.minecraft; -import java.util.HashMap; - -import gregtech.api.enums.Materials; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; +import java.util.HashMap; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; @@ -18,156 +16,140 @@ import net.minecraftforge.common.util.ForgeDirection; public class FakeWorld implements IBlockAccess { - public static HashMap mStaticFakeWorldData; - - public HashMap mFakeWorldData = new HashMap(); - - /** - * Must be an odd number - */ - private int aWorldSize = 99; - private final int aDistanceFromOrigin; - private final int aWorldHeight; - - public FakeWorld() { - t