Jump to content

Recommended Posts

Posted

I followed a tutorial on how to make custom potions for a minecraft mod, however, this was before deferred registries were used frequently. So I pieced together things from regular registries and deferred registries, however, I am having trouble. All but one of my custom recipes that use the Awkward Potion as a base results in an uncraftable potion, even though I can see, obtain, and use my custom potions from the creative tabs. The recipes that use my custom potions don't work at all.

 

I think this is all because of the way I inputted my custom potions into the recipes, because the one recipe that uses all vanilla items works fine (an awkward potion and an emerald, creating a Potion of Luck). Am I missing something? Am I way off as to where the problem lies?

My main class:

package com.oberonpuck.minormagicks;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.oberonpuck.minormagicks.util.ItemRegistryHandler;
import com.oberonpuck.minormagicks.util.PotionRegistryHandler;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("minormagicks")
public class MinorMagicks
{
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "minormagicks";
    public MinorMagicks() 
    {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
       
        ItemRegistryHandler.init();
        PotionRegistryHandler.init();
        MinecraftForge.EVENT_BUS.register(this);
    }
    private void setup(final FMLCommonSetupEvent event){}
    private void doClientStuff(final FMLClientSetupEvent event){}
}

 

My potion class for registering potions and recipes:

package com.oberonpuck.minormagicks.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Supplier;
import com.oberonpuck.minormagicks.MinorMagicks;
import com.oberonpuck.minormagicks.items.ItemBase;

import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.EffectType;
import net.minecraft.potion.Effects;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionBrewing;
import net.minecraft.potion.Potions;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;
public class PotionRegistryHandler
{
	public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, MinorMagicks.MOD_ID);
	public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, MinorMagicks.MOD_ID);
	public static void init ()
	{
		POTIONS.register(FMLJavaModLoadingContext.get().getModEventBus());
		PotionRegistryHandler.addBrewingRecipes();
	}
	//Potions
	public static final RegistryObject<Potion> HUNGER = POTIONS.register("hunger", () -> new Potion(new EffectInstance(Effects.HUNGER, 3600)));
	public static final RegistryObject<Potion> RESISTANCE = POTIONS.register("resistance", () -> new Potion(new EffectInstance(Effects.RESISTANCE, 3600)));
	public static final RegistryObject<Potion> ABSORPTION = POTIONS.register("absorption", () -> new Potion(new EffectInstance(Effects.ABSORPTION, 3600)));
	public static final RegistryObject<Potion> HEALTH_BOOST = POTIONS.register("health_boost", () -> new Potion(new EffectInstance(Effects.HEALTH_BOOST, 3600)));
	public static final RegistryObject<Potion> HASTE = POTIONS.register("haste", () -> new Potion(new EffectInstance(Effects.HASTE, 3600)));
	public static final RegistryObject<Potion> MINING_FATIGUE = POTIONS.register("mining_fatigue", () -> new Potion(new EffectInstance(Effects.MINING_FATIGUE, 3600)));
	public static final RegistryObject<Potion> NASUEA = POTIONS.register("nausea", () -> new Potion(new EffectInstance(Effects.NAUSEA, 3600)));
	public static final RegistryObject<Potion> BLINDNESS = POTIONS.register("blindness", () -> new Potion(new EffectInstance(Effects.BLINDNESS, 3600)));
	public static final RegistryObject<Potion> GLOWING = POTIONS.register("glowing", () -> new Potion(new EffectInstance(Effects.GLOWING, 3600)));
	public static final RegistryObject<Potion> LEVITATION = POTIONS.register("levitation", () -> new Potion(new EffectInstance(Effects.LEVITATION, 3600)));
	public static final RegistryObject<Potion> DOLPHINS_GRACE = POTIONS.register("dolphins_grace", () -> new Potion(new EffectInstance(Effects.DOLPHINS_GRACE, 3600)));
	public static final RegistryObject<Potion> UNLUCK = POTIONS.register("unluck", () -> new Potion(new EffectInstance(Effects.UNLUCK, 3600)));
	
	private static Method brewing_mixes;
	
	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) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	static ResourceLocation nausea = new ResourceLocation("minormagicks:nausea");
	static ResourceLocation hunger = new ResourceLocation("minormagicks:hunger");
	static ResourceLocation unluck = new ResourceLocation("minormagicks:unluck");
	static ResourceLocation dolphins_grace = new ResourceLocation("minormagicks:dolphins_grace");
	static ResourceLocation resistance = new ResourceLocation("minormagicks:resistance");
	static ResourceLocation health_boost = new ResourceLocation("minormagicks:health_boost");
	static ResourceLocation haste = new ResourceLocation("minormagicks:haste");
	static ResourceLocation mining_fatigue = new ResourceLocation("minormagicks:mining_fatigue");
	static ResourceLocation absorption = new ResourceLocation("minormagicks:absorption");
	static ResourceLocation levitation = new ResourceLocation("minormagicks:levitation");
	
	public static void addBrewingRecipes()
	{
		addMix(Potions.AWKWARD, Items.ROTTEN_FLESH, ForgeRegistries.POTION_TYPES.getValue(nausea));
		addMix(ForgeRegistries.POTION_TYPES.getValue(nausea), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(hunger));
		addMix(Potions.AWKWARD, Items.EMERALD, Potions.LUCK);
		addMix(Potions.LUCK, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(unluck));
		addMix(Potions.WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(dolphins_grace));
		addMix(Potions.AWKWARD, Items.SHULKER_SHELL, ForgeRegistries.POTION_TYPES.getValue(resistance));
		addMix(ForgeRegistries.POTION_TYPES.getValue(resistance), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(health_boost));
		addMix(Potions.AWKWARD, Items.PRISMARINE_CRYSTALS, ForgeRegistries.POTION_TYPES.getValue(haste));
		addMix(ForgeRegistries.POTION_TYPES.getValue(haste), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(mining_fatigue));
		addMix(Potions.FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(absorption));
		addMix(Potions.SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(levitation));
	}
}

 

Posted (edited)

First of all, don't reference FMLJavaModLoadingContext directly from that class, put it as a parameter in the PotionRegistryHandler#init method, second of all, you never even register your potions by calling EFFECTS#register, and lastly, your DeferredRegisters have their names mixed up, the first one is for effects and the second one is for potions.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted
On 7/14/2020 at 5:28 AM, Novârch said:

First of all, don't reference FMLJavaModLoadingContext directly from that class, put it as a parameter in the PotionRegistryHandler#init method, second of all, you never even register your potions by calling EFFECTS#register, and lastly, your DeferredRegisters have their names mixed up, the first one is for effects and the second one is for potions.

Well, it turns out that problem was not that at all. I just needed to use the RegistryObjects of my new potions and then add ".get()" and use those for the recipes, instead of the ResourceLocations:

public static void addBrewingRecipes()
	{
		addMix(Potions.AWKWARD, Items.ROTTEN_FLESH, PotionRegistryHandler.NASUEA.get());
		addMix(PotionRegistryHandler.NASUEA.get(), Items.REDSTONE, PotionRegistryHandler.LONG_NASUEA.get());
		addMix(PotionRegistryHandler.NASUEA.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.HUNGER.get());
		addMix(PotionRegistryHandler.LONG_NASUEA.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_HUNGER.get());
		addMix(Potions.AWKWARD, Items.EMERALD, Potions.LUCK);
		addMix(Potions.LUCK, Items.REDSTONE, PotionRegistryHandler.LONG_LUCK.get());
		addMix(Potions.LUCK, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.UNLUCK.get());
		addMix(PotionRegistryHandler.LONG_LUCK.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_UNLUCK.get());
		addMix(Potions.WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.DOLPHINS_GRACE.get());
		addMix(Potions.LONG_WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_DOLPHINS_GRACE.get());
		addMix(Potions.AWKWARD, Items.SHULKER_SHELL, PotionRegistryHandler.RESISTANCE.get());
		addMix(PotionRegistryHandler.RESISTANCE.get(), Items.REDSTONE, PotionRegistryHandler.LONG_RESISTANCE.get());
		addMix(PotionRegistryHandler.RESISTANCE.get(), Items.GLOWSTONE, PotionRegistryHandler.STRONG_RESISTANCE.get());
		addMix(PotionRegistryHandler.RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.HEALTH_BOOST.get());
		addMix(PotionRegistryHandler.LONG_RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_HEALTH_BOOST.get());
		addMix(PotionRegistryHandler.STRONG_RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.STRONG_HEALTH_BOOST.get());
		addMix(Potions.AWKWARD, Items.PRISMARINE_CRYSTALS, PotionRegistryHandler.HASTE.get());
		addMix(PotionRegistryHandler.HASTE.get(), Items.REDSTONE, PotionRegistryHandler.LONG_HASTE.get());
		addMix(PotionRegistryHandler.HASTE.get(), Items.GLOWSTONE, PotionRegistryHandler.STRONG_HASTE.get());
		addMix(PotionRegistryHandler.HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.MINING_FATIGUE.get());
		addMix(PotionRegistryHandler.LONG_HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_MINING_FATIGUE.get());
		addMix(PotionRegistryHandler.STRONG_HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.STRONG_MINING_FATIGUE.get());
		addMix(Potions.FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.ABSORPTION.get());
		addMix(Potions.LONG_FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_ABSORPTION.get());
		addMix(Potions.SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LEVITATION.get());
		addMix(Potions.LONG_SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_LEVITATION.get());
		addMix(Potions.AWKWARD, Items.ENDER_EYE, PotionRegistryHandler.GLOWING.get());
		addMix(PotionRegistryHandler.GLOWING.get(), Items.REDSTONE, PotionRegistryHandler.LONG_GLOWING.get());
		addMix(PotionRegistryHandler.GLOWING.get(), Items.FERMENTED_SPIDER_EYE, Potions.INVISIBILITY);
		addMix(PotionRegistryHandler.LONG_GLOWING.get(), Items.FERMENTED_SPIDER_EYE, Potions.LONG_INVISIBILITY);
	}

 

Posted

image.png.eea945875ed4f75391ce8416ba9d919b.png

These do basically the same thing (if you had marked the methods with the @SubscribeEvent annotation, they actually would; as is the EVENT_BUS.register call does nothing).

But its largely pointless, because those event methods are empty anyway.

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.

Posted
On 7/14/2020 at 12:11 AM, OberonPuck said:

ObfuscationReflectionHelper

Brewing recipes are hooked in via BrewingRecipeRegistry::addRecipe. Also, are you seriously calling the brewing recipes in your constructor before the potions are even registered? This should be done within FMLCommonSetupEvent surrounded by a DeferredWorkQueue.

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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
  • Topics

×
×
  • Create New...

Important Information

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