Search in sources :

Example 6 with InventoryAdapter

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

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

the class SlotMixin_Lens_Inventory method lensGeneratorBridge$generateLens.

@Override
public Lens lensGeneratorBridge$generateLens(SlotLensProvider slotLensProvider) {
    try {
        final Lens rootLens = ((InventoryAdapter) this.container).inventoryAdapter$getRootLens();
        SlotLens lens = rootLens.getSlotLens(this.inventoryAdapter$getFabric(), this.slot);
        if (lens != null) {
            return lens;
        }
    } catch (Exception ignored) {
    }
    // this works as a fallback but removes Inventory Property Support completely
    return new BasicSlotLens(0);
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens)

Example 8 with InventoryAdapter

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

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

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

the class ReverseQuery method execute.

@Override
public Inventory execute(Inventory parent, InventoryAdapter inventory) {
    List<Slot> slots = new ArrayList<>(((Inventory) inventory).slots());
    Collections.reverse(slots);
    CompoundSlotLensProvider slotProvider = new CompoundSlotLensProvider();
    slots.forEach(s -> slotProvider.add((InventoryAdapter) s));
    InventoryAdapter adapter = ((InventoryBridge) inventory).bridge$getAdapter();
    CompoundLens lens = CompoundLens.builder().add(adapter.inventoryAdapter$getRootLens()).build(slotProvider);
    return lens.getAdapter(adapter.inventoryAdapter$getFabric(), (Inventory) inventory);
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) ArrayList(java.util.ArrayList) Slot(org.spongepowered.api.item.inventory.Slot) CompoundSlotLensProvider(org.spongepowered.common.inventory.lens.CompoundSlotLensProvider) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens)

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