Search in sources :

Example 1 with GuiId

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();
}
Also used : GuiIdProperty(org.spongepowered.api.item.inventory.property.GuiIdProperty) SpongeGuiId(org.spongepowered.common.data.type.SpongeGuiId) SpongeGuiId(org.spongepowered.common.data.type.SpongeGuiId) GuiId(org.spongepowered.api.item.inventory.property.GuiId)

Example 2 with GuiId

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

GuiId (org.spongepowered.api.item.inventory.property.GuiId)2 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 GuiIdProperty (org.spongepowered.api.item.inventory.property.GuiIdProperty)1 SpongeGuiId (org.spongepowered.common.data.type.SpongeGuiId)1