use of org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl 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);
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl in project SpongeCommon by SpongePowered.
the class MixinContainerWorkbench method rootLens.
@Override
public Lens<IInventory, ItemStack> rootLens(Fabric<IInventory> fabric, InventoryAdapter<IInventory, ItemStack> adapter) {
List<Lens<IInventory, ItemStack>> lenses = new ArrayList<>();
lenses.add(new CraftingInventoryLensImpl(0, 1, 3, 3, inventory$getSlotProvider()));
lenses.add(new MainPlayerInventoryLensImpl(3 * 3 + 1, inventory$getSlotProvider(), true));
return new ContainerLens(adapter, inventory$getSlotProvider(), lenses);
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl in project SpongeCommon by SpongePowered.
the class PlayerInventoryLens method init.
@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
// Adding slots
for (int ord = 0, slot = this.base; ord < this.size; ord++, slot++) {
this.addChild(slots.getSlot(slot), new SlotIndex(ord));
}
int base = 0;
this.main = new MainPlayerInventoryLensImpl(base, slots, false);
base += this.main.slotCount();
this.equipment = new EquipmentInventoryLensImpl(this.player, base, EQUIPMENT, 1, slots, false);
base += EQUIPMENT;
this.offhand = slots.getSlot(base);
// TODO Hotbar in Vanilla is part of the main inventory (first 9 slots) ; maybe wrap it in a Lens?
this.addSpanningChild(this.main);
this.addSpanningChild(this.equipment);
this.addSpanningChild(this.offhand);
// Additional Slots for bigger modded inventories
int additionalSlots = this.size - base - 1;
if (additionalSlots > 0) {
this.addSpanningChild(new OrderedInventoryLensImpl(base, additionalSlots, 1, slots));
}
}
use of org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl in project SpongeCommon by SpongePowered.
the class ContainerPlayerInventoryLens method init.
@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
// 1
int base = CRAFTING_OUTPUT;
final CraftingInventoryLensImpl crafting = new CraftingInventoryLensImpl(0, base, CRAFTING_GRID, CRAFTING_GRID, slots);
// 4
base += CRAFTING_GRID * CRAFTING_GRID;
// TODO pass player for carrier to EquipmentInventory
final EquipmentInventoryLensImpl armor = new EquipmentInventoryLensImpl(null, base, EQUIPMENT, 1, slots, true);
// 4
base += EQUIPMENT;
final MainPlayerInventoryLensImpl main = new MainPlayerInventoryLensImpl(base, slots, true);
// 9
base += MAIN_INVENTORY_HEIGHT * INVENTORY_WIDTH + HOTBAR * INVENTORY_WIDTH;
final SlotLens<IInventory, ItemStack> offHand = slots.getSlot(base);
base += OFFHAND;
this.viewedInventories = new ArrayList<>(Arrays.asList(crafting, armor, offHand, main));
int additionalSlots = this.size - base - 1;
if (additionalSlots > 0) {
viewedInventories.add(new OrderedInventoryLensImpl(base, additionalSlots, 1, slots));
}
// TODO actual Container order is:
// CraftingOutput (1) -> Crafting (4) -> ArmorSlots (4) -> MainInventory (27) -> Hotbar (9) -> Offhand (1)
// how to handle issues like in #939? ; e.g. Inventory#offer using a different insertion order
super.init(slots);
}
Aggregations