Search in sources :

Example 1 with InventoryAdapter

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

the class TransactionSink method logClickContainer.

default EffectTransactor logClickContainer(final AbstractContainerMenu menu, final int slotNum, final int buttonNum, final ClickType clickType, final Player player) {
    @Nullable Slot slot = null;
    if (buttonNum >= 0) {
        // Try to get valid slot - might not be present e.g. for drag-events
        slot = ((InventoryAdapter) menu).inventoryAdapter$getSlot(slotNum).orElse(null);
    }
    final ClickMenuTransaction transaction = new ClickMenuTransaction(player, menu, slotNum, buttonNum, clickType, slot, ItemStackUtil.snapshotOf(player.inventory.getCarried()));
    this.logTransaction(transaction);
    return this.pushEffect(new ResultingTransactionBySideEffect(InventoryEffect.getInstance()));
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) ClickMenuTransaction(org.spongepowered.common.event.tracking.context.transaction.inventory.ClickMenuTransaction) Slot(org.spongepowered.api.item.inventory.Slot) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 2 with InventoryAdapter

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

the class SpongeInventoryBuilder method grid.

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

Example 3 with InventoryAdapter

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

the class PacketPhaseUtil method validateCapturedTransactions.

public static void validateCapturedTransactions(final int slotId, final AbstractContainerMenu containerMenu, final List<SlotTransaction> capturedTransactions) {
    if (capturedTransactions.size() == 0 && slotId >= 0 && slotId < containerMenu.slots.size()) {
        final Slot slot = containerMenu.getSlot(slotId);
        if (slot != null) {
            final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(slot.getItem());
            final SlotTransaction slotTransaction = new SlotTransaction(((InventoryAdapter) containerMenu).inventoryAdapter$getSlot(slotId).get(), snapshot, snapshot);
            capturedTransactions.add(slotTransaction);
        }
    }
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) Slot(net.minecraft.world.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction)

Example 4 with InventoryAdapter

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

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

the class TraitMixin_Equipable_Inventory_API method equipment.

@Override
public EquipmentInventory equipment() {
    if (this.impl$equipmentInventory == null) {
        final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
        final EquipmentInventoryLens lens = (EquipmentInventoryLens) inv.inventoryAdapter$getRootLens();
        this.impl$equipmentInventory = (EquipmentInventory) lens.getAdapter(inv.inventoryAdapter$getFabric(), null);
    }
    return this.impl$equipmentInventory;
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) 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