TerraFirmaCraft

TerraFirmaCraft

2M Downloads

[Crash] Can't read config value before loaded

pietro-lopes opened this issue ยท 3 comments

commented

I'm porting TFC Casting with Channels and when I click "SinglePlayer" it triggers this ForgeEvent TagsUpdatedEvent and this code:

FoodCapability.markRecipeOutputsAsNonDecaying(event.getRegistryAccess(), manager);

and later it calls this:

float mod = data.decayModifier() * TFCConfig.SERVER.foodDecayModifier.get().floatValue();

And crashes saying can't read config value before it is loaded.
Can I ask to wrap this config to Helpers.getValueOrDefault ?

commented

This doesn't crash in a TFC dev env, what's the actual stack trace and how is this triggering in said addon's dev env but not TFC? markRecipeOutputsAsNonDecaying() calls IFood.setNonDecaying() which shouldn't need to query a decay date, so under what circumstances is that occuring?

commented

This is better looked at as a flaw in markRecipeOutputsAsNonDecaying(), because it shouldn't - as much as we can avoid it - be doing anything other than setting a single stack directly. In this case it's actually doing entirely redundant work, because the copy() means that this isn't editing the recipe in the slightest.

Any recipe using ItemStackProvider, and thus calling getEmptyStack() in Recipe#getResultItem() ideally should be excluded from this, as the marking is pointless, because ISP doesn't get marked (as opposed to the vast majority of vanilla + mod recipes, where getResultItem is simply an accessor for a stack which we can mutate).

commented

This is the stack:

getDecayDateModifier:145, FoodHandler (net.dries007.tfc.common.capabilities.food)
calculateRottenDate:227, FoodHandler (net.dries007.tfc.common.capabilities.food)
getCreationDate:87, FoodHandler (net.dries007.tfc.common.capabilities.food)
serializeNBT:182, FoodHandler (net.dries007.tfc.common.capabilities.food)
serializeNBT:34, FoodHandler (net.dries007.tfc.common.capabilities.food)
serializeNBT:115, CapabilityDispatcher (net.minecraftforge.common.capabilities)
serializeCaps:132, CapabilityProvider (net.minecraftforge.common.capabilities)
copy:477, ItemStack (net.minecraft.world.item)
getStack:123, ItemStackProvider (net.dries007.tfc.common.recipes.outputs)
getEmptyStack:112, ItemStackProvider (net.dries007.tfc.common.recipes.outputs)
getResultItem:94, CastingRecipe (net.dries007.tfc.common.recipes)
markRecipeOutputsAsNonDecaying:219, FoodCapability (net.dries007.tfc.common.capabilities.food)
onTagsUpdated:1554, ForgeEventHandler (net.dries007.tfc)
accept:-1, ForgeEventHandler$$Lambda$6704/0x0000000801afc6c8 (net.dries007.tfc)
doCastFilter:260, EventBus (net.minecraftforge.eventbus)
lambda$addListener$11:252, EventBus (net.minecraftforge.eventbus)
invoke:-1, EventBus$$Lambda$4681/0x00000008017b0250 (net.minecraftforge.eventbus)
invoke:-1, EventBus$$Lambda$4770/0x00000008017b25e8 (net.minecraftforge.eventbus)
post:315, EventBus (net.minecraftforge.eventbus)
post:296, EventBus (net.minecraftforge.eventbus)
updateRegistryTags:90, ReloadableServerResources (net.minecraft.server)
lambda$load$1:44, WorldLoader (net.minecraft.server)
apply:-1, WorldLoader$$Lambda$10878/0x0000000801fe77c8 (net.minecraft.server)
tryFire:646, CompletableFuture$UniApply (java.util.concurrent)
run:482, CompletableFuture$Completion (java.util.concurrent)
doRunTask:166, BlockableEventLoop (net.minecraft.util.thread)
doRunTask:22, ReentrantBlockableEventLoop (net.minecraft.util.thread)
pollTask:132, BlockableEventLoop (net.minecraft.util.thread)
managedBlock:145, BlockableEventLoop (net.minecraft.util.thread)
loadWorldDataBlocking:163, WorldOpenFlows (net.minecraft.client.gui.screens.worldselection)
loadWorldStem:113, WorldOpenFlows (net.minecraft.client.gui.screens.worldselection)
doLoadLevel:181, WorldOpenFlows (net.minecraft.client.gui.screens.worldselection)
doLoadLevel:169, WorldOpenFlows (net.minecraft.client.gui.screens.worldselection)
loadLevel:65, WorldOpenFlows (net.minecraft.client.gui.screens.worldselection)
loadWorld:602, WorldSelectionList$WorldListEntry (net.minecraft.client.gui.screens.worldselection)
joinWorld:501, WorldSelectionList$WorldListEntry (net.minecraft.client.gui.screens.worldselection)
mouseClicked:440, WorldSelectionList$WorldListEntry (net.minecraft.client.gui.screens.worldselection)
mouseClicked:319, AbstractSelectionList (net.minecraft.client.gui.components)
mouseClicked:53, ContainerEventHandler (net.minecraft.client.gui.components.events)
[...]

this is one of the recipes

https://github.com/lJuanGB/TFCCasting/blob/main/src/main/resources/data/tfcchannelcasting/recipes/casting/white_chocolate_heart.json

This is right after serialization
image