Search in sources :

Example 1 with SlotLens

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

the class CompoundSlotLensProvider method add.

/**
 * Adds all slots from this inventory adapter.
 *
 * @param adapter The adapter
 *
 * @return this provider for chaining
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public CompoundSlotLensProvider add(InventoryAdapter adapter) {
    for (Inventory slot : ((Inventory) adapter).slots()) {
        SlotLens slotLens = ((SlotLens) ((SlotAdapter) slot).inventoryAdapter$getRootLens());
        this.slotList.add(slotLens);
    }
    return this;
}
Also used : SlotAdapter(org.spongepowered.common.inventory.adapter.impl.slots.SlotAdapter) Inventory(org.spongepowered.api.item.inventory.Inventory) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 2 with SlotLens

use of org.spongepowered.common.inventory.lens.slots.SlotLens 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 3 with SlotLens

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

the class EquipmentInventoryLens method init.

private void init(Map<EquipmentType, SlotLens> lenses) {
    for (EquipmentSlot slot : EquipmentSlot.values()) {
        final EquipmentType type = (EquipmentType) (Object) slot;
        final SlotLens lensAtSlot = lenses.get(slot);
        if (lensAtSlot != null) {
            final EquipmentSlotLens equipmentSlotLens = new EquipmentSlotLens(this, lensAtSlot, type);
            this.addSpanningChild(equipmentSlotLens, KeyValuePair.of(Keys.EQUIPMENT_TYPE, type));
            this.lenses.put(type, equipmentSlotLens);
        }
    }
}
Also used : EquipmentSlotLens(org.spongepowered.common.inventory.lens.impl.slot.EquipmentSlotLens) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) EquipmentSlotLens(org.spongepowered.common.inventory.lens.impl.slot.EquipmentSlotLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 4 with SlotLens

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

the class ServerPlayerMixin_Inventory method impl$getSpongeSlot.

// -- small bridge-like methods
@SuppressWarnings("ConstantConditions")
@Override
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
    final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
    final PlayerInventoryBridge inventory = (PlayerInventoryBridge) ((net.minecraft.server.level.ServerPlayer) (Object) this).inventory;
    final Lens lens = ((InventoryAdapter) inventory).inventoryAdapter$getRootLens();
    final Fabric fabric = ((InventoryAdapter) inventory).inventoryAdapter$getFabric();
    if (lens instanceof PlayerInventoryLens) {
        final SlotLens slotLens = ((PlayerInventoryLens) lens).getEquipmentLens().getSlotLens(equipmentType);
        return slotLens.getAdapter(fabric, (Inventory) inventory);
    }
    throw new IllegalStateException("Unknown Lens for Player Inventory: " + lens.getClass().getName());
}
Also used : PlayerInventoryBridge(org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Fabric(org.spongepowered.common.inventory.fabric.Fabric) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 5 with SlotLens

use of org.spongepowered.common.inventory.lens.slots.SlotLens 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)

Aggregations

SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)13 Lens (org.spongepowered.common.inventory.lens.Lens)6 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)5 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)4 LinkedHashMap (java.util.LinkedHashMap)3 Fabric (org.spongepowered.common.inventory.fabric.Fabric)3 EquipmentInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)3 Map (java.util.Map)2 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)2 SlotAdapter (org.spongepowered.common.inventory.adapter.impl.slots.SlotAdapter)2 DelegatingSlotLens (org.spongepowered.common.inventory.lens.impl.slot.DelegatingSlotLens)2 QueriedSlotLens (org.spongepowered.common.inventory.lens.impl.slot.QueriedSlotLens)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Key (org.spongepowered.api.data.Key)1