Search in sources :

Example 1 with Range6Int

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);
                    }
                }
            }
        }
    }
}
Also used : Range6Int(me.jellysquid.mods.lithium.common.util.tuples.Range6Int) BlockBox(net.minecraft.util.math.BlockBox) EntityTrackerSection(me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerSection) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with Range6Int

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);
}
Also used : Range6Int(me.jellysquid.mods.lithium.common.util.tuples.Range6Int)

Aggregations

Range6Int (me.jellysquid.mods.lithium.common.util.tuples.Range6Int)2 EntityTrackerSection (me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerSection)1 BlockBox (net.minecraft.util.math.BlockBox)1 BlockPos (net.minecraft.util.math.BlockPos)1