Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.