Search in sources :

Example 1 with ClientContainer

use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleDoubleClick.

@Override
public void handleDoubleClick(ClientContainer clientContainer, ClientSlot clientSlot) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || !(clientSlot instanceof ClientSlot.Slot)) {
        return;
    }
    final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
    final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(getCursorItem());
    ItemStackSnapshot newItem = oldItem;
    final List<SlotTransaction> transactions = new ArrayList<>();
    if (getCursorItem() != null && !(slot instanceof OutputSlot)) {
        final ItemStack cursorItem = getCursorItem().copy();
        int quantity = cursorItem.getQuantity();
        final int maxQuantity = cursorItem.getMaxStackQuantity();
        if (quantity < maxQuantity) {
            final AbstractInventory inventory;
            if (clientContainer instanceof PlayerClientContainer) {
                inventory = this.container.getPlayerInventory().getView(LanternPlayerInventory.View.ALL_PRIORITY_MAIN);
            } else {
                inventory = AbstractOrderedInventory.viewBuilder().inventory(this.container.getOpenInventory()).inventory(this.container.getPlayerInventory().getView(LanternPlayerInventory.View.PRIORITY_MAIN_AND_HOTBAR)).build();
            }
            // Try first to get enough unfinished stacks
            PeekedPollTransactionResult peekResult = inventory.peekPoll(maxQuantity - quantity, stack -> stack.getQuantity() < stack.getMaxStackQuantity() && ((LanternItemStack) cursorItem).similarTo(stack)).orElse(null);
            if (peekResult != null) {
                quantity += peekResult.getPolledItem().getQuantity();
                transactions.addAll(peekResult.getTransactions());
            }
            // Get the last items for the stack from a full stack
            if (quantity <= maxQuantity) {
                peekResult = this.container.peekPoll(maxQuantity - quantity, stack -> stack.getQuantity() >= stack.getMaxStackQuantity() && ((LanternItemStack) cursorItem).similarTo(stack)).orElse(null);
                if (peekResult != null) {
                    quantity += peekResult.getPolledItem().getQuantity();
                    transactions.addAll(peekResult.getTransactions());
                }
            }
            cursorItem.setQuantity(quantity);
            newItem = cursorItem.createSnapshot();
        }
    }
    final CauseStack causeStack = CauseStack.current();
    final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldItem, newItem);
    final ClickInventoryEvent.Double event = SpongeEventFactory.createClickInventoryEventDouble(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
    finishInventoryEvent(event);
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) CauseStack(org.lanternpowered.server.event.CauseStack) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ArrayList(java.util.ArrayList) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 2 with ClientContainer

use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleDrag.

@Override
public void handleDrag(ClientContainer clientContainer, List<ClientSlot> clientSlots, MouseButton mouseButton) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null)) {
        return;
    }
    final List<AbstractSlot> slots = clientSlots.stream().filter(clientSlot -> clientSlot instanceof ClientSlot.Slot).map(clientSlot -> ((ClientSlot.Slot) clientSlot).getSlot()).collect(Collectors.toList());
    if (slots.size() != clientSlots.size()) {
        // TODO: Is this the behavior we want?
        return;
    }
    final ItemStack cursorItem = getCursorItem();
    if (cursorItem == null || cursorItem.isEmpty()) {
        return;
    }
    final CauseStack causeStack = CauseStack.current();
    if (mouseButton == MouseButton.LEFT) {
        final int quantity = cursorItem.getQuantity();
        final int slotCount = slots.size();
        final int itemsPerSlot = quantity / slotCount;
        final int rest = quantity - itemsPerSlot * slotCount;
        final List<SlotTransaction> transactions = new ArrayList<>();
        for (AbstractSlot slot : slots) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(itemsPerSlot);
            transactions.addAll(slot.peekOffer(itemStack).getTransactions());
        }
        ItemStackSnapshot newCursorItem = ItemStackSnapshot.NONE;
        if (rest > 0) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(rest);
            newCursorItem = LanternItemStackSnapshot.wrap(itemStack);
        }
        final ItemStackSnapshot oldCursorItem = cursorItem.createSnapshot();
        final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldCursorItem, newCursorItem);
        final ClickInventoryEvent.Drag.Primary event = SpongeEventFactory.createClickInventoryEventDragPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
        finishInventoryEvent(event);
    } else if (mouseButton == MouseButton.RIGHT) {
        int quantity = cursorItem.getQuantity();
        final int size = Math.min(slots.size(), quantity);
        final List<SlotTransaction> transactions = new ArrayList<>();
        for (AbstractSlot slot : slots) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(1);
            transactions.addAll(slot.peekOffer(itemStack).getTransactions());
        }
        quantity -= size;
        ItemStackSnapshot newCursorItem = ItemStackSnapshot.NONE;
        if (quantity > 0) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(quantity);
            newCursorItem = LanternItemStackSnapshot.wrap(itemStack);
        }
        final ItemStackSnapshot oldCursorItem = getCursorItem().createSnapshot();
        final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldCursorItem, newCursorItem);
        final ClickInventoryEvent.Drag.Secondary event = SpongeEventFactory.createClickInventoryEventDragSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        finishInventoryEvent(event);
    } else {
    // TODO: Middle mouse drag mode
    }
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) CauseStack(org.lanternpowered.server.event.CauseStack) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ArrayList(java.util.ArrayList) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 3 with ClientContainer

use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.

the class PlayerContainerSession method setRawOpenContainer.

private boolean setRawOpenContainer(CauseStack causeStack, @Nullable LanternContainer container, boolean sendClose, boolean client) {
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        if (this.openContainer != container) {
            frame.addContext(EventContextKeys.PLAYER, this.player);
            ItemStackSnapshot cursorItem = ItemStackSnapshot.NONE;
            if (this.openContainer != null) {
                final ItemStackSnapshot cursorItemSnapshot = this.openContainer.getCursorSlot().peek().map(LanternItemStackSnapshot::wrap).orElse(LanternItemStackSnapshot.none());
                final InteractInventoryEvent.Close event = SpongeEventFactory.createInteractInventoryEventClose(frame.getCurrentCause(), new Transaction<>(cursorItemSnapshot, ItemStackSnapshot.NONE), this.openContainer);
                Sponge.getEventManager().post(event);
                if (event.isCancelled()) {
                    // Stop the client from closing the container, resend the open message
                    if (client) {
                        // This can't be done to the player inventory, player inventory uses index 0
                        // The optional should always return something at this point, otherwise
                        // something is broken
                        final ClientContainer clientContainer = getClientContainer();
                        if (clientContainer.getContainerId() != 0) {
                            // Reinitialize the client container
                            clientContainer.init();
                            return false;
                        }
                    } else {
                        // Just return
                        return false;
                    }
                }
                final Transaction<ItemStackSnapshot> transaction = event.getCursorTransaction();
                if (transaction.isValid()) {
                    if (transaction.getFinal().isEmpty()) {
                        // Add the event that caused the drop to the cause
                        frame.pushCause(event);
                        LanternEventHelper.handleDroppedItemSpawning(this.player.getTransform(), transaction.getOriginal());
                        frame.popCause();
                    } else {
                        cursorItem = transaction.getFinal();
                    }
                }
                // Close the inventory
                this.openContainer.close(causeStack);
            } else {
                sendClose = false;
            }
            if (container != null) {
                final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, cursorItem);
                final InteractInventoryEvent.Open event = SpongeEventFactory.createInteractInventoryEventOpen(frame.getCurrentCause(), cursorTransaction, container);
                Sponge.getEventManager().post(event);
                if (event.isCancelled()) {
                    if (cursorTransaction.isValid()) {
                        final ItemStackSnapshot cursorItem1 = cursorTransaction.getFinal();
                        if (!cursorItem1.isEmpty()) {
                            // Add the event that caused the drop to the cause
                            frame.pushCause(event);
                            LanternEventHelper.handleDroppedItemSpawning(this.player.getTransform(), cursorItem1);
                            frame.popCause();
                        }
                    }
                    return false;
                }
                if (cursorTransaction.isValid()) {
                    final ItemStackSnapshot cursorItem1 = cursorTransaction.getFinal();
                    container.getCursorSlot().setRawItemStack(cursorItem1.createStack());
                }
                sendClose = false;
                container.addViewer(this.player);
            }
            if (sendClose && getContainerId() != 0) {
                this.player.getConnection().send(new MessagePlayInOutCloseWindow(getContainerId()));
            }
            if (this.openContainer != null) {
                this.openContainer.removeViewer(this.player);
            }
        }
        this.openContainer = container;
        return true;
    }
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) Transaction(org.spongepowered.api.data.Transaction) MessagePlayInOutCloseWindow(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutCloseWindow) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) TradingClientContainer(org.lanternpowered.server.inventory.client.TradingClientContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) BeaconClientContainer(org.lanternpowered.server.inventory.client.BeaconClientContainer) EnchantmentTableClientContainer(org.lanternpowered.server.inventory.client.EnchantmentTableClientContainer) AnvilClientContainer(org.lanternpowered.server.inventory.client.AnvilClientContainer) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Example 4 with ClientContainer

use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleShiftClick.

@Override
public void handleShiftClick(ClientContainer clientContainer, ClientSlot clientSlot, MouseButton mouseButton) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || !(clientSlot instanceof ClientSlot.Slot) || mouseButton == MouseButton.MIDDLE) {
        return;
    }
    final AbstractInventorySlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
    final ItemStack itemStack = slot.peek().orElse(null);
    final Transaction<ItemStackSnapshot> cursorTransaction;
    final List<SlotTransaction> transactions = new ArrayList<>();
    if (slot instanceof CraftingOutput) {
        final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
        cursorTransaction = new Transaction<>(cursorItem, cursorItem);
        final AbstractInventory parent = slot.parent();
        if (parent instanceof CraftingInventory) {
            final CraftingInventory inventory = (CraftingInventory) parent;
            final Optional<ExtendedCraftingResult> optResult = Lantern.getRegistry().getCraftingRecipeRegistry().getExtendedResult(inventory.getCraftingGrid(), player.getWorld());
            if (optResult.isPresent()) {
                final ExtendedCraftingResult result = optResult.get();
                final ItemStackSnapshot resultItem = result.getResult().getResult();
                int times = result.getMaxTimes();
                final ItemStack itemStack1 = resultItem.createStack();
                itemStack1.setQuantity(times * itemStack1.getQuantity());
                final AbstractInventory targetInventory = this.container.getPlayerInventory().getView(LanternPlayerInventory.View.REVERSE_MAIN_AND_HOTBAR);
                PeekedOfferTransactionResult peekResult = targetInventory.peekOffer(itemStack1);
                if (peekResult.isSuccess()) {
                    transactions.add(new SlotTransaction(slot, resultItem, ItemStackSnapshot.NONE));
                    final ItemStack rejectedItem = peekResult.getRejectedItem().orElse(null);
                    if (rejectedItem != null) {
                        final int added = itemStack1.getQuantity() - rejectedItem.getQuantity();
                        times = added / resultItem.getQuantity();
                        final int diff = added % resultItem.getQuantity();
                        if (diff != 0) {
                            itemStack1.setQuantity(resultItem.getQuantity() * times);
                            peekResult = targetInventory.peekOffer(itemStack1);
                            checkState(peekResult.isSuccess());
                        }
                    }
                    transactions.addAll(peekResult.getTransactions());
                    updateCraftingGrid(player, inventory, result.getMatrixResult(times), transactions);
                }
            } else {
                // No actual transaction, there shouldn't have been a item in the crafting result slot
                transactions.add(new SlotTransaction(slot, ItemStackSnapshot.NONE, ItemStackSnapshot.NONE));
            }
        } else {
            Lantern.getLogger().warn("Found a CraftingOutput slot without a CraftingInventory as parent.");
            return;
        }
    } else {
        final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
        cursorTransaction = new Transaction<>(cursorItem, cursorItem);
        if (itemStack != null) {
            final IInventory target = this.container.getOpenInventory().getShiftClickBehavior().getTarget(this.container, slot);
            final PeekedOfferTransactionResult result = target.peekOffer(itemStack.copy());
            if (result.isSuccess()) {
                transactions.addAll(result.getTransactions());
                final ItemStack rejectedItem = result.getRejectedItem().orElse(null);
                if (rejectedItem != null) {
                    slot.peekPoll(itemStack.getQuantity() - rejectedItem.getQuantity(), stack -> true).ifPresent(peekResult -> transactions.addAll(peekResult.getTransactions()));
                } else {
                    slot.peekPoll(stack -> true).ifPresent(peekResult -> transactions.addAll(peekResult.getTransactions()));
                }
            }
        }
    }
    final List<SlotTransaction> transactions1 = this.container.transformSlots(transactions);
    final CauseStack causeStack = CauseStack.current();
    final ClickInventoryEvent.Shift event;
    if (mouseButton == MouseButton.LEFT) {
        event = SpongeEventFactory.createClickInventoryEventShiftPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions1);
    } else {
        event = SpongeEventFactory.createClickInventoryEventShiftSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions1);
    }
    finishInventoryEvent(event);
}
Also used : CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) IInventory(org.lanternpowered.server.inventory.IInventory) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) CauseStack(org.lanternpowered.server.event.CauseStack) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) ArrayList(java.util.ArrayList) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 5 with ClientContainer

use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleClick.

@Override
public void handleClick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot, MouseButton mouseButton) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || (clientSlot != null && !(clientSlot instanceof ClientSlot.Slot))) {
        return;
    }
    final CauseStack causeStack = CauseStack.current();
    if (clientSlot == null) {
        causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
        final List<Entity> entities = new ArrayList<>();
        final Transaction<ItemStackSnapshot> cursorTransaction;
        // Clicking outside the container
        ItemStackSnapshot oldItem = ItemStackSnapshot.NONE;
        ItemStackSnapshot newItem = ItemStackSnapshot.NONE;
        if (getCursorItem() != null) {
            oldItem = getCursorItem().createSnapshot();
            final ItemStackSnapshot droppedItem;
            if (mouseButton != MouseButton.LEFT) {
                final ItemStack stack = getCursorItem().copy();
                stack.setQuantity(stack.getQuantity() - 1);
                newItem = LanternItemStack.toSnapshot(stack);
                stack.setQuantity(1);
                droppedItem = LanternItemStack.toSnapshot(stack);
            } else {
                droppedItem = oldItem;
            }
            LanternEventHelper.handlePreDroppedItemSpawning(player.getTransform(), droppedItem).ifPresent(entities::add);
        }
        cursorTransaction = new Transaction<>(oldItem, newItem);
        final ClickInventoryEvent.Drop event;
        if (mouseButton == MouseButton.LEFT) {
            event = SpongeEventFactory.createClickInventoryEventDropOutsidePrimary(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, new ArrayList<>());
        } else {
            event = SpongeEventFactory.createClickInventoryEventDropOutsideSecondary(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, new ArrayList<>());
        }
        finishInventoryEvent(event);
        return;
    }
    // Clicking inside the container
    final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
    if (mouseButton == MouseButton.MIDDLE) {
        final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(getCursorItem());
        Transaction<ItemStackSnapshot> cursorTransaction = null;
        final Optional<GameMode> gameMode = player.get(Keys.GAME_MODE);
        if (gameMode.isPresent() && gameMode.get().equals(GameModes.CREATIVE) && getCursorItem() == null) {
            final ItemStack stack = slot.peek().orElse(null);
            if (stack != null) {
                stack.setQuantity(stack.getMaxStackQuantity());
                cursorTransaction = new Transaction<>(oldItem, stack.createSnapshot());
            }
        }
        if (cursorTransaction == null) {
            cursorTransaction = new Transaction<>(oldItem, oldItem);
        }
        final ClickInventoryEvent.Middle event = SpongeEventFactory.createClickInventoryEventMiddle(causeStack.getCurrentCause(), cursorTransaction, this.container, new ArrayList<>());
        finishInventoryEvent(event);
    } else {
        // Crafting slots have special click behavior
        if (slot instanceof CraftingOutput) {
            List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction;
            final AbstractInventory parent = slot.parent();
            if (parent instanceof CraftingInventory) {
                ClickInventoryEvent event;
                final CraftingInventory inventory = (CraftingInventory) parent;
                final Optional<ExtendedCraftingResult> optResult = Lantern.getRegistry().getCraftingRecipeRegistry().getExtendedResult(inventory.getCraftingGrid(), player.getWorld());
                final ItemStackSnapshot originalCursorItem = LanternItemStack.toSnapshot(getCursorItem());
                if (optResult.isPresent()) {
                    final CraftingResult result = optResult.get().getResult();
                    final ItemStackSnapshot resultItem = result.getResult();
                    int quantity = -1;
                    if (getCursorItem() == null) {
                        quantity = resultItem.getQuantity();
                    } else if (LanternItemStack.areSimilar(resultItem.createStack(), getCursorItem())) {
                        final int quantity1 = resultItem.getQuantity() + getCursorItem().getQuantity();
                        if (quantity1 < getCursorItem().getMaxStackQuantity()) {
                            quantity = quantity1;
                        }
                    }
                    if (quantity == -1) {
                        cursorTransaction = new Transaction<>(originalCursorItem, originalCursorItem);
                        transactions.add(new SlotTransaction(slot, resultItem, resultItem));
                    } else {
                        final LanternItemStack itemStack = (LanternItemStack) resultItem.createStack();
                        itemStack.setQuantity(quantity);
                        cursorTransaction = new Transaction<>(originalCursorItem, itemStack.createSnapshot());
                        transactions.add(new SlotTransaction(slot, resultItem, ItemStackSnapshot.NONE));
                        updateCraftingGrid(player, inventory, optResult.get().getMatrixResult(1), transactions);
                    }
                } else {
                    cursorTransaction = new Transaction<>(originalCursorItem, originalCursorItem);
                    // No actual transaction, there shouldn't have been a item in the crafting result slot
                    transactions.add(new SlotTransaction(slot, ItemStackSnapshot.NONE, ItemStackSnapshot.NONE));
                }
                transactions = this.container.transformSlots(transactions);
                if (mouseButton == MouseButton.LEFT) {
                    event = SpongeEventFactory.createClickInventoryEventPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
                } else {
                    event = SpongeEventFactory.createClickInventoryEventSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
                }
                finishInventoryEvent(event);
                return;
            } else {
                Lantern.getLogger().warn("Found a CraftingOutput slot without a CraftingInventory as parent.");
            }
        }
        ClickInventoryEvent event;
        if (mouseButton == MouseButton.LEFT) {
            final List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction = null;
            if (getCursorItem() != null && !(slot instanceof OutputSlot)) {
                final PeekedOfferTransactionResult result = slot.peekOffer(getCursorItem());
                if (result.isSuccess()) {
                    transactions.addAll(result.getTransactions());
                    cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(result.getRejectedItem().orElse(null)));
                } else {
                    final PeekedSetTransactionResult result1 = slot.peekSet(getCursorItem());
                    if (result1.isSuccess()) {
                        cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(result1.getReplacedItem().orElse(null)));
                        transactions.addAll(result1.getTransactions());
                    }
                }
            } else if (getCursorItem() == null) {
                final PeekedPollTransactionResult result = slot.peekPoll(stack -> true).orElse(null);
                if (result != null) {
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, LanternItemStack.toSnapshot(result.getPolledItem()));
                    transactions.addAll(result.getTransactions());
                } else {
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, ItemStackSnapshot.NONE);
                }
            }
            if (cursorTransaction == null) {
                final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
                cursorTransaction = new Transaction<>(cursorItem, cursorItem);
            }
            event = SpongeEventFactory.createClickInventoryEventPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        } else {
            final List<SlotTransaction> transactions = new ArrayList<>();
            Transaction<ItemStackSnapshot> cursorTransaction = null;
            if (getCursorItem() == null) {
                int stackSize = slot.getStackSize();
                if (stackSize != 0) {
                    stackSize = stackSize - (stackSize / 2);
                    final PeekedPollTransactionResult result = slot.peekPoll(stackSize, stack -> true).get();
                    transactions.addAll(result.getTransactions());
                    cursorTransaction = new Transaction<>(ItemStackSnapshot.NONE, result.getPolledItem().createSnapshot());
                }
            } else {
                final ItemStack itemStack = getCursorItem().copy();
                itemStack.setQuantity(1);
                final PeekedOfferTransactionResult result = slot.peekOffer(itemStack);
                if (result.isSuccess()) {
                    final ItemStackSnapshot oldCursor = getCursorItem().createSnapshot();
                    int quantity = getCursorItem().getQuantity() - 1;
                    if (quantity <= 0) {
                        cursorTransaction = new Transaction<>(oldCursor, ItemStackSnapshot.NONE);
                    } else {
                        final ItemStack newCursorItem = getCursorItem().copy();
                        newCursorItem.setQuantity(quantity);
                        cursorTransaction = new Transaction<>(oldCursor, newCursorItem.createSnapshot());
                    }
                    transactions.addAll(result.getTransactions());
                } else {
                    final PeekedSetTransactionResult result1 = slot.peekSet(getCursorItem());
                    if (result1.isSuccess()) {
                        final ItemStack replacedItem = result1.getReplacedItem().orElse(null);
                        if (replacedItem != null) {
                            setCursorItem(replacedItem);
                            cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), LanternItemStack.toSnapshot(replacedItem));
                        } else {
                            cursorTransaction = new Transaction<>(getCursorItem().createSnapshot(), ItemStackSnapshot.NONE);
                        }
                        transactions.addAll(result1.getTransactions());
                    }
                }
            }
            if (cursorTransaction == null) {
                final ItemStackSnapshot cursorItem = LanternItemStack.toSnapshot(getCursorItem());
                cursorTransaction = new Transaction<>(cursorItem, cursorItem);
            }
            event = SpongeEventFactory.createClickInventoryEventSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        }
        finishInventoryEvent(event);
    }
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) Entity(org.spongepowered.api.entity.Entity) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) ArrayList(java.util.ArrayList) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) CauseStack(org.lanternpowered.server.event.CauseStack) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

ClientContainer (org.lanternpowered.server.inventory.client.ClientContainer)12 PlayerClientContainer (org.lanternpowered.server.inventory.client.PlayerClientContainer)10 Nullable (javax.annotation.Nullable)7 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)7 CauseStack (org.lanternpowered.server.event.CauseStack)7 Transaction (org.spongepowered.api.data.Transaction)7 Preconditions.checkState (com.google.common.base.Preconditions.checkState)6 Streams (com.google.common.collect.Streams)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 LanternEventHelper (org.lanternpowered.server.event.LanternEventHelper)6 Lantern (org.lanternpowered.server.game.Lantern)6 AbstractInventory (org.lanternpowered.server.inventory.AbstractInventory)6 AbstractInventorySlot (org.lanternpowered.server.inventory.AbstractInventorySlot)6 AbstractOrderedInventory (org.lanternpowered.server.inventory.AbstractOrderedInventory)6 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)6 IInventory (org.lanternpowered.server.inventory.IInventory)6 LanternContainer (org.lanternpowered.server.inventory.LanternContainer)6