Cubic Chunks Compatibility
TheBigBadWolf2 opened this issue ยท 7 comments
2019-01-29-3.log.gz
Using Cubic Chunks, when placing a certain blocks below y=0, the console gets spammed, and GUIs for blocks will not open.
Forge Version: 14.23.5.2779
Rail Craft Version: 10.0.0-beta-4
Cubic Chunks Version: 0.0.912.0
Cubic World Gen Version: 0.0.29.0
Yes you can fix it. Whether someone wants to fix it, is a different matter.
It would involve around 10 lines of changes. First is just remove that log line that shows the spammy output for things below y=0.
The other is to serialize BlockPos to 3 ints instead of a single long (afaik, the GUI issues are only beyond -2048 to 2074 height range).
At least this should fix the 2 issues mentioned here. And I haven't found any other obvious issues that would apply to cubic chunks.
I have told people in discord repeatedly that railcraft depends on a negative y value for opening Minecart guis. I am actually fairly suprised that the game didn't crash straight. I'd like @Barteks2x to find a viable solution instead.
But vanilla gui handler only support 3 ints. For cubicchunks, all 3 of them will be used for blockpos; as a result, railcraft cannot open minecart guis.
For the 3 int and long thing, Railcraft should be saving 3 ints mostly. However, it is not a long-term solution. In 1.13+, Mojang uses the long serialization vastly, making it a pain for cubic chunks.
The X and Z coordinates have 6 bits of unused space each. Or, since it appears to be used as a flag, you could just pass Integer.MIN_VALUE and test for that.
For 1.13/1.14+ I'm probably going to change the way longs are used for block pos to have the user choose a tradeoff between horizontal and vertical size. And only optionally patch the long usages. And as far as I'm aware, this is only done for some deep internals that modders should rarely directly touch.
And since there is still 4096 blocks of usable space, it's not too big of an issue, but it would still be great if it was changed, as this is just a few additional lines of code (here is where I wish what PacketBuffer does would be more available to mods, as that is something I can patch)
There is a lot of code in Railcraft other than the GUIs that assumes trying to access the world below 0 is an error state and tries to fail gracefully. Like accessing Tile Entities I think does this.
The main reason for these checks is because certain minecraft code at least used to not be too picky about feeding valid block positions to certain block functions, even though the game will helpfully crash if you try passing them to certain other world functions.
Is there any other value we could to indicate its an entity GUI? Such as NEGATIVE_MAX? Or is that value sent as a short or something?
I'm not aware of any world or block function that won't like invalid positions. Any examples?
In 1.12 there is World.isOutsideBuildHeight that can be used. In 1.13+ I'm going to have a big issue because it's static, but we will see what I can do.
Accessing tile entities is fine at any coordinates. It's just a Map<BlockPos, TileEntity> in each chunk.
As for indicating an entity in GUI, I need to look more into it. I don't want to say something when I'm nor 100% sure what I'm talking about. As far as I know pretty much any x and z value above 30000000 is impossible in gui code. Vanilla may serialize that position as a long, and in that case, only values up to +-2^25 xz and +-2^11 y will work in vanilla. In that case, if all you need is a boolean flag, you could use position that as long serializes to -1.
Also maybe I just don't understand how it works (because I never really worked a lot with GUIs) but wouldn't it be possible to have separate IDs for entity GUIs? And how does vanilla get around it?
Forge helpfully only provides hooks that accept x, y, z values. As for vanilla, it has a completely separate and largely hardcoded GUI stack that as far as I'm aware is impossible to hook into. Because of this Forge adds its own GUI stack which can be used to open arbitrary GUIs.
But looking at it again, even though this was the way cpw told me to implement it back in the day (he wrote the whole gui stack), I'm thinking we could probably do what Forestry does for pages numbers and pack the flag into the GUI id value.
As for the accessing Tile Entities outside the world, that's a map now? I'm pretty sure it used to be an array back in the day and would crash if passed a negative y value.