illusivesoulworks / diet

Other
19 stars 16 forks source link

[Bug]: Cannot invoke "java.lang.Float.floatValue()" because the return value of "java.util.Map.get(Object)" is null #195

Open Ximu-Luya opened 5 months ago

Ximu-Luya commented 5 months ago

Minecraft Version

1.20.1

What happened?

The game crashed after I ate an apple

The crash log shows that this mod caused the crash

It is also possible that the crash is not caused by mod code, but my datapack configuration problem, please correct

How do you trigger this bug?

The following is the datapack:

  1. data\diet\diet\groups\vitamin.json
    {
    "icon": "minecraft:apple",
    "color": "#36ecd5",
    "order": 4,
    "default_value": 0.35,
    "gain_multiplier": 3.0,
    "decay_multiplier": 1.5,
    "beneficial": true
    }
  2. data\diet\tags\items\vitamin.json
    {
    "replace":true,
    "values": [
    {
      "id": "minecraft:apple",
      "required": false
    },
    ...
    ]
    }

I thought it was configured correctly.

Loader

Forge

Loader Version

Forge 47.3.1

API Version

No response

Mod Version

diet-forge-2.1.1+1.20.1

Relevant Log Outputs

java.lang.NullPointerException: Cannot invoke "java.lang.Float.floatValue()" because the return value of "java.util.Map.get(Object)" is null
    at com.illusivesoulworks.diet.common.capability.PlayerDietTracker.apply(PlayerDietTracker.java:340) ~[%5B均衡饮食%5D%20diet-forge-2.1.1+1.20.1.jar%23306!/:2.1.1+1.20.1] {re:classloading}
    at com.illusivesoulworks.diet.common.capability.PlayerDietTracker.consume(PlayerDietTracker.java:177) ~[%5B均衡饮食%5D%20diet-forge-2.1.1+1.20.1.jar%23306!/:2.1.1+1.20.1] {re:classloading}
    at com.illusivesoulworks.diet.common.capability.DietCapabilityEventsListener.lambda$finishItemUse$2(DietCapabilityEventsListener.java:118) ~[%5B均衡饮食%5D%20diet-forge-2.1.1+1.20.1.jar%23306!/:2.1.1+1.20.1] {re:classloading}
    at net.minecraftforge.common.util.LazyOptional.ifPresent(LazyOptional.java:137) ~[forge-1.20.1-47.3.1-universal.jar%23387!/:?] {re:mixin,re:classloading}
    at com.illusivesoulworks.diet.common.capability.DietCapabilityEventsListener.finishItemUse(DietCapabilityEventsListener.java:118) ~[%5B均衡饮食%5D%20diet-forge-2.1.1+1.20.1.jar%23306!/:2.1.1+1.20.1] {re:classloading}
    at com.illusivesoulworks.diet.common.capability.__DietCapabilityEventsListener_finishItemUse_Finish.invoke(.dynamic) ~[%5B均衡饮食%5D%20diet-forge-2.1.1+1.20.1.jar%23306!/:2.1.1+1.20.1] {re:classloading,pl:eventbus:B}
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%23137!/:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%23137!/:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%23137!/:?] {}
    at net.minecraftforge.event.ForgeEventFactory.onItemUseFinish(ForgeEventFactory.java:396) ~[forge-1.20.1-47.3.1-universal.jar%23387!/:?] {re:classloading}
...
Ximu-Luya commented 5 months ago

I used the exclusion method to think about the difference between before and after the datapack modification.

The exception seems to have occurred after I removed the default food group configuration (e.g. fruit.json, vegetables.json) under the tag/items/ directory.

I added them back and no more crashes.

I can play normally now, but I hope this information will help you troubleshoot the problem, or explain why I can't remove the default configuration e.g. fruit.json.