Search in sources :

Example 1 with ServerboundContainerClosePacket

use of net.minecraft.network.protocol.game.ServerboundContainerClosePacket in project Regeneration by Suff99.

the class TabRegistry method openInventoryGui.

public static void openInventoryGui() {
    Minecraft mc = Minecraft.getInstance();
    mc.player.connection.send(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
    InventoryScreen inventory = new InventoryScreen(mc.player);
    mc.setScreen(inventory);
}
Also used : ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) InventoryScreen(net.minecraft.client.gui.screens.inventory.InventoryScreen) Minecraft(net.minecraft.client.Minecraft)

Example 2 with ServerboundContainerClosePacket

use of net.minecraft.network.protocol.game.ServerboundContainerClosePacket in project Mohist by MohistMC.

the class CraftEventFactory method callInventoryOpenEvent.

public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
    if (player.containerMenu != player.inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId));
    }
    CraftServer server = player.level.getCraftServer();
    CraftPlayer craftPlayer = player.getBukkitEntity();
    player.containerMenu.transferTo(container, craftPlayer);
    InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
    event.setCancelled(cancelled);
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        container.transferTo(player.containerMenu, craftPlayer);
        return null;
    }
    return container;
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)

Example 3 with ServerboundContainerClosePacket

use of net.minecraft.network.protocol.game.ServerboundContainerClosePacket in project Mohist by MohistMC.

the class CraftHumanEntity method openInventory.

@Override
public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof ServerPlayer))
        return;
    if (((ServerPlayer) getHandle()).connection == null)
        return;
    if (getHandle().containerMenu != getHandle().inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        ((ServerPlayer) getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(getHandle().containerMenu.containerId));
    }
    ServerPlayer player = (ServerPlayer) getHandle();
    AbstractContainerMenu container;
    if (inventory instanceof CraftInventoryView) {
        container = ((CraftInventoryView) inventory).getHandle();
    } else {
        container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounterInt());
    }
    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
        return;
    }
    // Now open the window
    MenuType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
    String title = inventory.getTitle();
    player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
    player.containerMenu = container;
    player.initMenu(container);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftInventoryView(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftContainer(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)

Aggregations

ServerboundContainerClosePacket (net.minecraft.network.protocol.game.ServerboundContainerClosePacket)3 Minecraft (net.minecraft.client.Minecraft)1 InventoryScreen (net.minecraft.client.gui.screens.inventory.InventoryScreen)1 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)1 CraftContainer (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)1 CraftInventoryView (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView)1 InventoryOpenEvent (org.bukkit.event.inventory.InventoryOpenEvent)1