Search in sources :

Example 11 with Lens

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

the class LivingEntityMixin_Inventory method impl$getSpongeSlot.

@SuppressWarnings("ConstantConditions")
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
    final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
    if (this instanceof InventoryBridge) {
        final InventoryAdapter adapter = ((InventoryBridge) this).bridge$getAdapter();
        final Lens lens = adapter.inventoryAdapter$getRootLens();
        if (lens instanceof EquipmentInventoryLens) {
            final SlotLens slotLens = ((EquipmentInventoryLens) lens).getSlotLens(equipmentType);
            return slotLens.getAdapter(adapter.inventoryAdapter$getFabric(), (Inventory) adapter);
        }
        throw new IllegalStateException("Expected EquipmentInventoryLens for " + this.getClass().getName() + " Inventory but found: " + lens.getClass().getName());
    }
    throw new IllegalStateException("Living Entity has no InventoryAdapter: " + this.getClass().getName());
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 12 with Lens

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

the class InventoryMixin_Inventory_API method armor.

@Override
public EquipmentInventory armor() {
    if (this.api$armor == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$armor = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getArmorLens().getAdapter(fabric, this);
    }
    return this.api$armor;
}
Also used : EquipmentInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter) PrimaryPlayerInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Example 13 with Lens

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

the class InventoryMixin_Inventory_API method primary.

@Override
public PrimaryPlayerInventory primary() {
    if (this.api$primary == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$primary = (PrimaryPlayerInventoryAdapter) ((PlayerInventoryLens) lens).getPrimaryInventoryLens().getAdapter(fabric, this);
    }
    return this.api$primary;
}
Also used : EquipmentInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter) PrimaryPlayerInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Example 14 with Lens

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

the class LensRegistrar method lensRepairContainer.

@SuppressWarnings("unchecked")
private static Lens lensRepairContainer(Object inventory, int size, SlotLensProvider slotLensProvider) {
    final List<Lens> lenses = new ArrayList<>();
    lenses.add(new DefaultIndexedLens(0, 3, slotLensProvider));
    lenses.add(new PrimaryPlayerInventoryLens(3, slotLensProvider, true));
    return new ContainerLens(size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider, lenses);
}
Also used : PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) ArrayList(java.util.ArrayList) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) CraftingGridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingGridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) BrewingStandInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.BrewingStandInventoryLens) FurnaceInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.FurnaceInventoryLens) ContainerPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens) LargeChestInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.LargeChestInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens)

Example 15 with Lens

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

the class LensRegistrar method generateLens.

@SuppressWarnings("unchecked")
private static Lens generateLens(Object inventory, int size, SlotLensProvider slotLensProvider) {
    if (size == 0) {
        return new DefaultEmptyLens();
    }
    LensFactory lensFactory = LensRegistrar.lensFactories.get(inventory.getClass());
    Lens lens = null;
    if (lensFactory != null) {
        lens = lensFactory.apply(inventory.getClass(), size, slotLensProvider);
        if (lens != null) {
            return lens;
        }
    }
    if (inventory instanceof CraftingContainer) {
        lens = LensRegistrar.lensCraftingInventory(size, ((CraftingContainer) inventory).getWidth(), ((CraftingContainer) inventory).getHeight(), slotLensProvider);
    } else if (inventory instanceof AbstractContainerMenu) {
        lens = ContainerUtil.generateLens(((AbstractContainerMenu) inventory), slotLensProvider);
    } else if (size == 1) {
        return slotLensProvider.getSlotLens(0);
    }
    if (lens != null) {
        return lens;
    }
    return new SingleIndexedLens(0, size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) CraftingGridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingGridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) BrewingStandInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.BrewingStandInventoryLens) FurnaceInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.FurnaceInventoryLens) ContainerPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens) LargeChestInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.LargeChestInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens)

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