use of me.jellysquid.mods.lithium.common.util.tuples.Range6Int in project lithium-fabric by CaffeineMC.
the class NearbyEntityListener method forEachChunkInRangeChange.
/**
* Calls the callbacks for the chunk coordinates that this listener is leaving and entering
*/
default void forEachChunkInRangeChange(SectionedEntityCache<? extends EntityLike> entityCache, ChunkSectionPos prevCenterPos, ChunkSectionPos newCenterPos) {
Range6Int chunkRange = this.getChunkRange();
if (chunkRange == EMPTY_RANGE) {
return;
}
BlockPos.Mutable pos = new BlockPos.Mutable();
BlockBox after = newCenterPos == null ? null : new BlockBox(newCenterPos.getX() - chunkRange.negativeX(), newCenterPos.getY() - chunkRange.negativeY(), newCenterPos.getZ() - chunkRange.negativeZ(), newCenterPos.getX() + chunkRange.positiveX(), newCenterPos.getY() + chunkRange.positiveY(), newCenterPos.getZ() + chunkRange.positiveZ());
BlockBox before = prevCenterPos == null ? null : new BlockBox(prevCenterPos.getX() - chunkRange.negativeX(), prevCenterPos.getY() - chunkRange.negativeY(), prevCenterPos.getZ() - chunkRange.negativeZ(), prevCenterPos.getX() + chunkRange.positiveX(), prevCenterPos.getY() + chunkRange.positiveY(), prevCenterPos.getZ() + chunkRange.positiveZ());
if (before != null) {
for (int x = before.getMinX(); x <= before.getMaxX(); x++) {
for (int y = before.getMinY(); y <= before.getMaxY(); y++) {
for (int z = before.getMinZ(); z <= before.getMaxZ(); z++) {
if (after == null || !after.contains(pos.set(x, y, z))) {
long sectionPos = ChunkSectionPos.asLong(x, y, z);
EntityTrackingSection<? extends EntityLike> trackingSection = entityCache.getTrackingSection(sectionPos);
((EntityTrackerSection) trackingSection).removeListener(entityCache, this);
if (trackingSection.isEmpty()) {
entityCache.removeSection(sectionPos);
}
}
}
}
}
}
if (after != null) {
for (int x = after.getMinX(); x <= after.getMaxX(); x++) {
for (int y = after.getMinY(); y <= after.getMaxY(); y++) {
for (int z = after.getMinZ(); z <= after.getMaxZ(); z++) {
if (before == null || !before.contains(pos.set(x, y, z))) {
((EntityTrackerSection) entityCache.getTrackingSection(ChunkSectionPos.asLong(x, y, z))).addListener(this);
}
}
}
}
}
}
use of me.jellysquid.mods.lithium.common.util.tuples.Range6Int in project lithium-fabric by CaffeineMC.
the class NearbyEntityListenerMulti method calculateRange.
private Range6Int calculateRange() {
if (this.listeners.isEmpty()) {
return this.range = EMPTY_RANGE;
}
int positiveX = -1;
int positiveY = -1;
int positiveZ = -1;
int negativeX = 0;
int negativeY = 0;
int negativeZ = 0;
for (NearbyEntityListener listener : this.listeners) {
Range6Int chunkRange = listener.getChunkRange();
positiveX = Math.max(chunkRange.positiveX(), positiveX);
positiveY = Math.max(chunkRange.positiveY(), positiveY);
positiveZ = Math.max(chunkRange.positiveZ(), positiveZ);
negativeX = Math.max(chunkRange.negativeX(), negativeX);
negativeY = Math.max(chunkRange.negativeY(), negativeY);
negativeZ = Math.max(chunkRange.negativeZ(), negativeZ);
}
return this.range = new Range6Int(positiveX, positiveY, positiveZ, negativeX, negativeY, negativeZ);
}
Aggregations