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);
}
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();
}
}
Aggregations