use of org.spongepowered.common.item.inventory.lens.impl.DelegatingLens in project SpongeCommon by SpongePowered.
the class ContainerUtil method generateAdapterLens.
@Nullable
private static Lens<IInventory, ItemStack> generateAdapterLens(SlotProvider<IInventory, ItemStack> slots, int index, CraftingInventoryData crafting, List<Slot> slotList, @Nullable IInventory subInventory) {
if (!(subInventory instanceof InventoryAdapter)) {
return null;
}
Lens<IInventory, ItemStack> adapterLens = ((InventoryAdapter) subInventory).getRootLens();
if (adapterLens == null) {
return null;
}
if (subInventory.getSizeInventory() == 0) {
return new DefaultEmptyLens<>(((InventoryAdapter) subInventory));
}
if (adapterLens instanceof PlayerInventoryLens) {
if (slotList.size() == 36) {
return new DelegatingLens(index, new MainPlayerInventoryLensImpl(index, slots, true), slots);
}
return null;
}
// For Crafting Result we need the Slot to get Filter logic
if (subInventory instanceof InventoryCraftResult) {
Slot slot = slotList.get(0);
adapterLens = new CraftingOutputSlotLensImpl(index, item -> slot.isItemValid(((ItemStack) item)), itemType -> (slot.isItemValid((ItemStack) org.spongepowered.api.item.inventory.ItemStack.of(itemType, 1))));
crafting.out = index;
if (slot instanceof SlotCrafting) {
if (crafting.base == null) {
// In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
// e.g. for IC2 ContainerIndustrialWorkbench
crafting.base = index + 1;
crafting.grid = ((SlotCrafting) slot).craftMatrix;
}
}
}
if (subInventory instanceof InventoryCrafting) {
crafting.base = index;
crafting.grid = ((InventoryCrafting) subInventory);
}
return new DelegatingLens(index, adapterLens, slots);
}
Aggregations