Search in sources :

Example 11 with Item

use of net.minecraft.server.v1_14_R1.DataWatcher.Item in project SilkSpawners by timbru31.

the class NMSHandler method setSpawnersUnstackable.

@Override
public void setSpawnersUnstackable() {
    try {
        final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
        final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
        maxStackSize.setAccessible(true);
        maxStackSize.set(spawner, 1);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_14_R1.Item) Field(java.lang.reflect.Field) MinecraftKey(net.minecraft.server.v1_14_R1.MinecraftKey)

Example 12 with Item

use of net.minecraft.server.v1_14_R1.DataWatcher.Item in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaNBTEntityID.

@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_14_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    tag = tag.getCompound("BlockEntityTag");
    if (tag.hasKey("EntityId")) {
        return tag.getString("EntityId");
    } else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
        return tag.getCompound("SpawnData").getString("id");
    } else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
        return tag.getList("SpawnPotentials", 8).getCompound(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 13 with Item

use of net.minecraft.server.v1_14_R1.DataWatcher.Item in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    String prefixedEntity;
    if (!entity.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entity;
    } else {
        prefixedEntity = entity;
    }
    net.minecraft.server.v1_14_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getOrCreateTag();
    // Check for SilkSpawners key
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    // Check for Vanilla keys
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = tag.getCompound("BlockEntityTag");
    // EntityId - Deprecated in 1.9
    tag.setString("EntityId", entity);
    tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
    // SpawnData
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", prefixedEntity);
    if (!tag.hasKey("SpawnPotentials")) {
        tag.set("SpawnPotentials", new NBTTagCompound());
    }
    // SpawnEgg data
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound)

Example 14 with Item

use of net.minecraft.server.v1_14_R1.DataWatcher.Item in project TheAPI by TheDevTec.

the class v1_14_R1 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_14_R1.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() == Material.AIR || item.getType() == Material.CAVE_AIR)) && (item.getType() == Material.AIR || item.getType() == Material.CAVE_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().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_14_R1.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_14_R1.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack)

Example 15 with Item

use of net.minecraft.server.v1_14_R1.DataWatcher.Item in project Ublisk by Derkades.

the class Sword method getItemStack.

@Override
public ItemStack getItemStack() {
    final Item item = new Item(this.getMaterial()).setName(this.getColoredName()).setLore(this.getLore());
    final NBTTagList modifiers = new NBTTagList();
    final NBTTagCompound damage = new NBTTagCompound();
    damage.setString("AttributeName", "generic.attackDamage");
    damage.setString("Name", "generic.attackDamage");
    damage.setDouble("Amount", this.getDamage());
    damage.setInt("Operation", 1);
    damage.setInt("UUIDLeast", 652);
    damage.setInt("UUIDMost", 12098);
    modifiers.add(damage);
    if (this.getMovementSpeed() != -1) {
        final NBTTagCompound speed = new NBTTagCompound();
        speed.setString("AttributeName", "generic.movementSpeed");
        speed.setString("Name", "generic.movementSpeed");
        speed.setDouble("Amount", this.getMovementSpeed());
        speed.setInt("Operation", 1);
        speed.setInt("UUIDLeast", 652);
        speed.setInt("UUIDMost", 12098);
        modifiers.add(speed);
    }
    if (this.getAttackSpeed().getValue() != -1) {
        final NBTTagCompound attackSpeed = new NBTTagCompound();
        attackSpeed.setString("AttributeName", "generic.attackSpeed");
        attackSpeed.setString("Name", "generic.attackSpeed");
        attackSpeed.setDouble("Amount", this.getAttackSpeed().getValue());
        attackSpeed.setInt("Operation", 1);
        attackSpeed.setInt("UUIDLeast", 652);
        attackSpeed.setInt("UUIDMost", 12098);
        modifiers.add(attackSpeed);
    }
    if (this.getKnockbackResistance() != -1) {
        final NBTTagCompound knockback = new NBTTagCompound();
        knockback.setString("AttributeName", "generic.knockbackResistance");
        knockback.setString("Name", "generic.knockbackResistance");
        knockback.setDouble("Amount", this.getKnockbackResistance());
        knockback.setInt("Operation", 1);
        knockback.setInt("UUIDLeast", 652);
        knockback.setInt("UUIDMost", 12098);
        modifiers.add(knockback);
    }
    final NBTTagCompound compound = item.getNBT();
    compound.set("AttributeModifiers", modifiers);
    compound.setInt("HideFlags", 7);
    compound.setBoolean("Unbreakable", true);
    item.setNBT(compound);
    item.setDamage(this.getDamage());
    return item.getItemStack();
}
Also used : NBTTagList(net.minecraft.server.v1_14_R1.NBTTagList) Item(xyz.derkades.ublisk.utils.inventory.Item) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack)10 NBTTagCompound (net.minecraft.server.v1_14_R1.NBTTagCompound)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 ItemStack (org.bukkit.inventory.ItemStack)4 Container (net.minecraft.server.v1_14_R1.Container)3 CraftPlayer (org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 ContainerAnvil (net.minecraft.server.v1_14_R1.ContainerAnvil)2 EntityPlayer (net.minecraft.server.v1_14_R1.EntityPlayer)2 Item (net.minecraft.server.v1_14_R1.Item)2 ItemStack (net.minecraft.server.v1_14_R1.ItemStack)2 MinecraftKey (net.minecraft.server.v1_14_R1.MinecraftKey)2 Item (net.minecraft.server.v1_16_R2.DataWatcher.Item)2 Item (net.minecraft.server.v1_16_R3.DataWatcher.Item)2 CraftContainer (org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)2