Jump to content

[1.16.3] How to create a custom potion with a custom effect?


Recommended Posts

Posted

Hello,

 

I tried to create a custom potion with a custom effect and looked at the vanilla code. Someone on YouTube also tried that and used invoke to make a private method accessable. Here is the code:

	private static void addMix(Potion start, Item ingredient, Potion result) {
		if(brewing_mixes == null) {
			brewing_mixes = ObfuscationReflectionHelper.findMethod(PotionBrewing.class, "addMix", Potion.class, Item.class, Potion.class);
			brewing_mixes.setAccessible(true);
		}
		try {
			brewing_mixes.invoke(null, start, ingredient, result);
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
		} 
	}
	
	public static void addBrewingRecipes() {
		addMix(Potions.AWKWARD, ItemList.nectar, PotionList.love_potion);
	}
	
	public static class ModEffect extends Effect{

		public ModEffect(EffectType typeIn, int liquidColorIn) {
			super(typeIn, liquidColorIn);
		}
		
	}

The addBrewingRecipes() method get's called during the FMLCommonSetupEvent.

But there is something wrong with it, because the invoke method throws an InvocationTargetException. So I guess I need to try it differently. Could someone please give me a hint where I have to start? :) 

 

Thanks in advance and stay healthy.

Posted
  On 10/13/2020 at 7:35 AM, diesieben07 said:

PotionUtils.addPotionToItemStack

Expand  

Okay, that helps - thank you. I only have one problem left: register the potion and the effect the right way. Here is what I've done:

	public static void init (){
		EFFECTS.register(FMLJavaModLoadingContext.get().getModEventBus());
		POTIONS.register(FMLJavaModLoadingContext.get().getModEventBus());
		PotionList.addBrewingRecipes();
	}

	
	public static void addBrewingRecipes() {
		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(ItemStack.EMPTY, Potions.AWKWARD)), Ingredient.fromStacks(new ItemStack(ItemList.nectar)), PotionUtils.addPotionToItemStack(ItemStack.EMPTY, PotionList.LOVE.get()));
	}
	
	public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, DeepAffection.modid);
	public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, DeepAffection.modid);
	
	//Effects
	public static final RegistryObject<Effect> LOVE_EFFECT = EFFECTS.register("love", () -> new ModEffect(EffectType.BENEFICIAL, 0xc98fff).addAttributesModifier(Attributes.field_233821_d_, "55FCED67-E92A-486E-9800-B47F202C4386", (double)0.34F, AttributeModifier.Operation.MULTIPLY_TOTAL));
	
	//Potions
	public static final RegistryObject<Potion> LOVE = POTIONS.register("love", () -> new Potion(new EffectInstance(PotionList.LOVE_EFFECT.get(), 3600)));

When I start the game, I get a NullPointerException because the registry object deepaffection:love is not present. The init() method get's during the instantiation of DeepAffection.

 

Could you please tell me what I did wrong? :)

 

Posted
  On 10/18/2020 at 1:00 PM, diesieben07 said:

Use FMLCommonSetupEvent to register the recipes. Note that BrewingRecipeRegistry is not threadsafe, so you have to use enqueueWork.

Expand  

Okay, now I did this:

	public static void init (){
		EFFECTS.register(FMLJavaModLoadingContext.get().getModEventBus());
		POTIONS.register(FMLJavaModLoadingContext.get().getModEventBus());
	}

	
	public static void addBrewingRecipes(FMLCommonSetupEvent event) {
		System.out.println("PotionList: Brewing Recipes called.");
		event.enqueueWork( () -> {
		BrewingRecipeRegistry.addRecipe(Ingredient.fromStacks(PotionUtils.addPotionToItemStack(ItemStack.EMPTY, Potions.AWKWARD)), Ingredient.fromStacks(new ItemStack(ItemList.nectar)), PotionUtils.addPotionToItemStack(ItemStack.EMPTY, PotionList.LOVE.get()));
		} );
	}
	
	public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, DeepAffection.modid);
	public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, DeepAffection.modid);
	
	//Effects
	public static final RegistryObject<Effect> LOVE_EFFECT = EFFECTS.register("love_effect", () -> new ModEffect(EffectType.BENEFICIAL, 13209599)
			.addAttributesModifier(Attributes.field_233821_d_, "55FCED67-E92A-486E-9800-B47F202C4386", (double)0.34F, AttributeModifier.Operation.MULTIPLY_TOTAL)
			.addAttributesModifier(Attributes.field_233825_h_,"AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3", (double)0.17F, AttributeModifier.Operation.MULTIPLY_TOTAL)
			.addAttributesModifier(Attributes.field_233818_a_, "5D6F0BA2-1186-46AC-B896-C61C5CEE99CC", 10.0D, AttributeModifier.Operation.ADDITION)
			.addAttributesModifier(Attributes.field_233828_k_, "03C3C89D-7037-4B42-869F-B146BCB64D2E", 1.0D, AttributeModifier.Operation.ADDITION));
	
	//Potions
	public static final RegistryObject<Potion> LOVE = POTIONS.register("love", () -> new Potion(new EffectInstance(PotionList.LOVE_EFFECT.get(), 6000)));

My potion works now, but I can't brew it yet. Did I do something wrong with the enqueueWork?

Posted
  On 10/21/2020 at 10:37 AM, diesieben07 said:

You are adding potions to the empty ItemStack (or trying to, rather). You need to create a new ItemStack of Items.POTION.

Expand  

Ah okay, I didn't know what exactly to use there. Thank you very much, it works now! :) 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my game keeps crashing right before launching the game before full screen and keeps poping up this error message "error code 1 " The game crashed: rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @d919544; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @d919544)
    • removing oculus or any of ETF or EMF or even embeddium doesn't change anything it just crashes again with error -1  https://gist.github.com/Tikalian-coconut/d49e8fb83bf57d5e04eb042522046786 this time i removed all 4 at same time and that gave it something is wrong with the game seriously..
    • crash report -> https://gist.github.com/Tikalian-coconut/18c41f97bdacef54725e5141f57697d7 from what i see it seems like Entity Texture Features doesn't like Oculus doing something or invert.. not sure it's why everything is all black textured but that causes a -1 error
    • well that's bad, cuz there's no crash report at all (the last crash report is from previous replies) it's probably another issue that doesn't fit in this bug report, the game works fine except that everything is black, no texture except the sky and skin, everything else is just black i've tried reloading the textures in game, see for drivers updates but it did nothing, seems like an issue with Embeddium or Oculus i think, but i know nothing compared to you i can still send the latest debug and latest.log files.. edit: it seems that when i re-add rechiseled (1.1.6-1.20.1) it crashes as error 1 (i can't remove it off from the modpack cuz that'll break all my builds on some maps) lemme start the game and get it to crash to get a crash report done)
    • If you've fallen victim to a crypto scam, you're not alone and thankfully, you're not without options. I highly recommend iBolt Cyber Hacker Company for anyone seeking professional and effective assistance in recovering scammed cryptocurrency. After extensive research and hearing from multiple satisfied clients, it's clear that iBolt stands out in a crowded and often unreliable market. Their team of experienced cyber experts and blockchain analysts uses advanced tracking techniques to follow stolen funds across the blockchain and engage with crypto exchanges when possible. They’re not just tech-savvy—they’re strategic and persistent. WHY CHOOSE iBOLT CYBER HACKER COMPANY? (1) Proven success in crypto asset recovery (2) Fast, professional, and discreet service (3) Skilled in blockchain forensics and cyber investigation (4) Committed to fighting online fraud and supporting victims Don’t give up. I strongly recommend reaching out to iBolt Cyber Hacker Company. ENQUIRIES: info @ iboltcyberhack . org/ www . iboltcyberhack. org/ +39. 351. 105. 3619.
  • Topics

×
×
  • Create New...

Important Information

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