Search in sources :

Example 16 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_8_R1 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventoryView)

Example 17 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_9_R1 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventoryView)

Example 18 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView in project Magma-1.16.x by magmafoundation.

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.nextContainerCounter());
    }
    // 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(); // Paper - comment
    // Paper
    net.kyori.adventure.text.Component adventure$title = inventory.title();
    // Paper
    if (adventure$title == null)
        adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(inventory.getTitle());
    player.containerMenu = container;
    player.containerMenu.addSlotListener(player);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView) CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) Container(net.minecraft.inventory.container.Container) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 19 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView 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);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftInventoryView(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftContainer(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)

Aggregations

CraftInventoryView (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView)3 CraftInventoryView (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventoryView)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.Container)1 Container (net.minecraft.inventory.container.Container)1 CCloseWindowPacket (net.minecraft.network.play.client.CCloseWindowPacket)1 CPacketCloseWindow (net.minecraft.network.play.client.CPacketCloseWindow)1 SPacketOpenWindow (net.minecraft.network.play.server.SPacketOpenWindow)1 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)1 ServerboundContainerClosePacket (net.minecraft.network.protocol.game.ServerboundContainerClosePacket)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1