Search in sources :

Example 11 with ClientContainer

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

the class LanternContainer method addViewer.

/**
 * Adds and opens a {@link ClientContainer} for the {@link Player}.
 *
 * @param viewer The viewer
 */
void addViewer(Player viewer) {
    checkNotNull(viewer, "viewer");
    checkState(!this.viewers.containsKey(viewer));
    final ClientContainer clientContainer;
    // Get the gui id (ClientContainerType)
    final GuiId guiId = this.openInventory.getInventoryProperty(GuiIdProperty.class).map(GuiIdProperty::getValue).orElseThrow(IllegalStateException::new);
    clientContainer = ((ClientContainerType) guiId).createContainer(this.openInventory);
    clientContainer.bindCursor(this.cursor);
    clientContainer.bindInteractionBehavior(new VanillaContainerInteractionBehavior(this));
    this.openInventory.initClientContainer(clientContainer);
    // Bind the default bottom container part if the custom one is missing
    if (!clientContainer.getBottom().isPresent()) {
        final LanternPlayer player = (LanternPlayer) getPlayerInventory().getCarrier().get();
        clientContainer.bindBottom(player.getInventoryContainer().getClientContainer().getBottom().get());
    }
    this.viewers.put(viewer, clientContainer);
    clientContainer.bind(viewer);
    clientContainer.init();
    addViewer(viewer, this);
}
Also used : ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) GuiId(org.spongepowered.api.item.inventory.property.GuiId) VanillaContainerInteractionBehavior(org.lanternpowered.server.inventory.behavior.VanillaContainerInteractionBehavior) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 12 with ClientContainer

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

the class LanternContainer method removeViewer.

@Nullable
void removeViewer(Player viewer) {
    checkNotNull(viewer, "viewer");
    final ClientContainer clientContainer = this.viewers.remove(viewer);
    if (clientContainer != null) {
        removeViewer(viewer, this);
        clientContainer.release();
    }
}
Also used : ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) Nullable(javax.annotation.Nullable)

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