javaminecraftminecraft-fabric

Is it possible to create a potion with multiple effects and put it in a brewing recipe without registering the potion?


I am making a server side only fabric 1.21.1 mod which adds custom potions with vanilla effects. I have been unsuccessful in making the recipe without registering items/potions which cause vanilla players to get kicked on encountering the item and fabric players to be unable to join.

Initially, I tried registering a potion recipe with builder.registerPotionRecipe(), but that takes in RegistryEntry<Potion> and not Potion, which I had created. I then started using builder.registerItemRecipe(), but that lead to the server not starting. Registering the Item or Potion would lead to vanilla clients being kicked whenever encountering the item in game, and fabric players would be unable to join because the client lacks the registry. I did see that the brewing recipe existed as I was able to put the emerald block in the ingredients slot, and the brewing stand started.

    @Override
    public void onInitializeServer() {
        ArrayList<StatusEffectInstance> RICH_POTION_EFFECTS = new ArrayList<>();
        RICH_POTION_EFFECTS.add(new StatusEffectInstance(StatusEffects.HERO_OF_THE_VILLAGE, 480, 5));
        RICH_POTION_EFFECTS.add(new StatusEffectInstance(StatusEffects.LUCK, 480, 3));
        Item RICH_POTION = new Item(new Item.Settings().component(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Optional.empty(),Optional.empty(), RICH_POTION_EFFECTS)));

        Item AWKWARD_POTION = new Item(new Item.Settings().component(DataComponentTypes.POTION_CONTENTS, new PotionContentsComponent(Potions.AWKWARD)));
            FabricBrewingRecipeRegistryBuilder.BUILD.register(builder -> {
                builder.registerItemRecipe(
                        AWKWARD_POTION,
                        Items.EMERALD_BLOCK,
                        RICH_POTION
                );
            });
    }
[17:10:46] [main/ERROR] (Minecraft) Failed to start the minecraft server
 java.lang.IllegalStateException: Some intrusive holders were not registered: [Reference{null=[unregistered]}, Reference{null=[unregistered]}]
    at net.minecraft.registry.SimpleRegistry.freeze(SimpleRegistry.java:359) ~[minecraft-common-c2b31d572c-1.21.1-net.fabricmc.yarn.1_21_1.1.21.1+build.3-v2.jar:?]
    at net.minecraft.registry.Registries.freezeRegistries(Registries.java:264) ~[minecraft-common-c2b31d572c-1.21.1-net.fabricmc.yarn.1_21_1.1.21.1+build.3-v2.jar:?]
    at net.minecraft.registry.Registries.bootstrap(Registries.java:248) ~[minecraft-common-c2b31d572c-1.21.1-net.fabricmc.yarn.1_21_1.1.21.1+build.3-v2.jar:?]
    at net.minecraft.server.Main.handler$zhp000$fabric-registry-sync-v0$afterModInit(Main.java:1547) ~[minecraft-common-c2b31d572c-1.21.1-net.fabricmc.yarn.1_21_1.1.21.1+build.3-v2.jar:?]
    at net.minecraft.server.Main.main(Main.java:111) [minecraft-common-c2b31d572c-1.21.1-net.fabricmc.yarn.1_21_1.1.21.1+build.3-v2.jar:?]
    at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:480) [fabric-loader-0.16.5.jar:?]
    at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) [fabric-loader-0.16.5.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotServer.main(KnotServer.java:23) [fabric-loader-0.16.5.jar:?]
    at net.fabricmc.devlaunchinjector.Main.main(Main.java:86) [dev-launch-injector-0.2.1+build.8.jar:?]

Solution

  • The only way to do it are custom potions here, this will not register the item and will NOT make a brewing recipe. If you want a potion with a brewing recipe it needs to be registered.