Search in sources :

Example 1 with ClientboundOpenScreenPacket

use of net.minecraft.network.protocol.game.ClientboundOpenScreenPacket in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)

Example 2 with ClientboundOpenScreenPacket

use of net.minecraft.network.protocol.game.ClientboundOpenScreenPacket in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)

Example 3 with ClientboundOpenScreenPacket

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

the class CloseMenuTransaction method reopen.

private void reopen(final ServerPlayer player, final AbstractContainerMenu container) {
    if (container.getSlot(0) == null) {
        return;
    }
    if (!(container instanceof InventoryMenu)) {
        // Inventory closed by client, reopen window and send container
        player.containerMenu = container;
        final Slot slot = container.getSlot(0);
        final net.minecraft.world.Container slotInventory = slot.container;
        final net.minecraft.network.chat.@Nullable Component title;
        // TODO get name from last open
        if (slotInventory instanceof MenuProvider) {
            title = ((MenuProvider) slotInventory).getDisplayName();
        } else {
            // expected fallback for unknown types
            title = null;
        }
        slotInventory.startOpen(player);
        player.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), title));
        // resync data to client
        player.refreshContainer(container);
    } else {
    // TODO: Maybe print a warning or throw an exception here?
    // The player gui cannot be opened from the
    // server so allowing this event to be cancellable when the
    // GUI has been closed already would result
    // in opening the wrong GUI window.
    }
}
Also used : InventoryMenu(net.minecraft.world.inventory.InventoryMenu) Slot(net.minecraft.world.inventory.Slot) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) MenuProvider(net.minecraft.world.MenuProvider) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)3 TextComponent (net.minecraft.network.chat.TextComponent)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)2 MenuProvider (net.minecraft.world.MenuProvider)1 InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 Slot (net.minecraft.world.inventory.Slot)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftContainer (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1 CraftContainer (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1