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 Guy4mo ago
@Moderator
Yeshi
Yeshi4mo ago
don't ping every mod :unhappy:
BillBodkin
BillBodkinOP4mo ago
Bro lived up to his name
BackSun
BackSun4mo ago
Why did you ping the moderators anyway, this isn’t even your question?
Solution
BackSun
BackSun4mo 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
Yeshi4mo ago
is DhApi.Delayed.worldProxy.getSinglePlayerLevel(), necessary here? what's it return
BackSun
BackSun4mo ago
It returns the level. DH’s api needs to know what level (dimension) to query.
Yeshi
Yeshi4mo ago
can this not be automatically fetched by blockPos
BackSun
BackSun4mo 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
Yeshi4mo ago
might be reading this wrong, is blockPos not a method that's being called
BackSun
BackSun4mo 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
Yeshi4mo ago
OOP is funky, i need to make an effort to properly understand it some day
BillBodkin
BillBodkinOP4mo ago
Ok fair enough ty, do you think I could run these checks in other threads to help or would that cause issues?
BackSun
BackSun4mo ago
Running on a separate thread is a great idea and will work just fine.
BillBodkin
BillBodkinOP4mo ago
Nice! I will give that a go, thanks!
Yeshi
Yeshi4mo 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
BackSun4mo ago
SQLite handles it gracefully. That’s one of the big benefits of running a DB vs flat files.
BillBodkin
BillBodkinOP4mo 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
BillBodkinOP4mo ago
Aha! Think I have found what I am looking for
No description
Want results from more Discord servers?
Add your server