use of org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory 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);
}
Aggregations