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()));
}
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;
}
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);
}
}
}
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));
}
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;
}
Aggregations