Add functionality in IItemHandler to test if a slot can accept an item (#5033)

This commit is contained in:
Cody Brittain authored and LexManos committed 2018-07-28 17:38:18 -07:00
1 parent eb870bc84c
commit 4acfca27f8
10 files changed
+105 -28

No files matched your search

@@ -132,4 +132,13 @@ public class CombinedInvWrapper implements IItemHandlerModifiable
int localSlot = getSlotFromIndex(slot, index);
return handler.getSlotLimit(localSlot);
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
int index = getIndexForSlot(slot);
IItemHandlerModifiable handler = getHandlerFromIndex(index);
int localSlot = getSlotFromIndex(slot, index);
return handler.isItemValid(localSlot, stack);
}
}
@@ -67,4 +67,10 @@ public class EmptyHandler implements IItemHandlerModifiable
{
return 0;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return false;
}
}
@@ -179,6 +179,12 @@ public abstract class EntityEquipmentInvWrapper implements IItemHandlerModifiabl
entity.setItemStackToSlot(equipmentSlot, stack);
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return IItemHandlerModifiable.super.isItemValid(slot, stack);
}
protected EntityEquipmentSlot validateSlotIndex(final int slot)
{
if (slot < 0 || slot >= slots.size())
@@ -204,6 +204,12 @@ public class InvWrapper implements IItemHandlerModifiable
return getInv().getInventoryStackLimit();
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return getInv().isItemValidForSlot(slot, stack);
}
public IInventory getInv()
{
return inv;
@@ -105,6 +105,17 @@ public class RangedWrapper implements IItemHandlerModifiable {
return 0;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
if (checkSlot(slot))
{
return compose.isItemValid(slot + minSlot, stack);
}
return false;
}
private boolean checkSlot(int localSlot)
{
return localSlot + minSlot < maxSlot;
@@ -230,4 +230,10 @@ public class SidedInvWrapper implements IItemHandlerModifiable
{
return inv.getInventoryStackLimit();
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return inv.isItemValidForSlot(slot, stack);
}
}