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