JurassiCraftTeam / JurassiCraft

5 stars 10 forks source link

Fix edge case crash when there are no loaded chunks (e.g. on world load) #14

Open wallabra opened 2 years ago

wallabra commented 2 years ago

Apparently, the tickEvent handles circumstantial conversion from dirt to peat in loaded chunks. When there are no loaded chunks, it should have no effect, acting much like a no-op.

What used to happen instead is that, if there are no loaded chunks (possible e.g. when loading a save under certain rare circumstances or with some other mods), it would crash, as it would try to get a random integer between 0 and 0, and Java's Random throws an error when that happens.

By preventing the block with the random call from executing altogether in this scenario, this one error scenario is completely thwarted. The function has also been slightly refactored so that conditions like this are at the top of the function, to reduce nested indentation and make it easier for new early return conditions to be added in the future if needed.