Search in sources :

Example 21 with Lens

use of org.spongepowered.common.inventory.lens.Lens in project SpongeCommon by SpongePowered.

the class AbstractLens method getSlotLens.

@Override
@Nullable
public SlotLens getSlotLens(Fabric fabric, int ordinal) {
    if (ordinal < 0 || ordinal > this.maxOrdinal) {
        return null;
    }
    int offset = 0;
    for (final Lens child : this.spanningChildren) {
        int count = child.slotCount();
        if (ordinal < offset + count) {
            return child.getSlotLens(fabric, ordinal - offset);
        }
        offset += count;
    }
    return null;
}
Also used : QueriedSlotLens(org.spongepowered.common.inventory.lens.impl.slot.QueriedSlotLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) DelegatingSlotLens(org.spongepowered.common.inventory.lens.impl.slot.DelegatingSlotLens) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 22 with Lens

use of org.spongepowered.common.inventory.lens.Lens in project SpongeCommon by SpongePowered.

the class AbstractContainerMenuMixin_Adapter_Inventory method inventoryAdapter$getSlot.

@Override
public Optional<org.spongepowered.api.item.inventory.Slot> inventoryAdapter$getSlot(int ordinal) {
    org.spongepowered.api.item.inventory.Slot slot = this.impl$slots.get(ordinal);
    if (slot == null) {
        Lens rootLens = this.inventoryAdapter$getRootLens();
        SlotLens slotLens = rootLens.getSlotLens(this.inventoryAdapter$getFabric(), ordinal);
        if (slotLens == null) {
            return Optional.empty();
        }
        slot = slotLens.getAdapter(this.inventoryAdapter$getFabric(), ((Inventory) this));
        this.impl$slots.put(ordinal, slot);
    }
    return Optional.of(slot);
}
Also used : SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Aggregations

Lens (org.spongepowered.common.inventory.lens.Lens)22 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)10 DelegatingLens (org.spongepowered.common.inventory.lens.impl.DelegatingLens)9 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)8 Fabric (org.spongepowered.common.inventory.fabric.Fabric)8 PlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens)7 LinkedHashMap (java.util.LinkedHashMap)5 CraftingInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens)5 PrimaryPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens)5 SingleGridLens (org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens)5 ContainerLens (org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens)5 EquipmentInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter)4 PrimaryPlayerInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter)4 BasicSlotLens (org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)3 CompoundLens (org.spongepowered.common.inventory.lens.impl.CompoundLens)3 HashMap (java.util.HashMap)2 List (java.util.List)2