Search in sources :

Example 31 with ContainerAnvil

use of net.minecraft.server.v1_16_R3.ContainerAnvil in project TheAPI by TheDevTec.

the class v1_7_R4 method openAnvilGUI.

@Override
public void openAnvilGUI(Player player, Object con, String title, ItemStack[] items) {
    ContainerAnvil container = (ContainerAnvil) con;
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = container.windowId;
    net.minecraft.server.v1_7_R4.ItemStack[] nmsItems = new net.minecraft.server.v1_7_R4.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_7_R4.ItemStack item = null;
        container.setItem(i, item = (net.minecraft.server.v1_7_R4.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, "minecraft:anvil", 0, title));
    int i = 0;
    for (net.minecraft.server.v1_7_R4.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    container.checkReachable = false;
}
Also used : IContainer(net.minecraft.server.v1_7_R4.IContainer) CraftContainer(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftContainer) Container(net.minecraft.server.v1_7_R4.Container) ContainerAnvil(net.minecraft.server.v1_7_R4.ContainerAnvil) EntityPlayer(net.minecraft.server.v1_7_R4.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Example 32 with ContainerAnvil

use of net.minecraft.server.v1_16_R3.ContainerAnvil in project TheAPI by TheDevTec.

the class v1_7_R4 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.slot;
    if (slot == -999)
        return false;
    int id = packet.c();
    int mouseClick = packet.e();
    InventoryClickType type = InventoryClickType.values()[packet.h()];
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.g());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType() == Material.AIR) && item.getType() == Material.AIR)
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getContents() : gui.getInventory().getContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    } else if (type == InventoryClickType.QUICK_MOVE)
        cancel = true;
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).b((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_7_R4.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_7_R4.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Example 33 with ContainerAnvil

use of net.minecraft.server.v1_16_R3.ContainerAnvil in project TheAPI by TheDevTec.

the class v1_8_R1 method openAnvilGUI.

@Override
public void openAnvilGUI(Player player, Object con, String title, ItemStack[] items) {
    ContainerAnvil container = (ContainerAnvil) con;
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = container.windowId;
    net.minecraft.server.v1_8_R1.ItemStack[] nmsItems = new net.minecraft.server.v1_8_R1.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_8_R1.ItemStack item = null;
        container.setItem(i, item = (net.minecraft.server.v1_8_R1.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, "minecraft:anvil", 0, title));
    int i = 0;
    for (net.minecraft.server.v1_8_R1.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    container.checkReachable = false;
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftContainer) IContainer(net.minecraft.server.v1_8_R1.IContainer) Container(net.minecraft.server.v1_8_R1.Container) ContainerAnvil(net.minecraft.server.v1_8_R1.ContainerAnvil) EntityPlayer(net.minecraft.server.v1_8_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)

Example 34 with ContainerAnvil

use of net.minecraft.server.v1_16_R3.ContainerAnvil in project TheAPI by TheDevTec.

the class v1_8_R1 method createAnvilContainer.

public Object createAnvilContainer(Inventory inv, Player player) {
    int id = ((CraftPlayer) player).getHandle().nextContainerCounter();
    ContainerAnvil anvil = new ContainerAnvil(((CraftPlayer) player).getHandle().inventory, ((CraftPlayer) player).getHandle().world, zero, ((CraftPlayer) player).getHandle());
    anvil.windowId = id;
    for (int i = 0; i < 2; ++i) anvil.setItem(i, (net.minecraft.server.v1_8_R1.ItemStack) asNMSItem(inv.getItem(i)));
    return anvil;
}
Also used : ContainerAnvil(net.minecraft.server.v1_8_R1.ContainerAnvil) CraftPlayer(org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)

Example 35 with ContainerAnvil

use of net.minecraft.server.v1_16_R3.ContainerAnvil in project TheAPI by TheDevTec.

the class v1_8_R1 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.b();
    if (slot == -999)
        return false;
    int id = packet.a();
    int mouseClick = packet.c();
    InventoryClickType type = InventoryClickType.values()[packet.f()];
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.e());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType() == Material.AIR) && item.getType() == Material.AIR)
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getContents() : gui.getInventory().getContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).b((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_8_R1.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_8_R1.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 InventoryClickType (me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType)15 AnvilGUI (me.devtec.theapi.bukkit.gui.AnvilGUI)15 ClickType (me.devtec.theapi.bukkit.gui.GUI.ClickType)15 ContainerAnvil (net.minecraft.server.v1_12_R1.ContainerAnvil)3 ContainerAnvil (net.minecraft.server.v1_7_R4.ContainerAnvil)3 ContainerAnvil (net.minecraft.server.v1_8_R1.ContainerAnvil)3 ContainerAnvil (net.minecraft.server.v1_8_R2.ContainerAnvil)3 ContainerAnvil (net.minecraft.server.v1_8_R3.ContainerAnvil)3 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)3 ContainerAnvil (net.minecraft.server.v1_10_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_11_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_13_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_13_R2.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_14_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_16_R1.ContainerAnvil)2 ContainerAnvil (net.minecraft.server.v1_16_R2.ContainerAnvil)2