Search in sources :

Example 1 with Fabric

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

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

the class InventoryMixin_Inventory_API method equipment.

@Override
public EquipmentInventory equipment() {
    if (this.api$equipment == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$equipment = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getEquipmentLens().getAdapter(fabric, this);
    }
    return this.api$equipment;
}
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 3 with Fabric

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

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

the class InventoryMixin_Inventory_API method offhand.

@Override
public Slot offhand() {
    if (this.api$offhand == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$offhand = (SlotAdapter) ((PlayerInventoryLens) lens).getOffhandLens().getAdapter(fabric, this);
    }
    return this.api$offhand;
}
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 5 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)

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