Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix an oopsie in chunk caches with dynamic world height #3375

Open
wants to merge 2 commits into
base: 1.17.1
Choose a base branch
from

Conversation

wagyourtail
Copy link
Collaborator

fixes #mine chest and some stuff not working properly

@@ -43,7 +43,7 @@
/**
* Magic value to detect invalid cache files, or incompatible cache files saved in an old version of Baritone
*/
private static final int CACHED_REGION_MAGIC = 456022910;
private static final int CACHED_REGION_MAGIC = 456022911;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I supposed to just bump this, or roll some dice and pick new numbers, or what

@@ -166,7 +166,7 @@ public synchronized final void save(String directory) {
out.writeShort(entry.getValue().size());
for (BlockPos pos : entry.getValue()) {
out.writeByte((byte) (pos.getZ() << 4 | pos.getX()));
out.writeByte((byte) (pos.getY()));
out.writeInt(pos.getY()-dimension.minY());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs updating due to expanding the range of this

@Rorschach3533
Copy link

You guys gonna update this or are we going to change something ?

@wagyourtail wagyourtail requested a review from leijurv April 5, 2022 02:16
@leijurv
Copy link
Member

leijurv commented Apr 5, 2022

I explained how it should be done here 05cc63f

I'd like to see something like LEGACY_REGION_MAGIC = 456022910; and CACHED_REGION_MAGIC = 456022911;. When loading, switch on that value and do something like boolean yCoordinateIsAByte = magic == LEGACY_REGION_MAGIC;, then int Y = yCoordinateIsAByte ? in.readByte() & 0xff : in.readInt() + dimension.minY();

Also I don't see why we need to add and subtract out dimension.minY(). It seems simpler to just directly write the actual value?

That should only happen on read. Writing a chunk should always do it the new way with the new magic.

@wagyourtail
Copy link
Collaborator Author

Also I don't see why we need to add and subtract out dimension.minY()

yeah, I suppose that doesn't need to be there as it'll be signed when read/writing, it will match the y value of the chunk data tho, since those are -minY to be able to shove into a long value

@wagyourtail
Copy link
Collaborator Author

I'd like to see something like LEGACY_REGION_MAGIC ...

I'm not sure if this is a good idea, this might cause issues with people who have old cache data that is wrong (incorrect y value currently from chunks parsed with worlds with -ymin values).
it's good I guess for loading cachedata from 1.17/older worlds that didn't previously have the minY, but iirc we're now saving the cache data in a folder name based on the worldheight, so it'll always have been wrong

@leijurv
Copy link
Member

leijurv commented Apr 5, 2022

we're now saving the cache data in a folder name based on the worldheight

mmmmmmmmmmmm I don't like that, with a patch to saving the Y coord I don't think that's a good idea anymore, want to undo that afterwards

this might cause issues with people who have old cache data that is wrong (incorrect y value currently from chunks parsed with worlds with -ymin values).

I actually don't think this would cause any issues. Imagining you do #goto chest or some such, and it's out of your render distance, the Y coordinate doesn't matter in practice (and if simplifyUnloadedYCoord is left at default, it doesn't matter at all). Once it comes into your render distance, incorrect Y coordinate data in the cache is overwritten with the true data from the actual chunks, so there is no issue.

Really, thinking on it now, the XYZ coordinate within the chunk of the interesting block doesn't matter lol. Saving it in RAM is good, but saving it on disk is a little pointless. I think we could get away just as well with the on-disk format just containing the quantity of blocks in the chunk, not their locations?

@leijurv
Copy link
Member

leijurv commented Apr 5, 2022

tldr: given that the XYZ doesn't matter so much, my opinion is that it's much better to scrape together as much data as we can from older or incompatible caches, than to ignore it because its Y could be incorrect.

@wagyourtail
Copy link
Collaborator Author

Really, thinking on it now, the XYZ coordinate within the chunk of the interesting block doesn't matter lol. Saving it in RAM is good, but saving it on disk is a little pointless. I think we could get away just as well with the on-disk format just containing the quantity of blocks in the chunk, not their locations?

goto spawner/chest isn't working properly without cache, so might need to fix a few things to do that...

@leijurv
Copy link
Member

leijurv commented Apr 6, 2022

goto spawner/chest isn't working properly without cache, so might need to fix a few things to do that...

Reread what I said - "Saving it in RAM is good, but saving it on disk is a little pointless."

If it's in the CachedChunk.specialBlockLocations, which it will be for a chunk in render distance that just came out of the ChunkPacker, then it will work just fine for goto spawner. If it's out of render distance, the Y coordinate will be unknown, as well as the X and Z within the chunk, but that's fine since if it's out of render distance we don't need to know where it is more precisely than what chunk it's in.

So I'm saying that actually I'm pretty sure goto spawner/chest would work perfectly without saving the XYZ of chest/spawner to disk. Just whether they're in the chunk or not (and maybe a quantity).

@leijurv
Copy link
Member

leijurv commented Jun 7, 2022

Update: to be clear, packed CachedChunks SHOULD still store the XYZ list while in RAM. XYZ should only be discarded when written to disk, it should NOT be discarded when packed. The reason is scenarios like 2b2t spawn

@wagyourtail
Copy link
Collaborator Author

wagyourtail commented Jun 20, 2022

2b2t spawn is probably big enough it shouldnt be discarded on disk either...
not like it takes that much space...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants