Search in sources :

Example 1 with SOpenWindowPacket

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);
}
Also used : ChestContainer(net.minecraft.inventory.container.ChestContainer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket)

Example 2 with SOpenWindowPacket

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);
}
Also used : Container(net.minecraft.inventory.container.Container) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 3 with SOpenWindowPacket

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);
}
Also used : Container(net.minecraft.inventory.container.Container) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket)

Example 4 with SOpenWindowPacket

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;
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) PlayerInventory(net.minecraft.entity.player.PlayerInventory) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket)

Example 5 with SOpenWindowPacket

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;
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) StringTextComponent(net.minecraft.util.text.StringTextComponent) PlayerInventory(net.minecraft.entity.player.PlayerInventory) 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