Mod dev question - How to check if a chunk has been cached to sqlite?

Hi. I am currently creating a crude mod to cache chunks on singleplayer or multiplayer by teleporting the player around the spawn area to have their client cache the chunks into DH. What I have currently works on a basic level, however I believe the way I am checking if a chunk is already in the sqlite db is sub optimal:
BlockPos blockPos = some block within the chunk I wish to check;

var cachedBlockData = DhApi.Delayed.terrainRepo.getSingleDataPointAtBlockPos(
DhApi.Delayed.worldProxy.getSinglePlayerLevel(),
blockPos.getX(),
blockPos.getY(),
blockPos.getZ()
);

bool chunkCached = cachedBlockData.success;
BlockPos blockPos = some block within the chunk I wish to check;

var cachedBlockData = DhApi.Delayed.terrainRepo.getSingleDataPointAtBlockPos(
DhApi.Delayed.worldProxy.getSinglePlayerLevel(),
blockPos.getX(),
blockPos.getY(),
blockPos.getZ()
);

bool chunkCached = cachedBlockData.success;
(Full repo: https://gitlab.com/billyg270/bb-preload-world) My question is if there is a more preformant way to preform this check. Thanks!
Solution:
That code looks good to me I can’t think of a faster way to check for present/absent data in the DB.
Jump to solution
19 Replies
That Guy
That Guy3mo ago
@Moderator
Yeshi
Yeshi3mo ago
don't ping every mod :unhappy:
BillBodkin
BillBodkin3mo ago
Bro lived up to his name
BackSun
BackSun3mo ago
Why did you ping the moderators anyway, this isn’t even your question?
Solution
BackSun
BackSun3mo ago
That code looks good to me I can’t think of a faster way to check for present/absent data in the DB.
Yeshi
Yeshi3mo ago
is DhApi.Delayed.worldProxy.getSinglePlayerLevel(), necessary here? what's it return
BackSun
BackSun3mo ago
It returns the level. DH’s api needs to know what level (dimension) to query.
Yeshi
Yeshi3mo ago
can this not be automatically fetched by blockPos
BackSun
BackSun3mo ago
No, a block pos is just 3 integers (x,y,z) the position by itself doesn’t know if it’s in the end or overworld.
Yeshi
Yeshi3mo ago
might be reading this wrong, is blockPos not a method that's being called
BackSun
BackSun3mo ago
Nope, it’s a variable Bill wants to check. And with DH’s API it requires both a level and X, Y, Z coordinate.
Yeshi
Yeshi3mo ago
OOP is funky, i need to make an effort to properly understand it some day
BillBodkin
BillBodkin3mo ago
Ok fair enough ty, do you think I could run these checks in other threads to help or would that cause issues?
BackSun
BackSun3mo ago
Running on a separate thread is a great idea and will work just fine.
BillBodkin
BillBodkin3mo ago
Nice! I will give that a go, thanks!
Yeshi
Yeshi3mo ago
speaking of threads, is there a chance of having race conditions when writing to the db or does DH/sqlite handle multiple threads writing at the same time gracefully
BackSun
BackSun3mo ago
SQLite handles it gracefully. That’s one of the big benefits of running a DB vs flat files.
BillBodkin
BillBodkin3mo ago
Using threads has greatly improved the system! The FPS maintains 60 as the process happens now. Final question on this topic, when using getSingleDataPointAtBlockPos will sucess only return true if all detail levels have been cached? If not if there something else I can call to confirm this?
BillBodkin
BillBodkin3mo ago
Aha! Think I have found what I am looking for
No description
Want results from more Discord servers?
Add your server