Search in sources :

Example 6 with Fabric

use of org.spongepowered.common.inventory.fabric.Fabric 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 7 with Fabric

use of org.spongepowered.common.inventory.fabric.Fabric 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 8 with Fabric

use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.

the class ItemStackQuery method matches.

@Override
public boolean matches(Lens lens, Lens parent, Inventory inventory) {
    if (lens instanceof SlotLens) {
        Fabric fabric = ((InventoryBridge) inventory).bridge$getAdapter().inventoryAdapter$getFabric();
        ItemStack stack = ItemStackUtil.fromNative(((SlotLens) lens).getStack(fabric));
        if (stack == null) {
            return false;
        }
        return this.matches(stack, this.arg);
    }
    return false;
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) Fabric(org.spongepowered.common.inventory.fabric.Fabric) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 9 with Fabric

use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.

the class KeyValueMatcherQuery method execute.

@Override
public Inventory execute(final Inventory inventory, final InventoryAdapter adapter) {
    final Fabric fabric = adapter.inventoryAdapter$getFabric();
    final Lens lens = adapter.inventoryAdapter$getRootLens();
    if (this.matches(lens, null, inventory)) {
        return lens.getAdapter(fabric, inventory);
    }
    return this.toResult(inventory, fabric, this.reduce(fabric, lens, this.search(inventory, lens)));
}
Also used : DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Example 10 with Fabric

use of org.spongepowered.common.inventory.fabric.Fabric in project SpongeCommon by SpongePowered.

the class SpongeDepthQuery method execute.

public Inventory execute(Inventory inventory, InventoryAdapter adapter) {
    final Fabric fabric = adapter.inventoryAdapter$getFabric();
    final Lens lens = adapter.inventoryAdapter$getRootLens();
    if (this.matches(lens, null, inventory)) {
        return lens.getAdapter(fabric, inventory);
    }
    return this.toResult(inventory, fabric, this.reduce(fabric, lens, this.depthFirstSearch(inventory, lens)));
}
Also used : DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Aggregations

Fabric (org.spongepowered.common.inventory.fabric.Fabric)11 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)8 Lens (org.spongepowered.common.inventory.lens.Lens)8 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 InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)3 DelegatingLens (org.spongepowered.common.inventory.lens.impl.DelegatingLens)3 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)3 EquipmentInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Key (org.spongepowered.api.data.Key)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)1 Query (org.spongepowered.api.item.inventory.query.Query)1