Search in sources :

Example 6 with SOpenWindowPacket

use of net.minecraft.network.play.server.SOpenWindowPacket in project LoliServer by Loli-Server.

the class CraftHumanEntity method openInventory.

@Override
public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof ServerPlayerEntity))
        return;
    if (((ServerPlayerEntity) getHandle()).connection == null)
        return;
    if (getHandle().containerMenu != getHandle().inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        ((ServerPlayerEntity) getHandle()).connection.handleContainerClose(new CCloseWindowPacket(getHandle().containerMenu.containerId));
    }
    ServerPlayerEntity player = (ServerPlayerEntity) getHandle();
    net.minecraft.inventory.container.Container container;
    if (inventory instanceof CraftInventoryView) {
        container = ((CraftInventoryView) inventory).getHandle();
    } else {
        container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounterCB());
    }
    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
        return;
    }
    // Now open the window
    ContainerType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
    String title = inventory.getTitle();
    player.connection.send(new SOpenWindowPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
    player.containerMenu = container;
    player.containerMenu.addSlotListener(player);
}
Also used : CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) Container(net.minecraft.inventory.container.Container) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket)

Aggregations

SOpenWindowPacket (net.minecraft.network.play.server.SOpenWindowPacket)6 Container (net.minecraft.inventory.container.Container)3 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 IInventory (net.minecraft.inventory.IInventory)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)2 ChestContainer (net.minecraft.inventory.container.ChestContainer)1 CCloseWindowPacket (net.minecraft.network.play.client.CCloseWindowPacket)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1 CraftContainer (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)1