use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject 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.wrappers.IInventoryObject in project Railcraft by Railcraft.
the class InvTools method findMatchingItem.
/**
* Returns a single item from the inventory that matches the
* filter, but does not remove it.
*
* @param inv the inventory The inventory
* @param filter the filter to match against
* @return An ItemStack
*/
@Nullable
public static ItemStack findMatchingItem(IInventoryComposite inv, Predicate<ItemStack> filter) {
for (IInventoryObject inventoryObject : inv) {
InventoryManipulator im = InventoryManipulator.get(inventoryObject);
ItemStack removed = im.tryRemoveItem(filter);
if (!isEmpty(removed))
return removed;
}
return emptyStack();
}
use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.
the class InvTools method moveItemStack.
/**
* Places an ItemStack in a destination Inventory. Will attempt to move as
* much of the stack as possible, returning any remainder.
*
* @param stack The ItemStack to put in the inventory.
* @param dest The destination IInventories.
* @return Null if itemStack was completely moved, a new itemStack with
* remaining stackSize if part or none of the stack was moved.
*/
@SuppressWarnings("unused")
@Nullable
public static ItemStack moveItemStack(ItemStack stack, IInventoryComposite dest) {
for (IInventoryObject inv : dest) {
InventoryManipulator im = InventoryManipulator.get(inv);
stack = im.addStack(stack);
if (isEmpty(stack))
return emptyStack();
}
return stack;
}
use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject 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.wrappers.IInventoryObject in project Railcraft by Railcraft.
the class InvTools method moveOneItem.
/**
* Attempts to move a single item from one inventory to another.
*
* @param source the source inventory
* @param dest the destination inventory
* @param filter Predicate to match against
* @return null if nothing was moved, the stack moved otherwise
*/
@Nullable
public static ItemStack moveOneItem(IInventoryComposite source, IInventoryComposite dest, Predicate<ItemStack> filter) {
for (IInventoryObject src : source) {
for (IInventoryObject dst : dest) {
InventoryManipulator imSource = InventoryManipulator.get(src);
ItemStack moved = imSource.moveItem(dst, filter);
if (!isEmpty(moved))
return moved;
}
}
return emptyStack();
}
Aggregations