Fixed NBT bugs and converted Hopper to Transactors
And I really need to fix my dev env so I can test these commits.
This commit is contained in:
parent
4175fe9399
commit
ca93a6661b
2 changed files with 9 additions and 26 deletions
|
@ -54,7 +54,7 @@ public class InventoryUtil {
|
||||||
_inventory.setInventorySlotContents(i, stackToMove);
|
_inventory.setInventorySlotContents(i, stackToMove);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (stackToMove.itemID == stack.itemID && (stackToMove.getItem().isDamageable() || stackToMove.getItemDamage() == stack.getItemDamage())) {
|
if (stackToMove.itemID == stack.itemID && (stackToMove.getItem().isDamageable() || stackToMove.getItemDamage() == stack.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, stackToMove)) {
|
||||||
if (stackToMove.stackSize + stack.stackSize <= stack.getMaxStackSize()) {
|
if (stackToMove.stackSize + stack.stackSize <= stack.getMaxStackSize()) {
|
||||||
stack.stackSize += stackToMove.stackSize;
|
stack.stackSize += stackToMove.stackSize;
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -6,12 +6,10 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.common.ISidedInventory;
|
import buildcraft.core.inventory.ITransactor;
|
||||||
import buildcraft.api.inventory.ISpecialInventory;
|
import buildcraft.core.inventory.Transactor;
|
||||||
import buildcraft.core.TileBuildCraft;
|
import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import buildcraft.core.utils.InventoryUtil;
|
|
||||||
import buildcraft.core.utils.SidedInventoryAdapter;
|
|
||||||
import buildcraft.core.utils.SimpleInventory;
|
import buildcraft.core.utils.SimpleInventory;
|
||||||
|
|
||||||
public class TileHopper extends TileBuildCraft implements IInventory {
|
public class TileHopper extends TileBuildCraft implements IInventory {
|
||||||
|
@ -43,32 +41,17 @@ public class TileHopper extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
if (tile == null) return;
|
if (tile == null) return;
|
||||||
|
|
||||||
ISpecialInventory special = null;
|
ITransactor transactor = Transactor.getTransactorFor(tile);
|
||||||
InventoryUtil externalInventory = null;
|
|
||||||
if (tile instanceof ISpecialInventory) {
|
if (transactor == null) return;
|
||||||
special = (ISpecialInventory) tile;
|
|
||||||
} else if (tile instanceof ISidedInventory) {
|
|
||||||
externalInventory = new InventoryUtil(new SidedInventoryAdapter((ISidedInventory) tile, ForgeDirection.UP));
|
|
||||||
} else if (tile instanceof IInventory) {
|
|
||||||
externalInventory = new InventoryUtil((IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int internalSlot = 0; internalSlot < _inventory.getSizeInventory(); internalSlot++) {
|
for(int internalSlot = 0; internalSlot < _inventory.getSizeInventory(); internalSlot++) {
|
||||||
ItemStack stackInSlot = _inventory.getStackInSlot(internalSlot);
|
ItemStack stackInSlot = _inventory.getStackInSlot(internalSlot);
|
||||||
if(stackInSlot == null) continue;
|
if(stackInSlot == null) continue;
|
||||||
|
|
||||||
if (special != null) {
|
ItemStack clonedStack = stackInSlot.copy().splitStack(1);
|
||||||
ItemStack clonedStack = stackInSlot.copy().splitStack(1);
|
if (transactor.addItem(clonedStack, ForgeDirection.UP, true).stackSize <= 0) {
|
||||||
if (special.addItem(clonedStack, true, ForgeDirection.UP) > 0) {
|
_inventory.decrStackSize(internalSlot, 1);
|
||||||
_inventory.decrStackSize(internalSlot, 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (externalInventory != null && externalInventory.hasRoomForItem(stackInSlot)) {
|
|
||||||
ItemStack stackToMove = _inventory.decrStackSize(internalSlot, 1);
|
|
||||||
externalInventory.addToInventory(stackToMove);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue