Anyway to set a persistent data container on the craft of an item?

Discussion in 'Plugin Development' started by man_in_matrix, Jan 7, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    man_in_matrix

    Hello!
    I'm trying to make items with custom stats and was wondering if there was a way to set a persistent data container in the item's recipe


    Code:
          public static ShapedRecipe buildTerminator() {
        ItemStack terminator = new ItemStack(Material.BOW);
        terminator.addEnchantment(Enchantment.ARROW_INFINITE, 1);
        ItemMeta terminatorMeta = terminator.getItemMeta();
        terminatorMeta.setDisplayName(ChatColor.GOLD + "Terminator");
       
        terminatorMeta.setLore(Arrays.asList(
                ChatColor.GRAY + "Gear Score: " + ChatColor.LIGHT_PURPLE + "665",
                ChatColor.GRAY + "Item Quality " + ChatColor.LIGHT_PURPLE + "100%",
                ChatColor.GRAY + "Damage: " + ChatColor.RED + "+" + ChatColor.RED + "335",
                ChatColor.GRAY + "Strength: " + ChatColor.RED + "+" + ChatColor.RED + "50",
                ChatColor.GRAY + "Crit Damage: " + ChatColor.RED + "+" + ChatColor.RED + "250" + ChatColor.RED + "%",
                ChatColor.GRAY + "Bonus Attack Speed: " + ChatColor.RED + "+" + ChatColor.RED + "40" + ChatColor.RED + "%",
                ChatColor.GRAY + "",
                ChatColor.GOLD + "Shortbow: Instantly shoots!",
                ChatColor.GRAY + "Shoots " + ChatColor.AQUA + "3 " + ChatColor.GRAY + "arrows at once.",
                ChatColor.GRAY + "Can damage enderman",
                ChatColor.GRAY + "",
                ChatColor.RED + "Divides your " + ChatColor.BLUE + "☣ Crit Chance " + ChatColor.RED + "by 4!",
                ChatColor.GRAY + "",
                ChatColor.GOLD + "Ability: Salvation " + ChatColor.YELLOW + ChatColor.BOLD + "RIGHT CLICK",
                ChatColor.GRAY + "Can be casted after landing " + ChatColor.GOLD + "3 " + ChatColor.GRAY + "hits.",
                ChatColor.GRAY + "Shoot a beam, penetrating up",
                ChatColor.GRAY + "to " + ChatColor.YELLOW + "5 " + ChatColor.GRAY + "foes and dealing " + ChatColor.RED + "2x",
                ChatColor.GRAY + "the damage an arrow would.",
                ChatColor.GRAY + "The beam always crits.",
                ChatColor.DARK_GRAY + "Soulflow Cost " + ChatColor.DARK_AQUA + "1 ⸎",
                ChatColor.DARK_GRAY + "Cooldown: " + ChatColor.GREEN + "2s",
                ChatColor.GRAY + "",
                ChatColor.DARK_GRAY + "This item can be reforged!",
                ChatColor.DARK_RED + "☠" + ChatColor.RED + "Requires " + ChatColor.DARK_PURPLE + "Enderman Slayer 7",
                ChatColor.GOLD + "" + ChatColor.BOLD + "LEGENDARY BOW" ));
       
      
       
        terminatorMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        NamespacedKey damage = new NamespacedKey(Main.getPlugin(Main.class), "damage");
        NamespacedKey strength = new NamespacedKey(Main.getPlugin(Main.class), "strength");
        NamespacedKey intelligence = new NamespacedKey(Main.getPlugin(Main.class), "intelligence");
        NamespacedKey ferocity = new NamespacedKey(Main.getPlugin(Main.class), "ferocity");
        NamespacedKey cDmg = new NamespacedKey(Main.getPlugin(Main.class), "cDmg");
        NamespacedKey cChance = new NamespacedKey(Main.getPlugin(Main.class), "cChance");
        NamespacedKey attackSpeed = new NamespacedKey(Main.getPlugin(Main.class), "attackSpeed");
       
       
       
        ItemMeta itemMeta = terminator.getItemMeta();
        itemMeta.getPersistentDataContainer().set(damage, PersistentDataType.INTEGER, 335);
        itemMeta.getPersistentDataContainer().set(strength, PersistentDataType.INTEGER, 50);
        itemMeta.getPersistentDataContainer().set(intelligence, PersistentDataType.INTEGER, 0);
        itemMeta.getPersistentDataContainer().set(ferocity, PersistentDataType.INTEGER, 0);
        itemMeta.getPersistentDataContainer().set(cDmg, PersistentDataType.INTEGER, 250);
        itemMeta.getPersistentDataContainer().set(cChance, PersistentDataType.INTEGER, 0);
        itemMeta.getPersistentDataContainer().set(attackSpeed, PersistentDataType.INTEGER, 40);
        terminator.setItemMeta(terminatorMeta);
        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(Main.plugin, "Terminator_Bow"), terminator);
        recipe.shape( " ES", "EBS", " ES" );
        recipe.setIngredient('E', Material.ENDER_PEARL);
        recipe.setIngredient('S', Material.STRING);
        recipe.setIngredient('B', Material.BOW);
       
       
        return recipe;
      }
    Any suggestions would be greatly appreciated.
     
  2. Offline

    Strahan

    Alas, no, you can't make PDC settings automatically. But all you have to do is watch for it being crafted then apply them at that time. I'd get away from so much hard coding if I were you; best to leave all that in config so it can be dynamic.
     
Thread Status:
Not open for further replies.

Share This Page