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