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