Search in sources :

Example 1 with ClientboundContainerClosePacket

use of net.minecraft.network.protocol.game.ClientboundContainerClosePacket in project SpongeCommon by SpongePowered.

the class CloseMenuTransaction method postProcessEvent.

@Override
public void postProcessEvent(final PhaseContext<@NonNull ?> context, final InteractContainerEvent event) {
    if (!this.clientSource) {
        // Server closed send packet to client
        this.player.connection.send(new ClientboundContainerClosePacket(this.player.containerMenu.containerId));
    }
    // Finish closing container
    this.player.containerMenu = this.player.inventoryMenu;
    // And restore cursor if needed
    PacketPhaseUtil.handleCursorRestore(this.player, event.cursorTransaction());
    if (event instanceof ChangeInventoryEvent) {
        PacketPhaseUtil.handleSlotRestore(this.player, this.menu, ((ChangeInventoryEvent) event).transactions(), event.isCancelled());
    }
    // prevent double capture
    this.player.inventoryMenu.broadcastChanges();
}
Also used : ClientboundContainerClosePacket(net.minecraft.network.protocol.game.ClientboundContainerClosePacket) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent)

Aggregations

ClientboundContainerClosePacket (net.minecraft.network.protocol.game.ClientboundContainerClosePacket)1 ChangeInventoryEvent (org.spongepowered.api.event.item.inventory.ChangeInventoryEvent)1