Search in sources :

Example 11 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method getItemStackNBTInt.

@Override
public int getItemStackNBTInt(ItemStack itemStack, String key) {
    net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
    return tagCompound.getInt(key);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 12 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method getItemStackNBTString.

@Override
public String getItemStackNBTString(ItemStack itemStack, String key) {
    net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
    return tagCompound.getString(key);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 13 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method setItemStackNBT.

@Override
public ItemStack setItemStackNBT(ItemStack itemStack, String key, String value) {
    net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getOrCreateTag();
    tagCompound.setString(key, value);
    return CraftItemStack.asBukkitCopy(nmsItem);
}
Also used : NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 14 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project BedWars1058 by andrei1058.

the class v1_16_R2 method registerTntWhitelist.

@Override
public void registerTntWhitelist() {
    try {
        Field field = net.minecraft.server.v1_16_R2.BlockBase.class.getDeclaredField("durability");
        field.setAccessible(true);
        field.set(Blocks.END_STONE, 12f);
        field.set(Blocks.GLASS, 300f);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) net.minecraft.server.v1_16_R2(net.minecraft.server.v1_16_R2)

Example 15 with net.minecraft.server.v1_16_R2

use of net.minecraft.server.v1_16_R2 in project TheAPI by TheDevTec.

the class v1_16_R2 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.c();
    if (slot == -999)
        return false;
    int id = packet.b();
    int mouseClick = packet.d();
    net.minecraft.server.v1_16_R2.InventoryClickType nmsType = packet.g();
    InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.f());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType().isAir()) && item.getType().isAir())
        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().getStorageContents() : gui.getInventory().getStorageContents();
        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().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(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).shiftClick((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_16_R2.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_16_R2.PacketPlayInWindowClick) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)11 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)9 ItemStack (org.bukkit.inventory.ItemStack)7 CraftChunk (org.bukkit.craftbukkit.v1_16_R2.CraftChunk)4 Container (net.minecraft.server.v1_16_R2.Container)3 EntityPlayer (net.minecraft.server.v1_16_R2.EntityPlayer)3 Chunk (org.bukkit.Chunk)3 CraftPlayer (org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)3 CraftContainer (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 Pair (com.mojang.datafixers.util.Pair)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 net.minecraft.server.v1_16_R2 (net.minecraft.server.v1_16_R2)2 BlockPosition (net.minecraft.server.v1_16_R2.BlockPosition)2 ChunkSection (net.minecraft.server.v1_16_R2.ChunkSection)2 ContainerAnvil (net.minecraft.server.v1_16_R2.ContainerAnvil)2 EnumItemSlot (net.minecraft.server.v1_16_R2.EnumItemSlot)2 PacketPlayOutEntityEquipment (net.minecraft.server.v1_16_R2.PacketPlayOutEntityEquipment)2 Material (org.bukkit.Material)2