use of mods.railcraft.common.util.inventory.wrappers.InventoryComposite in project Railcraft by Railcraft.
the class FilterSimpleRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
if (!matches(grid, null))
return InvTools.emptyStack();
InventoryComposite inv = InventoryComposite.of(grid);
ItemStack filter = InvTools.findMatchingItem(inv, FILTER);
if (InvTools.isEmpty(filter))
return InvTools.emptyStack();
ItemStack prototype = InvTools.findMatchingItem(inv, validPrototype(filter));
if (!InvTools.isEmpty(prototype))
return ItemFilterSimple.setPrototype(filter, prototype);
return InvTools.emptyStack();
}
use of mods.railcraft.common.util.inventory.wrappers.InventoryComposite in project Railcraft by Railcraft.
the class FilterSimpleRecipe method matches.
@Override
public boolean matches(InventoryCrafting grid, World world) {
InventoryComposite inv = InventoryComposite.of(grid);
int filterStacks = InvTools.countStacks(inv, FILTER);
if (filterStacks != 1)
return false;
ItemStack filter = InvTools.findMatchingItem(inv, FILTER);
if (InvTools.isEmpty(filter))
return false;
int prototype = InvTools.countStacks(inv, validPrototype(filter));
return prototype == 1;
}
use of mods.railcraft.common.util.inventory.wrappers.InventoryComposite in project Railcraft by Railcraft.
the class TileItemManipulator method processCart.
@Override
protected void processCart(EntityMinecart cart) {
chests.clear();
chests.add(invBuffer);
chests.addAll(invCache.getAdjacentInventories());
InventoryComposite cartInv = InventoryComposite.of(InventoryFactory.get(cart, getFacing().getOpposite()));
if (cartInv.isEmpty()) {
sendCart(cart);
return;
}
this.cart = cartInv;
switch(getMode()) {
case TRANSFER:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
filterManifest.entrySet().stream().filter(entry -> transferredItems.count(entry.getElement()) < entry.getCount()).anyMatch(entry -> {
ItemStack moved = InvTools.moveOneItem(getSource(), getDestination(), StackFilters.matches(entry.getElement().get()));
if (!InvTools.isEmpty(moved)) {
setProcessing(true);
transferredItems.add(entry.getElement());
return true;
}
return false;
});
break;
}
case STOCK:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
Multiset<StackKey> destManifest = InvTools.createManifest(getDestination(), filterManifest.elementSet());
moveItem(filterManifest.entrySet().stream().filter(entry -> destManifest.count(entry.getElement()) < entry.getCount()));
break;
}
case EXCESS:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
Multiset<StackKey> sourceManifest = InvTools.createManifest(getSource(), filterManifest.elementSet());
moveItem(filterManifest.entrySet().stream().filter(entry -> sourceManifest.count(entry.getElement()) > entry.getCount()));
if (!isProcessing()) {
Predicate<ItemStack> keep = filterManifest.elementSet().stream().map(e -> StackFilters.matches(e.get())).reduce(StackFilters.none(), Predicate::or);
ItemStack moved = InvTools.moveOneItemExcept(getSource(), getDestination(), keep);
itemMoved(moved);
}
break;
}
case ALL:
{
Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
if (filterManifest.isEmpty()) {
ItemStack moved = InvTools.moveOneItem(getSource(), getDestination());
itemMoved(moved);
} else {
moveItem(filterManifest.entrySet().stream());
}
break;
}
}
}
Aggregations