Skip to content

Commit 4791e9c

Browse files
committed
The great javadocs v2 electric boogaloo
1 parent f018dd9 commit 4791e9c

1 file changed

Lines changed: 55 additions & 31 deletions

File tree

src/main/java/net/superkat/tidal/water/WaterHandler.java

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,11 @@ public class WaterHandler {
9595
//boolean for if the centers of ALL sites should be recalculated - it's a very fast calculation, so I feel comfortable doing it all at once
9696
public boolean recalcSiteCenters = true;
9797

98-
//TODO - THE ULTIMATE PLAN
99-
//Chunk scanners should:
100-
// - find shoreline sites
101-
// - add scanned water blocks to a queue here
102-
//That queue will be iterated through to find a water block's closest site after all activate scanners are done
103-
//Scanners, sites, and queued blocks need to be sorted via chunks(longs).
104-
//Once all scanners are done, the water block queue begins.
105-
//Each block will be a key with a site pos, sorted via chunks(siteCache) (this is the version of regions)
106-
//water bodies will be replaced with these regions. Some of them can still be pretty big, and probably provide more accurate size data per area anyways.
107-
10898
//idea: if no site is within configurable distance, that water is considered open ocean and extra effects can be added there
99+
//idea 2: if the amount of blocks associated with a SitePos is really small, non-directional ambient particles spawn
109100

110-
//TODO - any cleanup, redo javadocs lol ( ͡• ͜ʖ ͡• )
111101
//TODO - possibly change build to use the tick scanners method instead of doing it all itself?
112102
//TODO - make it so that the scanners map clears finished chunks to free up memory (surprisingly difficult to do)
113-
114103
//FIXME - init build doesn't get all nearby chunks(reload build scans more chunks than join build)
115104

116105
public WaterHandler(ClientWorld world, TidalWaveHandler tidalWaveHandler) {
@@ -313,6 +302,11 @@ public void rebuild() {
313302
this.built = build();
314303
}
315304

305+
/**
306+
* Ticks scheduled ChunkScanenrs, setting their value to null if they are finished.
307+
*
308+
* @param player The Client's Player(used for distance calculation)
309+
*/
316310
public void tickScheduledScanners(ClientPlayerEntity player) {
317311
BlockPos playerPos = player.getBlockPos();
318312
int chunkRadius = this.tidalWaveHandler.getChunkRadius(); //caching this call might help?
@@ -338,6 +332,8 @@ public void tickScheduledScanners(ClientPlayerEntity player) {
338332
* Find the closest SitePos for all scanned water blocks, and remove them from the queue.
339333
* <br><br>Ticks 10 blocks at a time per chunk.
340334
*
335+
* @param assumeFullScan Should assume all chunks have been fully scanned or not. If true, the check for nearby scanners will not be called.
336+
*
341337
* @return True if there are no more waiting water blocks
342338
*/
343339
public boolean tickWaitingWaterBlocks(boolean assumeFullScan) {
@@ -371,6 +367,12 @@ public boolean tickWaitingWaterBlocks(boolean assumeFullScan) {
371367
return this.waitingWaterBlocks.isEmpty();
372368
}
373369

370+
/**
371+
* Checks if the nearby ChunkScanners from a ChunkPos(as a long) are finished.
372+
*
373+
* @param chunkPosL The ChunkPos(long) to check.
374+
* @return If the nearby ChunkScanners are finished.
375+
*/
374376
public boolean nearbyScannersFinished(long chunkPosL) {
375377
int radius = 3; //will be configurable later
376378
ChunkPos pos = new ChunkPos(chunkPosL);
@@ -396,6 +398,14 @@ public void calcSiteCenters() {
396398
MinecraftClient.getInstance().player.playSound(SoundEvents.ENTITY_WARDEN_SONIC_BOOM, 0.3f, 1f);
397399
}
398400

401+
/**
402+
* Checks if a ChunkPos(as a long) is within the ChunkScanner activation distance
403+
*
404+
* @param playerBlockPos The Client's Player's current BlockPos
405+
* @param chunkPosL The chunk to check
406+
* @param chunkRadius The radius of the activation distance(is a param to cache calling it from the config)
407+
* @return If the ChunkPos(as a long) is within the ChunkScanner activation distance.
408+
*/
399409
public boolean scannerInDistance(BlockPos playerBlockPos, long chunkPosL, int chunkRadius) {
400410
ChunkPos pos = new ChunkPos(chunkPosL);
401411
ChunkPos playerPos = new ChunkPos(playerBlockPos);
@@ -433,12 +443,44 @@ public void scheduleChunkScanner(ChunkPos chunkPos) {
433443
*/
434444
public boolean rescheduleChunkScanner(ChunkPos chunkPos) {
435445
long chunkPosL = chunkPos.toLong();
436-
// if (this.scanners.get(chunkPosL) != null) return false;
437446
this.scheduleChunkScanner(chunkPos);
438447
this.removeChunkFromTrackers(chunkPosL);
439448
return true;
440449
}
441450

451+
/**
452+
* Queues a collection of water blocks into the waitingWaterBlocks Queue.
453+
*
454+
* @param blocks The collection of water blocks to queue.
455+
*/
456+
public void queueWaterBlocks(Collection<BlockPos> blocks) {
457+
for (BlockPos water : blocks) {
458+
long chunkPosL = new ChunkPos(water).toLong();
459+
this.waitingWaterBlocks.computeIfAbsent(chunkPosL, aLong -> new ObjectArrayFIFOQueue<>()).enqueue(water);
460+
}
461+
}
462+
463+
/**
464+
* Creates a SitePos at the given BlockPos
465+
*
466+
* @param pos The given BlockPos
467+
*/
468+
public void createSitePos(BlockPos pos) {
469+
long chunkPosL = new ChunkPos(pos).toLong();
470+
SitePos site = new SitePos(pos);
471+
sites.computeIfAbsent(chunkPosL, aLong -> new ObjectOpenHashSet<>()).add(site);
472+
}
473+
474+
/**
475+
* Adds a shoreline block(assumed to not be water)
476+
*
477+
* @param pos The shoreline BlockPos
478+
*/
479+
public void addShorelineBlock(BlockPos pos) {
480+
long chunkPosL = new ChunkPos(pos).toLong();
481+
this.shoreBlocks.computeIfAbsent(chunkPosL, aLong -> new ObjectOpenHashSet<>()).add(pos);
482+
}
483+
442484
/**
443485
* Fully removes a chunk form all trackers, scanners, and updates. Called once a chunk is unloaded.
444486
*
@@ -464,24 +506,6 @@ public void removeChunkFromTrackers(long chunkPosL) {
464506
this.sites.remove(chunkPosL);
465507
}
466508

467-
public void queueWaterBlocks(Collection<BlockPos> blocks) {
468-
for (BlockPos water : blocks) {
469-
long chunkPosL = new ChunkPos(water).toLong();
470-
this.waitingWaterBlocks.computeIfAbsent(chunkPosL, aLong -> new ObjectArrayFIFOQueue<>()).enqueue(water);
471-
}
472-
}
473-
474-
public void createSitePos(BlockPos pos) {
475-
long chunkPosL = new ChunkPos(pos).toLong();
476-
SitePos site = new SitePos(pos);
477-
sites.computeIfAbsent(chunkPosL, aLong -> new ObjectOpenHashSet<>()).add(site);
478-
}
479-
480-
public void addShorelineBlock(BlockPos pos) {
481-
long chunkPosL = new ChunkPos(pos).toLong();
482-
this.shoreBlocks.computeIfAbsent(chunkPosL, aLong -> new ObjectOpenHashSet<>()).add(pos);
483-
}
484-
485509
public void clear() {
486510
this.waitingWaterBlocks.clear();
487511
this.shoreBlocks.clear();

0 commit comments

Comments
 (0)