Search in sources :

Example 1 with VanillaContainerInteractionBehavior

use of org.lanternpowered.server.inventory.behavior.VanillaContainerInteractionBehavior 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)

Aggregations

LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 VanillaContainerInteractionBehavior (org.lanternpowered.server.inventory.behavior.VanillaContainerInteractionBehavior)1 ClientContainer (org.lanternpowered.server.inventory.client.ClientContainer)1 GuiId (org.spongepowered.api.item.inventory.property.GuiId)1