use of net.minecraft.network.play.server.SOpenWindowPacket in project Enigmatic-Legacy by Aizistral-Studios.
the class PacketEnderRingKey method handle.
public static void handle(PacketEnderRingKey msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
ServerPlayerEntity playerServ = ctx.get().getSender();
if (playerServ.openContainer.windowId == 0)
if (SuperpositionHandler.hasCurio(playerServ, EnigmaticLegacy.enderRing)) {
ChestContainer container = ChestContainer.createGeneric9X3(playerServ.currentWindowId + 1, playerServ.inventory, playerServ.getInventoryEnderChest());
playerServ.currentWindowId = container.windowId;
playerServ.connection.sendPacket(new SOpenWindowPacket(container.windowId, container.getType(), new TranslationTextComponent("container.enderchest")));
container.addListener(playerServ);
playerServ.openContainer = container;
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(playerServ, playerServ.openContainer));
playerServ.world.playSound(null, playerServ.getPosition(), SoundEvents.BLOCK_ENDER_CHEST_OPEN, SoundCategory.PLAYERS, 1.0F, (float) (0.8F + (Math.random() * 0.2)));
}
});
ctx.get().setPacketHandled(true);
}
use of net.minecraft.network.play.server.SOpenWindowPacket in project Magma-1.16.x by magmafoundation.
the class CraftHumanEntity method openCustomInventory.
private void openCustomInventory(Inventory inventory, ServerPlayerEntity player, ContainerType<?> windowType) {
if (player.connection == null)
return;
Preconditions.checkArgument(windowType != null, "Unknown windowType");
net.minecraft.inventory.container.Container container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(player, container);
if (container == null)
return;
// String title = container.getBukkitView().getTitle(); // Paper - comment
// Paper
net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title();
// Paper
if (adventure$title == null)
adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(container.getBukkitView().getTitle());
// player.connection.send(new SOpenWindowPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
// Paper
player.connection.send(new SOpenWindowPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title)));
getHandle().containerMenu = container;
getHandle().containerMenu.addSlotListener(player);
}
use of net.minecraft.network.play.server.SOpenWindowPacket in project LoliServer by Loli-Server.
the class CraftHumanEntity method openCustomInventory.
private void openCustomInventory(Inventory inventory, ServerPlayerEntity player, ContainerType<?> windowType) {
if (player.connection == null)
return;
Preconditions.checkArgument(windowType != null, "Unknown windowType");
net.minecraft.inventory.container.Container container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounterCB());
container = CraftEventFactory.callInventoryOpenEvent(player, container);
if (container == null)
return;
String title = container.getBukkitView().getTitle();
player.connection.send(new SOpenWindowPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
getHandle().containerMenu = container;
getHandle().containerMenu.addSlotListener(player);
}
use of net.minecraft.network.play.server.SOpenWindowPacket in project Magma-1.16.x by magmafoundation.
the class CraftContainer method isSynched.
@Override
public boolean isSynched(PlayerEntity entityhuman) {
if (cachedType == view.getType() && cachedSize == getSize() && this.adventure$title.equals(view.title())) {
// Paper
return true;
}
// If the window type has changed for some reason, update the player
// This method will be called every tick or something, so it's
// as good a place as any to put something like this.
boolean typeChanged = (cachedType != view.getType());
cachedType = view.getType();
// Paper
this.adventure$title = view.title();
// Paper
if (this.adventure$title == null)
this.adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(view.getTitle());
// cachedTitle = view.getTitle(); // Paper - comment
if (view.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) view.getPlayer();
ContainerType<?> type = getNotchInventoryType(view.getTopInventory());
IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
PlayerInventory bottom = (PlayerInventory) ((CraftInventory) view.getBottomInventory()).getInventory();
this.lastSlots.clear();
this.slots.clear();
if (typeChanged) {
setupSlots(top, bottom, player.getHandle());
}
int size = getSize();
// Paper
player.getHandle().connection.send(new SOpenWindowPacket(this.containerId, type, io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure$title)));
// player.getHandle().connection.send(new SOpenWindowPacket(this.containerId, type, new StringTextComponent(cachedTitle))); // Paper - comment
player.updateInventory();
}
return true;
}
use of net.minecraft.network.play.server.SOpenWindowPacket in project LoliServer by Loli-Server.
the class CraftContainer method isSynched.
@Override
public boolean isSynched(PlayerEntity entityhuman) {
if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) {
return true;
}
// If the window type has changed for some reason, update the player
// This method will be called every tick or something, so it's
// as good a place as any to put something like this.
boolean typeChanged = (cachedType != view.getType());
cachedType = view.getType();
cachedTitle = view.getTitle();
if (view.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) view.getPlayer();
ContainerType<?> type = getNotchInventoryType(view.getTopInventory());
IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
PlayerInventory bottom = (PlayerInventory) ((CraftInventory) view.getBottomInventory()).getInventory();
this.lastSlots.clear();
this.slots.clear();
if (typeChanged) {
setupSlots(top, bottom, player.getHandle());
}
int size = getSize();
player.getHandle().connection.send(new SOpenWindowPacket(this.containerId, type, new StringTextComponent(cachedTitle)));
player.updateInventory();
}
return true;
}
Aggregations