Jump to content

[1.19.2] Loading loot modifier causes NullPointerException


Recommended Posts

Posted

Currently trying to edit the loot modifier for oak leaves. I'm fairly certain I have everything set up correctly and I checked for spelling errors in all the JSONs, but to no avail. Here is the error:

[22:32:19] [Render thread/ERROR] [ne.mi.co.lo.LootModifierManager/]: Couldn't parse loot modifier storange:oak_leaves_orange
java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.loot.GlobalLootModifierSerializer.read(net.minecraft.resources.ResourceLocation, com.google.gson.JsonObject, net.minecraft.world.level.storage.loot.predicates.LootItemCondition[])" because the return value of "net.minecraftforge.registries.IForgeRegistry.getValue(net.minecraft.resources.ResourceLocation)" is null
	at net.minecraftforge.common.loot.LootModifierManager.deserializeModifier(LootModifierManager.java:119) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2387%2394!/:?] {re:classloading}
	at net.minecraftforge.common.loot.LootModifierManager.lambda$apply$0(LootModifierManager.java:101) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2387%2394!/:?] {re:classloading}
	at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {}
	at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:99) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2387%2394!/:?] {re:classloading}
	at net.minecraftforge.common.loot.LootModifierManager.apply(LootModifierManager.java:40) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2387%2394!/:?] {re:classloading}
	at net.minecraft.server.packs.resources.SimplePreparableReloadListener.lambda$reload$1(SimplePreparableReloadListener.java:12) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading}
	at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718) ~[?:?] {}
	at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:482) ~[?:?] {}
	at net.minecraft.server.packs.resources.SimpleReloadInstance.lambda$new$3(SimpleReloadInstance.java:65) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading}
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:143) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:22) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading}
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:116) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:126) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.Minecraft.makeWorldStem(Minecraft.java:2082) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.doLoadLevel(Minecraft.java:1909) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.loadLevel(Minecraft.java:1873) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.loadWorld(WorldSelectionList.java:473) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.joinWorld(WorldSelectionList.java:330) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.WorldSelectionList$WorldListEntry.mouseClicked(WorldSelectionList.java:257) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.AbstractSelectionList.mouseClicked(AbstractSelectionList.java:323) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.events.ContainerEventHandler.mouseClicked(ContainerEventHandler.java:28) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.lambda$onPress$0(MouseHandler.java:88) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.wrapScreenError(Screen.java:528) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.onPress(MouseHandler.java:85) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.lambda$setup$4(MouseHandler.java:185) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.thread.BlockableEventLoop.execute(BlockableEventLoop.java:90) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.MouseHandler.lambda$setup$5(MouseHandler.java:184) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36) ~[lwjgl-glfw-3.2.2.jar%2366!/:build 10] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.2.2.jar%2372!/:build 10] {}
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101) ~[lwjgl-glfw-3.2.2.jar%2366!/:build 10] {}
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:168) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at com.mojang.blaze3d.platform.Window.updateDisplay(Window.java:333) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1068) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:665) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:205) ~[forge-1.18.2-40.1.84_mapped_official_1.18.2-recomp.jar%2388!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:24) ~[fmlloader-1.18.2-40.1.84.jar%239!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%2320!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {}

 

Here is the modifier class:

package avals.storange.loot;

import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.loot.LootModifier;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class OakLeavesOrangeModifier extends LootModifier {
    private final Item orangeItem;

    protected OakLeavesOrangeModifier(LootItemCondition[] conditionsIn, Item orangeItem) {
        super(conditionsIn);
        this.orangeItem = orangeItem;
    }

    @NotNull
    @Override
    protected List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
        if(context.getRandom().nextFloat() > 0.75) {
            generatedLoot.add(new ItemStack(orangeItem));
        }
        return null;
    }

    public static class Serializer extends GlobalLootModifierSerializer<OakLeavesOrangeModifier> {

        @Override
        public OakLeavesOrangeModifier read(ResourceLocation location, JsonObject object, LootItemCondition[] ailootcondition) {
            Item orangeItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(GsonHelper.getAsString(object, "orangeItem")));
            return new OakLeavesOrangeModifier(ailootcondition, orangeItem);
        }

        @Override
        public JsonObject write(OakLeavesOrangeModifier instance) {
            JsonObject json = makeConditions(instance.conditions);
            json.addProperty("orangeItem", ForgeRegistries.ITEMS.getKey(instance.orangeItem).toString());
            return json;
        }
    }
}

Events class:

package avals.storange.event;

import avals.storange.Storange;
import avals.storange.loot.OakLeavesOrangeModifier;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = Storange.ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModWorldEvents {
    @SubscribeEvent
    public static void registerModifierSerializers(@Nonnull final RegistryEvent.Register<GlobalLootModifierSerializer<?>> event) {
        event.getRegistry().registerAll(
                new OakLeavesOrangeModifier.Serializer().setRegistryName(new ResourceLocation(Storange.ID, "oak_leaves_orange"))
        );
    }
}

Loot modifier JSON:

{
  "conditions": [
    {
      "condition": "minecraft:inverted",
      "term": {
        "condition": "minecraft:match_tool",
        "predicate": {
          "item": "minecraft:shears"
        }
      }
    },
    {
      "condition": "minecraft:inverted",
      "term": {
        "condition": "minecraft:match_tool",
        "predicate": {
          "enchantments": [
            {
              "enchantment": "minecraft:silk_touch"
            }
          ]
        }
      }
    },
    {
      "condition": "minecraft:block_state_property",
      "block": "minecraft:oak_leaves"
    }
  ],
  "orangeItem": "storange:orange",
  "type": "storange:oak_leaves_orange"
}

Global Loot Modifiers:

{
  "replace": "false",
  "entries": [
    "storange:oak_leaves_orange"
  ]
}

Thank you!

Posted
Quote

[22:32:19] [Render thread/ERROR] [ne.mi.co.lo.LootModifierManager/]: Couldn't parse loot modifier storange:oak_leaves_orange java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.loot.GlobalLootModifierSerializer.read(net.minecraft.resources.ResourceLocation, com.google.gson.JsonObject, net.minecraft.world.level.storage.loot.predicates.LootItemCondition[])" because the return value of "net.minecraftforge.registries.IForgeRegistry.getValue(net.minecraft.resources.ResourceLocation)" is null

The error says your GLM is not registered.

When it tries to get the value from the registry with than name it is null.

You should check your registration code is actually invoked and you also don't have a typo somewhere with the name.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.