Minecraftforge: [1.14.3] Getting blockstate during world load locks game menu

Created on 29 Jun 2019  路  14Comments  路  Source: MinecraftForge/MinecraftForge


Minecraft Version: 1.14.3

Forge Version: 1.14.3-27.0.15

Full Log: No log created

Steps to Reproduce:
Create a basic TileEntity that overrides onLoad to use getBlockState in world. Place the TileEntity in a spawn chunk, close the game, and re-load the world. It will fail to start.

Description of bug:
Using the latest forge (1.14.3-27.0.15), if a TileEntity in the chunks being loaded while a world is initialized overrides onLoad() to use world.getBlockState(pos), it locks the game at the world loading menu with no error message, no crash, etc. In addition, no Exception is thrown, as wrapping the getBlockState call in a try-catch block has no effect.

TileEntities doing the same getBlockState call in onLoad that aren't loaded while the world is starting function fine.

It should be noted that neither the World or the BlockPos in the world.getBlockState(pos) are null.

1.14 Bug Confirmed Stale

Most helpful comment

We would have to do some really annoying and performance intensive system that checks when a TE is being added to work. If the chunk it is in is available at that time. If not then add a callback that happens when it is So we can fire off the load..
Doing things in First tick is a simple hack that may work.
Just make EVERY onLoad happen in the first tick. in Forge itself instead of requiring all TEs to continuously tick.

The other issue is the Chunk Load event, it's fired at the same time as onLoad, which means it'll have this same issue of the Chunk not being available.

All 14 comments

I'm not sure if it's possible to fix this.
onLoad in the TE is called while the chunk is still being loaded. So calling getBlockState will block until the chunk is loaded, which blocks until your onLoad is done...
What is your use-case for this?

onLoad in the TE is called while the chunk is still being loaded.

This was not the case in 1.12.2, so the behaviour here has changed.

It's very likely that in this case it's vanilla behavior that has changed, not forge.

My use case is getting the BlockState argument needed to schedule a blockTick in world (in world.getPendingBlockTicks().scheduleTick).

If getBlockState (among other things) is supposed to be unusable during loading, that severely limits the usefulness of onLoad overrides, and makes the comment on the method no longer useful/valid.

onLoad is likely requiring deprecation in it's current form. The worldload is multithreaded now, and as such, it's quite possible you cannot access the world directly from it anymore.

What's the recommended alternative for onLoad then?

Probably an if (first) inside tick? However that requires your TE to be tickable. So I suggest you provide use-cases for the previous onLoad for TEs that are not tickable so that a new solution can be found.

Maybe call a loadComplete method before tick is called the first time, for all TEs

The problem is that then all TEs have to be ticking (at least for one tick). And, like cpw said, this is not really feasible with the new world loading.

So again, please post actual use cases.

How much overhead would that cause (ticking every TE once)? We could add them to a set on load, and remove them after the initial tick. As long as people don't do heavy lifting in the loadComplete method it shouldn't be too bad surely?

EDIT: Re-read your comment, and am now thinking that any overhead may well be unnecessary overhead.

We would have to do some really annoying and performance intensive system that checks when a TE is being added to work. If the chunk it is in is available at that time. If not then add a callback that happens when it is So we can fire off the load..
Doing things in First tick is a simple hack that may work.
Just make EVERY onLoad happen in the first tick. in Forge itself instead of requiring all TEs to continuously tick.

The other issue is the Chunk Load event, it's fired at the same time as onLoad, which means it'll have this same issue of the Chunk not being available.

So, it's been a month, anyone have any suggestions at all?

This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___." or "Here's a screenshot of this issue on the latest version"). Thank you for your contributions!

This issue has been automatically closed because it has not had activity in a long time. Please feel free to reopen it or create a new issue.

Was this page helpful?
0 / 5 - 0 ratings