use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class FirestoneTickHandler method tick.
@SubscribeEvent
public void tick(LivingEvent.LivingUpdateEvent event) {
EntityLivingBase entity = event.getEntityLiving();
if (Game.isClient(entity.worldObj))
return;
clock++;
if (clock % 4 != 0)
return;
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer != ((EntityPlayer) entity).inventoryContainer)
return;
IInventoryObject inv = InventoryFactory.get(entity);
if (inv != null) {
for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
ItemStack stack = slot.getStack();
FirestoneTools.trySpawnFire(entity.worldObj, entity.getPosition(), stack);
}
}
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class InvTools method acceptsItemStack.
/**
* Checks if inventory will accept the ItemStack.
*
* @param stack The ItemStack
* @param dest The IInventory
* @return true if room for stack
*/
@Contract("null,_ -> false;")
public static boolean acceptsItemStack(@Nullable ItemStack stack, IInventoryComposite dest) {
if (isEmpty(stack))
return false;
ItemStack newStack = stack.copy();
newStack.stackSize = 1;
for (IInventoryObject inv : dest) {
for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
if (slot.canPutStackInSlot(stack))
return true;
}
}
return false;
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class ItemHandlerInventoryManipulator method removeItem.
@Nonnull
@Override
protected List<ItemStack> removeItem(Predicate<ItemStack> filter, int maxAmount, boolean doRemove) {
int amountNeeded = maxAmount;
List<ItemStack> outputList = new ArrayList<ItemStack>();
for (IInvSlot slot : this) {
if (amountNeeded <= 0)
break;
ItemStack stack = slot.getStack();
if (!isEmpty(stack) && slot.canTakeStackFromSlot(stack) && filter.test(stack)) {
ItemStack removed = inv.extractItem(slot.getIndex(), amountNeeded, !doRemove);
if (!isEmpty(removed)) {
amountNeeded -= removed.stackSize;
outputList.add(removed);
}
}
}
return outputList;
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class ItemHandlerInventoryManipulator method addStack.
@Override
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
if (isEmpty(stack))
return emptyStack();
stack = stack.copy();
List<IInvSlot> filledSlots = new ArrayList<IInvSlot>(inv.getSlots());
List<IInvSlot> emptySlots = new ArrayList<IInvSlot>(inv.getSlots());
for (IInvSlot slot : InventoryIterator.getForge(inv)) {
if (slot.canPutStackInSlot(stack)) {
if (isEmpty(slot.getStack()))
emptySlots.add(slot);
else
filledSlots.add(slot);
}
}
int injected = 0;
injected = tryPut(filledSlots, stack, injected, doAdd);
injected = tryPut(emptySlots, stack, injected, doAdd);
stack.stackSize -= injected;
if (stack.stackSize <= 0)
return emptyStack();
return stack;
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class ItemHandlerInventoryManipulator method tryPut.
private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
if (injected >= stack.stackSize)
return injected;
for (IInvSlot slot : slots) {
ItemStack stackToInsert = stack.copy();
int amountToInsert = stack.stackSize - injected;
stackToInsert.stackSize = amountToInsert;
ItemStack remainder = inv.insertItem(slot.getIndex(), stackToInsert, !doAdd);
if (remainder == null)
return stack.stackSize;
injected += amountToInsert - remainder.stackSize;
if (injected >= stack.stackSize)
return injected;
}
return injected;
}
Aggregations