Search in sources :

Example 11 with InventoryAdapter

use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.

the class AppendQuery method execute.

@Override
public Inventory execute(Inventory inventory, InventoryAdapter adapter) {
    Inventory result = new EmptyInventoryImpl(inventory);
    if (this.queryList.isEmpty()) {
        return result;
    }
    List<Inventory> results = this.queryList.stream().map(q -> q.execute(inventory)).collect(Collectors.toList());
    return new MultiInventoryAdapter(results);
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) SpongeQuery(org.spongepowered.common.inventory.query.SpongeQuery) Query(org.spongepowered.api.item.inventory.query.Query) Arrays(java.util.Arrays) List(java.util.List) MultiInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.MultiInventoryAdapter) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) EmptyInventoryImpl(org.spongepowered.common.inventory.EmptyInventoryImpl) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) ArrayList(java.util.ArrayList) EmptyInventoryImpl(org.spongepowered.common.inventory.EmptyInventoryImpl) MultiInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.MultiInventoryAdapter) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 12 with InventoryAdapter

use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.

the class SpongeInventoryBuilder method inventory.

public BuildingStep inventory(Inventory inventory) {
    InventoryAdapter adapter = (InventoryAdapter) inventory;
    this.size += inventory.capacity();
    this.lenses.add(adapter.inventoryAdapter$getRootLens());
    this.inventories.add(inventory);
    return this;
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter)

Example 13 with InventoryAdapter

use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.

the class SpongeInventoryBuilder method slots.

public BuildingStep slots(int amount) {
    this.size += amount;
    net.minecraft.world.SimpleContainer adapter = new net.minecraft.world.SimpleContainer(amount);
    this.inventories.add((Inventory) adapter);
    this.lenses.add(new DefaultIndexedLens(0, amount, ((InventoryAdapter) adapter).inventoryAdapter$getSlotLensProvider()));
    return this;
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) DefaultIndexedLens(org.spongepowered.common.inventory.lens.impl.DefaultIndexedLens)

Example 14 with InventoryAdapter

use of org.spongepowered.common.inventory.adapter.InventoryAdapter 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 15 with InventoryAdapter

use of org.spongepowered.common.inventory.adapter.InventoryAdapter 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

InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)17 Fabric (org.spongepowered.common.inventory.fabric.Fabric)7 Lens (org.spongepowered.common.inventory.lens.Lens)7 InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)5 PlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens)5 EquipmentInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter)4 PrimaryPlayerInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter)4 EquipmentInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)4 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)3 ArrayList (java.util.ArrayList)2 Slot (org.spongepowered.api.item.inventory.Slot)2 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Slot (net.minecraft.world.inventory.Slot)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1