Search in sources :

Example 1 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens in project SpongeCommon by SpongePowered.

the class PlayerInventoryLens method init.

protected void init(SlotLensProvider slots) {
    // Adding slots
    for (int ord = 0, slot = this.base; ord < this.size; ord++, slot++) {
        this.addChild(slots.getSlotLens(slot), KeyValuePair.slotIndex(ord));
    }
    int base = this.base;
    Map<EquipmentType, SlotLens> equipmentLenses = new LinkedHashMap<>();
    if (this.isContainer) {
        this.armor = new ArmorInventoryLens(base, slots, true);
        equipmentLenses.put(EquipmentTypes.HEAD.get(), slots.getSlotLens(base + 0));
        equipmentLenses.put(EquipmentTypes.CHEST.get(), slots.getSlotLens(base + 1));
        equipmentLenses.put(EquipmentTypes.LEGS.get(), slots.getSlotLens(base + 2));
        equipmentLenses.put(EquipmentTypes.FEET.get(), slots.getSlotLens(base + 3));
        // 4
        base += PlayerInventoryLens.ARMOR;
        this.primary = new PrimaryPlayerInventoryLens(base, slots, true);
        base += this.primary.slotCount();
        this.offhand = slots.getSlotLens(base);
        base += PlayerInventoryLens.OFFHAND;
        equipmentLenses.put(EquipmentTypes.OFF_HAND.get(), this.offhand);
        this.addSpanningChild(this.armor);
        this.addSpanningChild(this.primary);
        this.addSpanningChild(this.offhand);
    } else {
        this.primary = new PrimaryPlayerInventoryLens(base, slots, false);
        base += this.primary.slotCount();
        this.armor = new ArmorInventoryLens(base, slots, false);
        equipmentLenses.put(EquipmentTypes.FEET.get(), slots.getSlotLens(base + 0));
        equipmentLenses.put(EquipmentTypes.LEGS.get(), slots.getSlotLens(base + 1));
        equipmentLenses.put(EquipmentTypes.CHEST.get(), slots.getSlotLens(base + 2));
        equipmentLenses.put(EquipmentTypes.HEAD.get(), slots.getSlotLens(base + 3));
        base += PlayerInventoryLens.ARMOR;
        this.offhand = slots.getSlotLens(base);
        base += PlayerInventoryLens.OFFHAND;
        equipmentLenses.put(EquipmentTypes.OFF_HAND.get(), this.offhand);
        this.addSpanningChild(this.primary);
        this.addSpanningChild(this.armor);
        this.addSpanningChild(this.offhand);
    }
    equipmentLenses.put(EquipmentTypes.MAIN_HAND.get(), new HeldHandSlotLens(this.primary.getHotbar()));
    this.equipment = new EquipmentInventoryLens(equipmentLenses);
    for (Map.Entry<EquipmentType, SlotLens> entry : equipmentLenses.entrySet()) {
        this.addChild(entry.getValue(), KeyValuePair.of(Keys.EQUIPMENT_TYPE, entry.getKey()));
    }
    this.addChild(this.equipment);
    this.addMissingSpanningSlots(base, slots);
}
Also used : HeldHandSlotLens(org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) ArmorInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.ArmorInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) HeldHandSlotLens(org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens in project SpongeCommon by SpongePowered.

the class TraitMixin_ArmorEquipable_Inventory_API method equip.

@Override
public boolean equip(final EquipmentType type, @Nullable final ItemStack equipment) {
    final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
    final EquipmentInventoryLens lens = this.impl$equipmentInventory(inv);
    final Fabric fabric = inv.inventoryAdapter$getFabric();
    return lens.getSlotLens(type).setStack(fabric, ItemStackUtil.toNative(equipment));
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) Fabric(org.spongepowered.common.inventory.fabric.Fabric) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)

Example 3 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens in project SpongeCommon by SpongePowered.

the class TraitMixin_Equipable_Inventory_API method equipment.

@Override
public EquipmentInventory equipment() {
    if (this.impl$equipmentInventory == null) {
        final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
        final EquipmentInventoryLens lens = (EquipmentInventoryLens) inv.inventoryAdapter$getRootLens();
        this.impl$equipmentInventory = (EquipmentInventory) lens.getAdapter(inv.inventoryAdapter$getFabric(), null);
    }
    return this.impl$equipmentInventory;
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)

Example 4 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens in project SpongeCommon by SpongePowered.

the class LivingEntityMixin_EquipmentFabric_Inventory method lensGeneratorBridge$generateLens.

@Override
public Lens lensGeneratorBridge$generateLens(SlotLensProvider slotLensProvider) {
    Map<EquipmentType, SlotLens> equipmentLenses = new LinkedHashMap<>();
    for (int i = 0, slotsLength = EquipmentSlot.values().length; i < slotsLength; i++) {
        EquipmentSlot slot = EquipmentSlot.values()[i];
        equipmentLenses.put((EquipmentType) (Object) slot, slotLensProvider.getSlotLens(i));
    }
    return new EquipmentInventoryLens(equipmentLenses);
}
Also used : EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) 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) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with EquipmentInventoryLens

use of org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens in project SpongeCommon by SpongePowered.

the class TraitMixin_ArmorEquipable_Inventory_API method equipped.

@Override
public Optional<ItemStack> equipped(final EquipmentType type) {
    final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
    final EquipmentInventoryLens lens = this.impl$equipmentInventory(inv);
    final Fabric fabric = inv.inventoryAdapter$getFabric();
    return Optional.of(ItemStackUtil.fromNative(lens.getSlotLens(type).getStack(fabric)));
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) Fabric(org.spongepowered.common.inventory.fabric.Fabric) EquipmentInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)

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