use of org.spongepowered.api.item.inventory.property.GuiId in project SpongeCommon by SpongePowered.
the class CustomInventory method getGuiID.
@Override
public String getGuiID() {
String key = AbstractInventoryProperty.getDefaultKey(GuiIdProperty.class).toString();
InventoryProperty<?, ?> property = this.properties.get(key);
if (property instanceof GuiIdProperty) {
if (property.getValue() instanceof SpongeGuiId) {
// Handle Vanilla EntityHorse GuiId
return ((SpongeGuiId) property.getValue()).getInternalId();
}
return ((GuiIdProperty) property).getValue().getId();
}
GuiId guiId = this.archetype.getProperty(GuiIdProperty.class, key).map(GuiIdProperty::getValue).orElse(GuiIds.CHEST);
if (guiId instanceof SpongeGuiId) {
// Handle Vanilla EntityHorse GuiId
return ((SpongeGuiId) guiId).getInternalId();
}
return guiId.getId();
}
use of org.spongepowered.api.item.inventory.property.GuiId 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);
}
Aggregations