Search in sources :

Example 16 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method serialize.

private void serialize(Inventory inventory, NBTTagCompound tagCompound) {
    NBTTagList itemsList = new NBTTagList();
    org.bukkit.inventory.ItemStack[] items = inventory.getContents();
    for (int i = 0; i < items.length; ++i) {
        if (items[i] != null) {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            nbtTagCompound.setByte("Slot", (byte) i);
            CraftItemStack.asNMSCopy(items[i]).save(nbtTagCompound);
            itemsList.add(nbtTagCompound);
        }
    }
    tagCompound.setInt("Size", inventory.getSize());
    tagCompound.set("Items", itemsList);
}
Also used : NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 17 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project TheAPI by TheDevTec.

the class v1_8_R3 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_R3.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_8_R3.PacketPlayInWindowClick) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 18 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.12.2
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) theseSlots.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return ItemStack.a;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return ItemStack.a;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.f();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_13_R2.Slot) ItemStack(net.minecraft.server.v1_13_R2.ItemStack)

Example 19 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method b.

/**
 * The shift clicking method
 */
@Override
public ItemStack b(EntityHuman entityhuman, int i) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.c.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return null;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return null;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return null;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return null;
        }
        slot.f();
        if (itemstack1.count == itemstack.count) {
            return null;
        }
        slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack1, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_8_R3.Slot) ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Example 20 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.15.1
@Override
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) this.slots.get(i);
    if (slot != null && slot.hasItem()) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            this.containerAccess.a((world, blockposition) -> {
                itemstack1.getItem().b(itemstack1, world, entityhuman);
            });
            if (!this.a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if (i >= 10 && i < 46 ? !this.a(itemstack1, 1, 10, false) && (i < 37 ? !this.a(itemstack1, 37, 46, false) : !this.a(itemstack1, 10, 37, false)) : !this.a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.d();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : Slot(net.minecraft.server.v1_15_R1.Slot) ItemStack(net.minecraft.server.v1_15_R1.ItemStack)

Aggregations

ItemStack (net.minecraft.server.v1_8_R3.ItemStack)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)4 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)4 Slot (net.minecraft.server.v1_12_R1.Slot)3 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)2 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)2 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2 HardwareTokenType (ee.ria.xroad.signer.tokenmanager.token.HardwareTokenType)2 Slot (iaik.pkcs.pkcs11.Slot)2 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)2 Slot (net.minecraft.server.v1_11_R1.Slot)2 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)2 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)2 InventoryHolder (com.bgsoftware.wildchests.objects.inventory.InventoryHolder)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_8_R3.nbt.NbtTagCompound)1 CustomInventory (de.Keyle.MyPet.compat.v1_8_R3.util.inventory.CustomInventory)1 TokenType (ee.ria.xroad.signer.tokenmanager.token.TokenType)1 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1