Update #48 - Added some features from OptiFine

This commit is contained in:
lax1dude
2025-01-24 18:39:36 -08:00
parent 1f0d593a8c
commit e83a912e38
1056 changed files with 17706 additions and 898 deletions

View File

@ -0,0 +1,75 @@
package dev.redstudio.alfheim.utils;
import com.carrotsearch.hppc.LongArrayDeque;
import com.carrotsearch.hppc.LongHashSet;
/**
* A queue implementation for long values that are deduplicated on addition.
* <p>
* This is achieved by storing the values in a {@link LongOpenHashSet} and a
* {@link LongArrayFIFOQueue}.
*
* @author Luna Lage (Desoroxxx)
* @since 1.3
*/
public final class DeduplicatedLongQueue {
// TODO: Fully Implement my own implementation to get rid of the downsides of
// reduce etc...
private final LongArrayDeque queue;
private LongHashSet set;
/**
* Creates a new deduplicated queue with the given capacity.
*
* @param capacity The capacity of the deduplicated queue
*/
public DeduplicatedLongQueue(final int capacity) {
set = new LongHashSet(capacity);
queue = new LongArrayDeque(capacity);
}
/**
* Adds a value to the queue.
*
* @param value The value to add to the queue
*/
public void enqueue(final long value) {
if (set.add(value))
queue.addLast(value);
}
/**
* Removes and returns the first value in the queue.
*
* @return The first value in the queue
*/
public long dequeue() {
return queue.removeFirst();
}
/**
* Returns whether the queue is empty.
*
* @return {@code true} if the queue is empty, {@code false} otherwise
*/
public boolean isEmpty() {
return queue.isEmpty();
}
/**
* Creates a new deduplication set.
*/
public void newDeduplicationSet() {
int i = queue.size();
if(i < 4) {
i = 4;
}
if((set.keys.length * 3 / 2) > i) {
set = new LongHashSet(i);
}else {
set.clear();
}
}
}

View File

@ -0,0 +1,5 @@
package dev.redstudio.alfheim.utils;
public enum EnumBoundaryFacing {
IN, OUT
}

View File

@ -0,0 +1,88 @@
package dev.redstudio.alfheim.utils;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
/**
* Represents a slice of a world containing a collection of chunks.
*
* @author Luna Lage (Desoroxxx)
* @author Angeline (@jellysquid)
* @since 1.0
*/
public class WorldChunkSlice {
private static final int DIAMETER = 5;
private static final int RADIUS = DIAMETER / 2;
private final int x, z;
private final Chunk[] chunks;
/**
* Initializes a {@link WorldChunkSlice} object using a given chunk provider and
* coordinates.
*
* @param chunkProvider The chunk provider to get chunks from
* @param x The X-coordinate of the center chunk
* @param z The Z-coordinate of the center chunk
*/
public WorldChunkSlice(final IChunkProvider chunkProvider, final int x, final int z) {
chunks = new Chunk[DIAMETER * DIAMETER];
for (int xDiff = -RADIUS; xDiff <= RADIUS; xDiff++)
for (int zDiff = -RADIUS; zDiff <= RADIUS; zDiff++)
chunks[((xDiff + RADIUS) * DIAMETER) + (zDiff + RADIUS)] = chunkProvider.getLoadedChunk(x + xDiff,
z + zDiff);
this.x = x - RADIUS;
this.z = z - RADIUS;
}
/**
* Checks if all chunks within a radius around a coordinate are loaded.
*
* @param x The X-coordinate to check around
* @param z The Z-coordinate to check around
* @param radius The radius around the coordinates to check
*
* @return true if all chunks are loaded, false otherwise
*/
public boolean isLoaded(final int x, final int z, final int radius) {
final int xStart = ((x - radius) >> 4) - this.x;
final int zStart = ((z - radius) >> 4) - this.z;
final int xEnd = ((x + radius) >> 4) - this.x;
final int zEnd = ((z + radius) >> 4) - this.z;
for (int currentX = xStart; currentX <= xEnd; ++currentX)
for (int currentZ = zStart; currentZ <= zEnd; ++currentZ)
if (getChunk(currentX, currentZ) == null)
return false;
return true;
}
/**
* Retrieves the chunk that includes the provided world coordinates.
*
* @param x The X-coordinate in the world
* @param z The Z-coordinate in the world
*
* @return The Chunk object that includes these coordinates
*/
public Chunk getChunkFromWorldCoords(final int x, final int z) {
return getChunk((x >> 4) - this.x, (z >> 4) - this.z);
}
/**
* Retrieves the chunk located at the given coordinates within this chunk slice.
*
* @param x The X-coordinate within the slice
* @param z The Z-coordinate within the slice
*
* @return The Chunk object at these coordinates
*/
private Chunk getChunk(final int x, final int z) {
return chunks[(x * DIAMETER) + z];
}
}