use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class InvTools method findMatchingItems.
/**
* Returns all items from the inventory that match the
* filter, but does not remove them.
* The resulting set will be populated with a single instance of each item type.
*
* @param inv the inventory The inventory
* @param filter EnumItemType to match against
* @return A Set of ItemStacks
*/
@Nonnull
public static Set<StackKey> findMatchingItems(IInventoryComposite inv, Predicate<ItemStack> filter) {
Set<StackKey> items = CollectionTools.createItemStackSet();
for (IInventoryObject inventoryObject : inv) {
for (IInvSlot slot : InventoryIterator.getRailcraft(inventoryObject)) {
ItemStack stack = slot.getStack();
if (!isEmpty(stack) && filter.test(stack)) {
stack = stack.copy();
stack.stackSize = 1;
items.add(StackKey.make(stack));
}
}
}
return items;
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class CartDisassemblyRecipe method matches.
@Override
public boolean matches(InventoryCrafting grid, World worldIn) {
int itemCount = 0;
boolean foundCart = false;
for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
if (slot.hasStack()) {
if (slot.containsItem(fullCart))
foundCart = true;
itemCount++;
}
}
return itemCount == 1 && foundCart;
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class TileRockCrusher method update.
@Override
public void update() {
super.update();
if (Game.isHost(getWorld())) {
BlockPos pos = getPos();
double x = pos.getX();
double y = pos.getZ();
double z = pos.getZ();
if (isStructureValid()) {
// TileEntityHopper.getItemsAroundAPointOrSomethingLikeThat
for (EntityItem item : TileEntityHopper.getCaptureItems(getWorld(), x, y + 1, z)) {
if (item != null && useMasterEnergy(SUCKING_POWER_COST, false)) {
ItemStack stack = item.getEntityItem().copy();
InventoryManipulator.get((IInventory) invInput).addStack(stack);
useMasterEnergy(SUCKING_POWER_COST, true);
item.setDead();
}
}
EntityLivingBase entity = MiscTools.getEntityAt(worldObj, EntityLivingBase.class, getPos().up());
if (entity != null && useMasterEnergy(KILLING_POWER_COST, false))
if (entity.attackEntityFrom(RailcraftDamageSource.CRUSHER, 10))
useMasterEnergy(KILLING_POWER_COST, true);
}
if (isMaster()) {
if (clock % 16 == 0)
processActions();
if (paused)
return;
ItemStack input = InvTools.emptyStack();
ICrusherCraftingManager.ICrusherRecipe recipe = null;
for (IInvSlot slot : InventoryIterator.getVanilla((IInventory) invInput)) {
input = slot.getStack();
if (!InvTools.isEmpty(input)) {
recipe = RailcraftCraftingManager.rockCrusher.getRecipe(input);
if (recipe == null)
recipe = RockCrusherCraftingManager.NULL_RECIPE;
break;
}
}
if (recipe != null)
if (processTime >= PROCESS_TIME) {
isWorking = false;
InventoryCopy tempInv = new InventoryCopy(invOutput);
boolean hasRoom = true;
List<ItemStack> outputs = recipe.getProcessedOutputs();
for (ItemStack output : outputs) {
output = InvTools.moveItemStack(output, tempInv);
if (!InvTools.isEmpty(output)) {
hasRoom = false;
break;
}
}
if (hasRoom) {
for (ItemStack output : outputs) {
InvTools.moveItemStack(output, invOutput);
}
InvTools.removeOneItem(invInput, input);
SoundHelper.playSound(worldObj, null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, worldObj.rand.nextFloat() * 0.25F + 0.7F);
processTime = 0;
}
} else {
isWorking = true;
if (energyStorage != null) {
int energy = energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, true);
if (energy >= CRUSHING_POWER_COST_PER_TICK) {
processTime++;
energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, false);
}
} else
processTime++;
}
else {
processTime = 0;
isWorking = false;
}
}
}
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class CartFilterRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
ItemStack cartItem = InvTools.emptyStack();
ItemStack filterItem = InvTools.emptyStack();
FilterType filterType = null;
int cartSlot = -1;
int itemCount = 0;
int filterCartCount = 0;
for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
ItemStack stack = slot.getStack();
if (!InvTools.isEmpty(stack)) {
itemCount++;
FilterType type = FilterType.fromCartType(RailcraftCarts.getCartType(stack));
if (type != null) {
cartSlot = slot.getIndex();
filterType = type;
cartItem = stack.copy();
filterCartCount++;
}
}
}
if (filterType == null || itemCount > 2 || filterCartCount > 1)
return InvTools.emptyStack();
for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
if (slot.getIndex() == cartSlot)
continue;
ItemStack stack = slot.getStack();
if (!InvTools.isEmpty(stack) && filterType.isAllowedFilterItem(stack)) {
filterItem = stack.copy();
break;
}
}
if (InvTools.isEmpty(cartItem) || InvTools.isEmpty(filterItem))
return InvTools.emptyStack();
filterItem.stackSize = 1;
return CartBaseFiltered.addFilterToCartItem(cartItem, filterItem);
}
use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.
the class InventoryManipulator method moveItem.
@Nullable
public ItemStack moveItem(IInventoryObject dest, Predicate<ItemStack> filter) {
InventoryManipulator imDest = InventoryManipulator.get(dest);
for (IInvSlot slot : this) {
ItemStack stack = slot.getStack();
if (!isEmpty(stack) && slot.canTakeStackFromSlot(stack) && filter.test(stack)) {
stack = stack.copy();
stack.stackSize = 1;
stack = imDest.addStack(stack);
if (isEmpty(stack))
return slot.decreaseStack();
}
}
return emptyStack();
}
Aggregations