aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/tileentities/machines
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-10-13 21:54:43 +0100
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-10-13 21:54:43 +0100
commit82f4a138efb59d8fdc4a492a190d3c8d7c53fbff (patch)
tree63acd44e8f60099df9ab3570eb3a083654251cd4 /src/Java/gtPlusPlus/core/tileentities/machines
parent9d467e9912c8dbe8567e2925c4a5c538c0be5630 (diff)
downloadGT5-Unofficial-82f4a138efb59d8fdc4a492a190d3c8d7c53fbff.tar.gz
GT5-Unofficial-82f4a138efb59d8fdc4a492a190d3c8d7c53fbff.tar.bz2
GT5-Unofficial-82f4a138efb59d8fdc4a492a190d3c8d7c53fbff.zip
+ Added Round-Robinator recipes.
% Adjusted Zirconium Carbide tier, and changed the materials used for LV tiered recipes. % Finished work on the Round-Robinator logic. $ Removed PSS log spam. $ Many minor bug fixes.
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities/machines')
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityRoundRobinator.java695
1 files changed, 569 insertions, 126 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityRoundRobinator.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityRoundRobinator.java
index 13ba5ca44d..4950718f4a 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityRoundRobinator.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityRoundRobinator.java
@@ -1,19 +1,36 @@
package gtPlusPlus.core.tileentities.machines;
+import java.util.List;
+
+import gtPlusPlus.GTplusplus;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.handler.GuiHandler;
+import gtPlusPlus.core.inventories.Inventory_RoundRobinator;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import gtPlusPlus.core.util.sys.KeyboardUtils;
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockChest;
+import net.minecraft.command.IEntitySelector;
+import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
+import net.minecraft.tileentity.IHopper;
import net.minecraft.tileentity.TileEntity;
-import gtPlusPlus.api.objects.data.AutoMap;
-import gtPlusPlus.core.inventories.Inventory_RoundRobinator;
-import gtPlusPlus.core.recipe.common.CI;
-import gtPlusPlus.core.util.minecraft.PlayerUtils;
+import net.minecraft.tileentity.TileEntityChest;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.Facing;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.World;
-public class TileEntityRoundRobinator extends TileEntity implements ISidedInventory {
+public class TileEntityRoundRobinator extends TileEntity implements ISidedInventory, IHopper {
private int tickCount = 0;
private final Inventory_RoundRobinator inventoryContents;
@@ -21,7 +38,9 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
public int locationX;
public int locationY;
public int locationZ;
- private int aCurrentMode = 0;
+ private int aData = 1111;
+ private int aTier = 1;
+ private int aTickRate = 100;
public TileEntityRoundRobinator() {
this.inventoryContents = new Inventory_RoundRobinator();
@@ -34,6 +53,7 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
this.locationX = this.xCoord;
this.locationY = this.yCoord;
this.locationZ = this.zCoord;
+ this.aTier = this.getWorldObj().getBlockMetadata(locationX, locationY, locationZ) + 1;
return true;
}
}
@@ -41,8 +61,8 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
}
//Rename to hasCircuitToConfigure
- public final boolean hasCircuitToConfigure() {
- for (ItemStack i : this.getInventory().getInventory()) {
+ public final boolean hasInventoryContents() {
+ for (ItemStack i : this.aHopperInventory) {
if (i == null) {
continue;
}
@@ -56,76 +76,54 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
public Inventory_RoundRobinator getInventory() {
return this.inventoryContents;
}
-
- public boolean addOutput() {
- ItemStack[] aInputs = this.getInventory().getInventory().clone();
- //Check if there is output in slot.
- Boolean hasOutput = false;
- if (aInputs[25] != null) {
- hasOutput = true;
- }
- AutoMap<Integer> aValidSlots = new AutoMap<Integer>();
- int aSlotCount = 0;
- for (ItemStack i : aInputs) {
- if (i != null) {
- aValidSlots.put(aSlotCount);
- }
- aSlotCount++;
- }
- for (int e : aValidSlots) {
- boolean doAdd = false;
- ItemStack g = this.getStackInSlot(e);
- int aSize = 0;
- ItemStack aInputStack = null;
- if (g != null) {
- if (!hasOutput) {
- aSize = g.stackSize;
- doAdd = true;
- }
- else {
- ItemStack f = this.getStackInSlot(25);
- if (f != null) {
- if (f.getItemDamage() == e) {
- aSize = f.stackSize + g.stackSize;
- if (aSize > 64) {
- aInputStack = g.copy();
- aInputStack.stackSize = (aSize-64);
- }
- doAdd = true;
- }
- }
- else {
- doAdd = true;
- aSize = g.stackSize;
- }
- }
- if (doAdd) {
- ItemStack aOutput = CI.getNumberedCircuit(e);
- if (aOutput != null) {
- aOutput.stackSize = aSize;
- this.setInventorySlotContents(e, aInputStack);
- this.setInventorySlotContents(25, aOutput);
- return true;
- }
- }
- }
- continue;
- }
- return false;
+
+ public int getTier() {
+ return this.aTier;
+ }
+
+ public int getTickRate() {
+ return this.aTickRate;
}
@Override
public void updateEntity() {
try{
- if (!this.worldObj.isRemote) {
- if (tickCount % 10 == 0) {
- if (hasCircuitToConfigure()) {
- this.addOutput();
- this.markDirty();
+ // TODO
+ if (this.worldObj != null && !this.worldObj.isRemote){
+ setTileLocation();
+ aTickRate = (60-(aTier*10));
+ if (this.getTier() == 1) {
+ // 20 s
+ aTickRate = 400;
+ }
+ else if (this.getTier() == 2) {
+ // 5
+ aTickRate = 100;
+ }
+ else if (this.getTier() == 3) {
+ // 1
+ aTickRate = 20;
+ }
+ else if (this.getTier() == 4) {
+ // 1/5
+ aTickRate = 10;
+ }
+ else if (this.getTier() == 5) {
+ // 1/20
+ aTickRate = 1;
+ }
+ else {
+ aTickRate = 999999;
+ }
+
+ if (tickCount % getTickRate() == 0) {
+ if (hasInventoryContents()) {
+ Logger.INFO("Trying to move items. "+aTickRate);
+ this.tryProcessItems();
}
}
- this.tickCount++;
- }
+ this.tickCount++;
+ }
}
catch (final Throwable t){}
}
@@ -144,55 +142,26 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
@Override
public void writeToNBT(final NBTTagCompound nbt) {
super.writeToNBT(nbt);
- // Utils.LOG_WARNING("Trying to write NBT data to TE.");
- final NBTTagCompound chestData = new NBTTagCompound();
- this.inventoryContents.writeToNBT(chestData);
- nbt.setTag("ContentsChest", chestData);
if (this.hasCustomInventoryName()) {
nbt.setString("CustomName", this.getCustomName());
}
- nbt.setInteger("aCurrentMode", aCurrentMode);
+ nbt.setInteger("aCurrentMode", aData);
+ this.writeToNBT2(nbt);
}
@Override
public void readFromNBT(final NBTTagCompound nbt) {
super.readFromNBT(nbt);
- // Utils.LOG_WARNING("Trying to read NBT data from TE.");
- this.inventoryContents.readFromNBT(nbt.getCompoundTag("ContentsChest"));
if (nbt.hasKey("CustomName", 8)) {
this.setCustomName(nbt.getString("CustomName"));
}
- aCurrentMode = nbt.getInteger("aCurrentMode");
- }
-
- @Override
- public int getSizeInventory() {
- return this.getInventory().getSizeInventory();
- }
-
- @Override
- public ItemStack getStackInSlot(final int slot) {
- return this.getInventory().getStackInSlot(slot);
- }
-
- @Override
- public ItemStack decrStackSize(final int slot, final int count) {
- return this.getInventory().decrStackSize(slot, count);
- }
-
- @Override
- public ItemStack getStackInSlotOnClosing(final int slot) {
- return this.getInventory().getStackInSlotOnClosing(slot);
- }
-
- @Override
- public void setInventorySlotContents(final int slot, final ItemStack stack) {
- this.getInventory().setInventorySlotContents(slot, stack);
+ aData = nbt.getInteger("aCurrentMode");
+ this.readFromNBT2(nbt);
}
@Override
public int getInventoryStackLimit() {
- return this.getInventory().getInventoryStackLimit();
+ return 64;
}
@Override
@@ -205,7 +174,7 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, 1);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType());
- this.getInventory().openInventory();
+ //this.getInventory().openInventory();
}
@Override
@@ -213,32 +182,27 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, 1);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord - 1, this.zCoord, this.getBlockType());
- this.getInventory().closeInventory();
+ //this.getInventory().closeInventory();
}
@Override
public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) {
- return this.getInventory().isItemValidForSlot(slot, itemstack);
+ return true;
}
@Override
- public int[] getAccessibleSlotsFromSide(final int p_94128_1_) {
- final int[] accessibleSides = new int[this.getSizeInventory()];
- for (int r=0; r<this.getInventory().getSizeInventory(); r++){
- accessibleSides[r]=r;
- }
- return accessibleSides;
-
+ public int[] getAccessibleSlotsFromSide(final int aSide) {
+ return new int[] {0, 1, 2, 3, 4};
}
@Override
- public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) {
- return p_102007_1_ >= 0 && p_102007_1_ <= 24;
+ public boolean canInsertItem(final int aSlot, final ItemStack aStack, final int aSide) {
+ return aSide < 2;
}
@Override
- public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) {
- return p_102008_1_ == 25;
+ public boolean canExtractItem(final int aSlot, final ItemStack aStack, final int aSide) {
+ return false;
}
public String getCustomName() {
@@ -251,7 +215,7 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
@Override
public String getInventoryName() {
- return this.hasCustomInventoryName() ? this.customName : "container.circuitprogrammer";
+ return this.hasCustomInventoryName() ? this.customName : "container.roundrobinator";
}
@Override
@@ -272,15 +236,37 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
this.readFromNBT(tag);
}
- public boolean onScrewdriverRightClick(byte side, EntityPlayer player, int x, int y, int z) {
- try {
- if (aCurrentMode == 24) {
- aCurrentMode = 0;
+
+ public boolean onRightClick(byte side, EntityPlayer player, int x, int y, int z) {
+ if (player != null && player.getHeldItem() == null) {
+ if (!player.isSneaking() && !KeyboardUtils.isShiftKeyDown()) {
+ player.openGui(GTplusplus.instance, GuiHandler.GUI16, player.getEntityWorld(), x, y, z);
}
else {
- aCurrentMode++;
+ String InventoryContents = ItemUtils.getArrayStackNames(this.aHopperInventory);
+ PlayerUtils.messagePlayer(player, "Contents: "+InventoryContents+" | "+getDataString());
+ }
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ public boolean onScrewdriverRightClick(byte side, EntityPlayer player, int x, int y, int z) {
+ try {
+ if (side < 2) {
+ // Top/Bottom
}
- PlayerUtils.messagePlayer(player, "Now configuring units for type "+aCurrentMode+".");
+ else {
+ if (toggleSide(side)) {
+ PlayerUtils.messagePlayer(player, "Enabling side "+side+".");
+ }
+ else {
+ PlayerUtils.messagePlayer(player, "Disabling side "+side+".");
+ }
+ PlayerUtils.messagePlayer(player, "Mode String: "+aData+"");
+ }
return true;
}
catch (Throwable t) {
@@ -288,4 +274,461 @@ public class TileEntityRoundRobinator extends TileEntity implements ISidedInvent
}
}
+ public int getDataString() {
+ return aData;
+ }
+
+ public boolean[] getActiveSides() {
+ this.markDirty();
+ String s = String.valueOf(aData);
+ if (s == null || s.length() != 4) {
+ s = "1111";
+ }
+ boolean[] aActiveSides = new boolean[4];
+ for (int i=0;i<4;i++) {
+ char ch = s.charAt(i);
+ if (ch == '1') {
+ aActiveSides[i] = true;
+ }
+ else {
+ aActiveSides[i] = false;
+ }
+ }
+ return aActiveSides;
+ }
+
+ /**
+ * Toggle active state of side
+ * @param aSide - Forge Direction / Side
+ * @return - True if the side is now Active, false if now disabled.
+ */
+ public boolean toggleSide(int aSide) {
+ setSideActive(!getSideActive(aSide), aSide);
+ return getSideActive(aSide);
+ }
+
+
+ public void setSideActive(boolean aActive, int aSide) {
+ try {
+ if (aSide < 2) {
+ }
+ else {
+ if (aData < 1111) {
+ aData = 1111;
+ }
+ else if (aData > 2222) {
+ aData = 2222;
+ }
+ String s = String.valueOf(aData);
+ StringBuilder aDataString = new StringBuilder(s);
+ int aIndex = aSide - 2;
+ if (aActive) {
+ aDataString.setCharAt(aIndex, '1');
+ }
+ else {
+ aDataString.setCharAt(aIndex, '2');
+ }
+ aData = Integer.valueOf(aDataString.toString());
+ this.markDirty();
+ }
+ }
+ catch (Throwable t) {
+ }
+ }
+
+ public boolean getSideActive(int aSide) {
+ this.markDirty();
+ try {
+ if (aSide < 2) {
+ return false;
+ }
+ else {
+ if (aData < 1111) {
+ aData = 1111;
+ }
+ else if (aData > 2222) {
+ aData = 2222;
+ }
+ String s = String.valueOf(aData);
+ int aIndex = aSide - 2;
+ char ch = s.charAt(aIndex);
+ if (ch == '1') {
+ return true;
+ }
+ else {
+ return false;
+ }
+
+ }
+ }
+ catch (Throwable t) {
+ return false;
+ }
+ }
+
+ @Override
+ public double getXPos() {
+ return this.locationX;
+ }
+
+ @Override
+ public double getYPos() {
+ return this.locationY;
+ }
+
+ @Override
+ public double getZPos() {
+ return this.locationZ;
+ }
+
+
+
+
+
+
+
+
+ // TODO
+
+
+
+ /*
+ * Hopper Code
+ */
+
+
+ private ItemStack[] aHopperInventory = new ItemStack[5];
+
+ public int getSizeInventory() {
+ return this.aHopperInventory.length;
+ }
+
+ public ItemStack getStackInSlot(int aSlot) {
+ return this.aHopperInventory[aSlot];
+ }
+
+ /**
+ * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
+ * new stack.
+ */
+ public ItemStack decrStackSize(int aSlot, int aMinimumSizeOfExistingStack)
+ {
+ if (this.aHopperInventory[aSlot] != null)
+ {
+ ItemStack itemstack;
+
+ if (this.aHopperInventory[aSlot].stackSize <= aMinimumSizeOfExistingStack)
+ {
+ itemstack = this.aHopperInventory[aSlot];
+ this.aHopperInventory[aSlot] = null;
+ return itemstack;
+ }
+ else
+ {
+ itemstack = this.aHopperInventory[aSlot].splitStack(aMinimumSizeOfExistingStack);
+
+ if (this.aHopperInventory[aSlot].stackSize == 0)
+ {
+ this.aHopperInventory[aSlot] = null;
+ }
+
+ return itemstack;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
+ * like when you close a workbench GUI.
+ */
+ public ItemStack getStackInSlotOnClosing(int aSlot)
+ {
+ if (this.aHopperInventory[aSlot] != null)
+ {
+ ItemStack itemstack = this.aHopperInventory[aSlot];
+ this.aHopperInventory[aSlot] = null;
+ return itemstack;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
+ */
+ public void setInventorySlotContents(int aSlot, ItemStack aStack)
+ {
+ this.aHopperInventory[aSlot] = aStack;
+
+ if (aStack != null && aStack.stackSize > this.getInventoryStackLimit())
+ {
+ aStack.stackSize = this.getInventoryStackLimit();
+ }
+ }
+
+ public boolean tryProcessItems() {
+ if (this.worldObj != null && !this.worldObj.isRemote) {
+ boolean didSomething = false;
+ if (!this.isEmpty()) {
+ Logger.INFO("Has Items, Trying to push to all active directions.");
+ didSomething = this.tryPushItemsIntoNeighbours();
+ }
+ if (didSomething) {
+ this.markDirty();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Is Empty
+ * @return
+ */
+ private boolean isEmpty() {
+ ItemStack[] aitemstack = this.aHopperInventory;
+ int i = aitemstack.length;
+
+ for (int j = 0; j < i; ++j) {
+ ItemStack itemstack = aitemstack[j];
+
+ if (itemstack != null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private boolean tryPushItemsIntoNeighbours() {
+
+ boolean aDidPush = false;
+
+ for (int u = 2; u < 6; u++) {
+ if (!this.getSideActive(u)) {
+ Logger.INFO("Not pushing on side "+u);
+ continue;
+ }
+
+ Logger.INFO("Pushing on side "+u);
+ IInventory iinventory = this.getInventoryFromFacing(u);
+
+ if (iinventory == null) {
+ Logger.INFO("No inventory found.");
+ continue;
+ }
+ else {
+
+ int i = Facing.oppositeSide[u];
+ Logger.INFO("Using Opposite direction: "+i);
+
+ if (this.isInventoryFull(iinventory, i)) {
+ Logger.INFO("Target is full, skipping.");
+ continue;
+ }
+ else {
+ Logger.INFO("Target has space, let's move a single item.");
+ for (int j = 0; j < this.getSizeInventory(); ++j) {
+ if (this.getStackInSlot(j) != null) {
+ ItemStack itemstack = this.getStackInSlot(j).copy();
+ ItemStack itemstack1 = setStackInNeighbour(iinventory, this.decrStackSize(j, 1), i);
+ if (itemstack1 == null || itemstack1.stackSize == 0) {
+ iinventory.markDirty();
+ aDidPush = true;
+ continue;
+ }
+ this.setInventorySlotContents(j, itemstack);
+ }
+ }
+ }
+ }
+ }
+
+ return aDidPush;
+ }
+
+ private boolean isInventoryFull(IInventory aInv, int aSide) {
+ if (aInv instanceof ISidedInventory && aSide > -1) {
+ ISidedInventory isidedinventory = (ISidedInventory)aInv;
+ int[] aint = isidedinventory.getAccessibleSlotsFromSide(aSide);
+
+ for (int l = 0; l < aint.length; ++l)
+ {
+ ItemStack itemstack1 = isidedinventory.getStackInSlot(aint[l]);
+
+ if (itemstack1 == null || itemstack1.stackSize != itemstack1.getMaxStackSize())
+ {
+ return false;
+ }
+ }
+ }
+ else {
+ int j = aInv.getSizeInventory();
+
+ for (int k = 0; k < j; ++k)
+ {
+ ItemStack itemstack = aInv.getStackInSlot(k);
+
+ if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static ItemStack setStackInNeighbour(IInventory aNeighbour, ItemStack aStack, int aSide) {
+ if (aNeighbour instanceof ISidedInventory && aSide > -1)
+ {
+ ISidedInventory isidedinventory = (ISidedInventory)aNeighbour;
+ int[] aint = isidedinventory.getAccessibleSlotsFromSide(aSide);
+
+ for (int l = 0; l < aint.length && aStack != null && aStack.stackSize > 0; ++l)
+ {
+ aStack = tryMoveStack(aNeighbour, aStack, aint[l], aSide);
+ }
+ }
+ else
+ {
+ int j = aNeighbour.getSizeInventory();
+
+ for (int k = 0; k < j && aStack != null && aStack.stackSize > 0; ++k)
+ {
+ aStack = tryMoveStack(aNeighbour, aStack, k, aSide);
+ }
+ }
+
+ if (aStack != null && aStack.stackSize == 0)
+ {
+ aStack = null;
+ }
+
+ return aStack;
+ }
+
+ private static boolean canInsertItemIntoNeighbour(IInventory aNeighbour, ItemStack aStack, int aSlot, int aSide) {
+ return !aNeighbour.isItemValidForSlot(aSlot, aStack) ? false : !(aNeighbour instanceof ISidedInventory) || ((ISidedInventory)aNeighbour).canInsertItem(aSlot, aStack, aSide);
+ }
+
+ private static ItemStack tryMoveStack(IInventory aNeighbour, ItemStack aStack, int aSlot, int aSide) {
+ ItemStack itemstack1 = aNeighbour.getStackInSlot(aSlot);
+ if (canInsertItemIntoNeighbour(aNeighbour, aStack, aSlot, aSide)) {
+ boolean aDidSomething = false;
+ if (itemstack1 == null) {
+ //Forge: BUGFIX: Again, make things respect max stack sizes.
+ int max = Math.min(aStack.getMaxStackSize(), aNeighbour.getInventoryStackLimit());
+ if (max >= aStack.stackSize) {
+ aNeighbour.setInventorySlotContents(aSlot, aStack);
+ aStack = null;
+ }
+ else {
+ aNeighbour.setInventorySlotContents(aSlot, aStack.splitStack(max));
+ }
+ aDidSomething = true;
+ }
+ else if (areItemStacksEqual(itemstack1, aStack)) {
+ //Forge: BUGFIX: Again, make things respect max stack sizes.
+ int max = Math.min(aStack.getMaxStackSize(), aNeighbour.getInventoryStackLimit());
+ if (max > itemstack1.stackSize) {
+ int l = Math.min(aStack.stackSize, max - itemstack1.stackSize);
+ aStack.stackSize -= l;
+ itemstack1.stackSize += l;
+ aDidSomething = l > 0;
+ }
+ }
+ if (aDidSomething){
+ aNeighbour.markDirty();
+ }
+ }
+ return aStack;
+ }
+
+ private IInventory getInventoryFromFacing(int aSide)
+ {
+ int i = aSide;
+ return tryFindInvetoryAtXYZ(this.getWorldObj(), (double)(this.xCoord + Facing.offsetsXForSide[i]), (double)(this.yCoord + Facing.offsetsYForSide[i]), (double)(this.zCoord + Facing.offsetsZForSide[i]));
+ }
+
+ public static IInventory tryFindInvetoryAtXYZ(World aWorld, double aX, double aY, double aZ)
+ {
+ IInventory iinventory = null;
+ int sX = MathHelper.floor_double(aX);
+ int sY = MathHelper.floor_double(aY);
+ int sZ = MathHelper.floor_double(aZ);
+ TileEntity tileentity = aWorld.getTileEntity(sX, sY, sZ);
+
+ if (tileentity != null && tileentity instanceof IInventory)
+ {
+ iinventory = (IInventory)tileentity;
+
+ if (iinventory instanceof TileEntityChest)
+ {
+ Block block = aWorld.getBlock(sX, sY, sZ);
+
+ if (block instanceof BlockChest)
+ {
+ iinventory = ((BlockChest)block).func_149951_m(aWorld, sX, sY, sZ);
+ }
+ }
+ }
+
+ if (iinventory == null)
+ {
+ List list = aWorld.getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getBoundingBox(aX, aY, aZ, aX + 1.0D, aY + 1.0D, aZ + 1.0D), IEntitySelector.selectInventories);
+
+ if (list != null && list.size() > 0)
+ {
+ iinventory = (IInventory)list.get(aWorld.rand.nextInt(list.size()));
+ }
+ }
+
+ return iinventory;
+ }
+
+ private static boolean areItemStacksEqual(ItemStack aStack, ItemStack aStack2) {
+ return aStack.getItem() != aStack2.getItem() ? false : (aStack.getItemDamage() != aStack2.getItemDamage() ? false : (aStack.stackSize > aStack.getMaxStackSize() ? false : ItemStack.areItemStackTagsEqual(aStack, aStack2)));
+ }
+
+ public void readFromNBT2(NBTTagCompound p_145839_1_) {
+ super.readFromNBT(p_145839_1_);
+ NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
+ this.aHopperInventory = new ItemStack[this.getSizeInventory()];
+ for (int i = 0; i < nbttaglist.tagCount(); ++i) {
+ NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
+ byte b0 = nbttagcompound1.getByte("Slot");
+ if (b0 >= 0 && b0 < this.aHopperInventory.length) {
+ this.aHopperInventory[b0] = ItemStack.loadItemStackFromNBT(
+ nbttagcompound1
+ );
+ }
+ }
+ }
+
+ public void writeToNBT2(NBTTagCompound aNBT) {
+ super.writeToNBT(aNBT);
+ NBTTagList nbttaglist = new NBTTagList();
+ for (int i = 0; i < this.aHopperInventory.length; ++i) {
+ if (this.aHopperInventory[i] != null) {
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+ nbttagcompound1.setByte("Slot", (byte) i);
+ this.aHopperInventory[i].writeToNBT(nbttagcompound1);
+ nbttaglist.appendTag(nbttagcompound1);
+ }
+ }
+ aNBT.setTag("Items", nbttaglist);
+ }
+
+
+
+
+
+
+
}