Fix SidedInvWrapper accessing wrong slots for setStackInSlot. (#2797)

Fix DoubleChestItemHandler not implementing IItemHandlerModifiable
This commit is contained in:
boni 2016-05-02 21:19:54 +02:00 committed by LexManos
parent 9c9107c434
commit 8fdd76bae1
2 changed files with 21 additions and 2 deletions

View file

@ -12,7 +12,7 @@ import java.lang.ref.WeakReference;
import com.google.common.base.Objects;
public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest> implements IItemHandler
public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest> implements IItemHandlerModifiable
{
// Dummy cache value to signify that we have checked and definitely found no adjacent chests
public static final VanillaDoubleChestItemHandler NO_ADJACENT_CHESTS_INSTANCE = new VanillaDoubleChestItemHandler(null, null, false);
@ -91,6 +91,22 @@ public class VanillaDoubleChestItemHandler extends WeakReference<TileEntityChest
return chest != null ? chest.getStackInSlot(targetSlot) : null;
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
{
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityChest chest = getChest(accessingUpperChest);
if (chest != null)
{
IItemHandler singleHandler = chest.getSingleChestHandler();
if (singleHandler instanceof IItemHandlerModifiable)
{
((IItemHandlerModifiable) singleHandler).setStackInSlot(targetSlot, stack);
}
}
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{

View file

@ -144,7 +144,10 @@ public class SidedInvWrapper implements IItemHandlerModifiable
@Override
public void setStackInSlot(int slot, ItemStack stack)
{
inv.setInventorySlotContents(slot, stack);
int slot1 = getSlot(inv, slot, side);
if (slot1 != -1)
inv.setInventorySlotContents(slot1, stack);
}
@Override