use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.
the class VanillaContainerInteractionBehavior method handleDropKey.
@Override
public void handleDropKey(ClientContainer clientContainer, ClientSlot clientSlot, boolean ctrl) {
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 CauseStack causeStack = CauseStack.current();
causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
final List<Entity> entities = new ArrayList<>();
final Transaction<ItemStackSnapshot> cursorTransaction;
List<SlotTransaction> slotTransactions = new ArrayList<>();
final ItemStackSnapshot item = LanternItemStack.toSnapshot(getCursorItem());
cursorTransaction = new Transaction<>(item, item);
final Optional<PeekedPollTransactionResult> result = ctrl ? slot.peekPoll(itemStack -> true) : slot.peekPoll(1, itemStack -> true);
if (result.isPresent()) {
final List<SlotTransaction> transactions = result.get().getTransactions();
slotTransactions.addAll(transactions);
final ItemStack itemStack = transactions.get(0).getOriginal().createStack();
itemStack.setQuantity(itemStack.getQuantity() - transactions.get(0).getFinal().getQuantity());
LanternEventHelper.handlePreDroppedItemSpawning(player.getTransform(), LanternItemStackSnapshot.wrap(itemStack)).ifPresent(entities::add);
}
slotTransactions = this.container.transformSlots(slotTransactions);
final ClickInventoryEvent.Drop event;
if (ctrl) {
event = SpongeEventFactory.createClickInventoryEventDropFull(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, slotTransactions);
} else {
event = SpongeEventFactory.createClickInventoryEventDropSingle(causeStack.getCurrentCause(), cursorTransaction, entities, this.container, slotTransactions);
}
finishInventoryEvent(event);
}
use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.
the class VanillaContainerInteractionBehavior method handlePick.
@Override
public void handlePick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot) {
final LanternPlayer player = clientContainer.getPlayer();
if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || !(clientSlot instanceof ClientSlot.Slot)) {
return;
}
final PlayerInventoryContainer inventoryContainer = player.getInventoryContainer();
final ClientSlot hotbarClientSlot = inventoryContainer.getClientContainer().getSelectedHotbarSlot();
if (!(hotbarClientSlot instanceof ClientSlot.Slot)) {
return;
}
final LanternHotbarInventory hotbar = player.getInventory().getHotbar();
final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
// The slot we will swap items with
AbstractSlot hotbarSlot = hotbar.getSelectedSlot();
if (hotbarSlot.peek().isPresent()) {
final Optional<AbstractSlot> optSlot = Streams.stream(hotbar.<AbstractSlot>slots()).filter(slot1 -> !slot1.peek().isPresent()).findFirst();
if (optSlot.isPresent()) {
hotbarSlot = optSlot.get();
}
}
final ItemStack slotItem = slot.peek().orElse(null);
final ItemStack hotbarItem = hotbarSlot.peek().orElse(null);
hotbarSlot.set(slotItem);
hotbar.setSelectedSlotIndex(hotbar.getSlotIndex(hotbarSlot));
slot.set(hotbarItem);
}
use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.
the class PlayerContainerSession method handleWindowClick.
public void handleWindowClick(MessagePlayInClickWindow message) {
final int windowId = message.getWindowId();
if (this.openContainer == null) {
if (message.getWindowId() == 0) {
openPlayerContainer();
} else {
return;
}
} else if (windowId != getContainerId()) {
return;
}
final ClientContainer clientContainer = getClientContainer();
clientContainer.handleClick(message.getSlot(), message.getMode(), message.getButton());
}
use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.
the class PlayerContainerSession method handlePickItem.
public void handlePickItem(MessagePlayInPickItem message) {
final ClientContainer clientContainer = getClientContainer();
clientContainer.handlePick(message.getSlot());
}
use of org.lanternpowered.server.inventory.client.ClientContainer in project LanternServer by LanternPowered.
the class PlayerContainerSession method handleWindowCreativeClick.
public void handleWindowCreativeClick(MessagePlayInCreativeWindowAction message) {
if (this.openContainer == null) {
openPlayerContainer();
}
final ClientContainer clientContainer = getClientContainer();
clientContainer.handleCreativeClick(message.getSlot(), message.getItemStack());
}
Aggregations