Search in sources :

Example 6 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens 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)

Aggregations

EquipmentInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)6 InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)4 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)4 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)3 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)3 LinkedHashMap (java.util.LinkedHashMap)2 Fabric (org.spongepowered.common.inventory.fabric.Fabric)2 Map (java.util.Map)1 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)1 Lens (org.spongepowered.common.inventory.lens.Lens)1 ArmorInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.ArmorInventoryLens)1 PrimaryPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens)1 HeldHandSlotLens (org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens)1