Jump to content

[1.12.2] Add a custom shapeless crafting recipe using code involving potions


lukas2005

Recommended Posts

i have a custom bat wing item and i want to add 2 shapeless crafting recipes that uses it on is bat wing + water bottle = poison potion and another is bat wing + dragon breath = splash levitation potion

i have this code:

public static void init() {
        addShapelessRecipe(new ItemStack(Items.POTIONITEM, 1, 8260), ModItems.getItem("bat_wing"), Items.POTIONITEM);

        NBTTagCompound levitationPotionNbt = new NBTTagCompound();
        NBTTagCompound displayNBT = new NBTTagCompound();
        NBTTagList customEffectsList = new NBTTagList();
        NBTTagCompound potionNbt = new NBTTagCompound();
        potionNbt.setInteger("Id", 25);
        potionNbt.setInteger("Amplifier", 1);
        potionNbt.setInteger("Duration", 600); // 600 = (0:30) 1800 = (1:30)
        customEffectsList.set(0, potionNbt);
        levitationPotionNbt.setTag("CustomPotionEffects", customEffectsList);
        displayNBT.setString("Name", "Splash Potion of Levitation");
        levitationPotionNbt.setTag("display", displayNBT);


        addShapelessRecipe(new ItemStack(Items.POTIONITEM, 1, 0, levitationPotionNbt), ModItems.getItem("bat_wing"), Items.DRAGON_BREATH);
    }

    public static void addShapedRecipe(ItemStack output, Object...shape) {
        GameRegistry.addShapedRecipe(new ResourceLocation(Reference.MOD_ID, output.getItem().getRegistryName().getResourcePath()+"_recipe"), null, output, shape);
    }

    public static void addShapelessRecipe(ItemStack output, Item...items) {
        Ingredient[] ingredients = new Ingredient[items.length];
        for (int i = 0; i < ingredients.length; i++) ingredients[i] = Ingredient.fromItem(items[i]);
      

(init is called in a item register event after registering all the mod items)

recipes are not added properly the first one does not works completly and the second one gives me a uncraftable potion with no effects

Link to comment
Share on other sites

The NBT constructor is for capability NBT, it is not the same as the ItemStack's stackTagCompound field.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The ItemStack(Item, int, int, NBTTagCompound) constructor doesn't do what you think it does. The NBTTagCompound argument is for the serialised capability data, not the ItemStack's compound tag.

 

Use one of the constructors without an NBTTagCompound argument and then use ItemStack#setTagCompound to set the ItemStack's compound tag.

 

You shouldn't be manually creating the potion NBT anyway. If the effects you want already have a PotionType, use PotionUtils.addPotionToItemStack to add that to the potion ItemStack. If the effects don't have a PotionType (and you don't want to create one for them), use PotionUtils.appendEffects to add them to the potion ItemStack instead.

 

If you want a splash potion, use Items.SPLASH_POTION instead of Items.POTIONITEM.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.