Supernova Support

This commit is contained in:
Jason Mitchell authored and Jason Mitchell committed 2026-03-21 22:06:38 -07:00
1 parent 5ed26f3af7
commit bccc5b00ca
24 files changed
+1634 -88

No files matched your search

@@ -0,0 +1,115 @@
package com.gtnewhorizons.angelica.api;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.chunk.Chunk;
/**
* Provides per-block RGB light color data for the rendering pipeline. Mods that replace the lighting engine (e.g. Supernova) implement this
* and register via {@link #register(BlockLightProvider)}.
*
*/
public interface BlockLightProvider {
/**
* Get RGB block light at the given world coordinates.
*
* @param blockAccess the block access context (WorldSlice on builder threads, World on main thread)
* @return packed RGB (see class Javadoc), or {@code -1} if no data is available
*/
int getBlockLightRGB(IBlockAccess blockAccess, int x, int y, int z);
/**
* Get RGB sky light at the given world coordinates.
*
* @param blockAccess the block access context (WorldSlice on builder threads, World on main thread)
* @return packed RGB (see class Javadoc), or {@code -1} if no data
*/
default int getSkyLightRGB(IBlockAccess blockAccess, int x, int y, int z) { return -1; }
/**
* Capture per-section light data on the main thread for use by builder threads.
* Called during {@code ClonedChunkSection.init()}.
*
* @return a {@link SectionLightData} snapshot, or {@code null} if not supported
*/
default SectionLightData prepareSectionData(Chunk chunk, int sectionY) {
return null;
}
/** Pack three 0-15 channels into a single int. */
static int packRGB(int r, int g, int b) {
return (r << 8) | (g << 4) | b;
}
/** Extract the red channel (0-15) from a packed RGB word. */
static int unpackR(int word) {
return (word >> 8) & 0xF;
}
/** Extract the green channel (0-15) from a packed RGB word. */
static int unpackG(int word) {
return (word >> 4) & 0xF;
}
/** Extract the blue channel (0-15) from a packed RGB word. */
static int unpackB(int word) {
return word & 0xF;
}
static BlockLightProvider getInstance() {
return Holder.INSTANCE;
}
static boolean isRegistered() {
return Holder.INSTANCE != Holder.DEFAULT;
}
/**
* Register the global block light provider. Must be called exactly once.
*
* @throws IllegalStateException if a provider has already been registered
*/
static void register(BlockLightProvider provider) {
if (Holder.INSTANCE != Holder.DEFAULT) {
throw new IllegalStateException("BlockLightProvider already registered: " + Holder.INSTANCE.getClass().getName() + ". Cannot register " + provider.getClass().getName());
}
Holder.INSTANCE = provider;
}
/**
* Call from your {@code IFMLLoadingPlugin} static initializer to enable colored light support.
* Must be called before mixin application (i.e. during coremod loading). Calling after mixins are frozen will throw.
*/
static void enableColoredLight() {
if (EarlyFlags.MIXINS_FROZEN) {
throw new IllegalStateException("Too late to enable colored light -- mixin configs have already been evaluated. Call BlockLightProvider.enableColoredLight() from your IFMLLoadingPlugin.");
}
EarlyFlags.COLORED_LIGHT = true;
}
/**
* Freeze the mixin config gate. After this call, {@link #enableColoredLight()} will throw.
* Called by the mixin config evaluation path before reading {@link #coloredLightEnabled()}.
*/
static void freezeMixinConfig() {
EarlyFlags.MIXINS_FROZEN = true;
}
/**
* Returns whether colored light support was enabled via {@link #enableColoredLight()}.
* Call {@link #freezeMixinConfig()} separately to close the enablement window.
*/
static boolean coloredLightEnabled() {
return EarlyFlags.COLORED_LIGHT;
}
final class EarlyFlags {
static boolean COLORED_LIGHT = false;
static boolean MIXINS_FROZEN = false;
}
final class Holder {
static final BlockLightProvider DEFAULT = (_, _, _, _) -> -1;
static BlockLightProvider INSTANCE = DEFAULT;
}
}
@@ -0,0 +1,34 @@
package com.gtnewhorizons.angelica.api;
/**
* Mixin interface for {@code AoFaceData} providing per-corner RGB light values.
* Each array has 4 elements corresponding to the quad's corner vertices.
*/
public interface ExtAoFaceData {
/** Per-corner red light values (block light, 0-15 range). */
float[] angelica$getRl();
/** Per-corner green light values (block light, 0-15 range). */
float[] angelica$getGl();
/** Per-corner blue light values (block light, 0-15 range). */
float[] angelica$getBl();
float angelica$getBlendedR(float[] w);
float angelica$getBlendedG(float[] w);
float angelica$getBlendedB(float[] w);
/** Per-corner red light values (sky light, 0-15 range). */
float[] angelica$getSkyRl();
/** Per-corner green light values (sky light, 0-15 range). */
float[] angelica$getSkyGl();
/** Per-corner blue light values (sky light, 0-15 range). */
float[] angelica$getSkyBl();
float angelica$getBlendedSkyR(float[] w);
float angelica$getBlendedSkyG(float[] w);
float angelica$getBlendedSkyB(float[] w);
}
@@ -0,0 +1,55 @@
package com.gtnewhorizons.angelica.api;
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
/**
* Mixin interface for {@code LightDataAccess} providing per-block RGB light cache.
*
* <h3>Channel format</h3>
* Individual RGB words use the {@link BlockLightProvider} packing: {@code (r << 8) | (g << 4) | b}, each channel 0-15.
*
*/
public interface ExtLightDataAccess {
/** RGB block light at exact world coordinates. */
int angelica$getRGB(int x, int y, int z);
/** RGB block light offset one block in {@code dir} (face neighbor lookup). */
int angelica$getRGB(int x, int y, int z, ModelQuadFacing dir);
/** RGB block light offset by two directions (edge/corner neighbor for AO). */
int angelica$getRGB(int x, int y, int z, ModelQuadFacing d1, ModelQuadFacing d2);
boolean angelica$isRGBEnabled();
/** RGB sky light at exact world coordinates. */
int angelica$getSkyRGB(int x, int y, int z);
/** RGB sky light offset one block in {@code dir} (face neighbor lookup). */
int angelica$getSkyRGB(int x, int y, int z, ModelQuadFacing dir);
/** RGB sky light offset by two directions (edge/corner neighbor for AO). */
int angelica$getSkyRGB(int x, int y, int z, ModelQuadFacing d1, ModelQuadFacing d2);
boolean angelica$isSkyRGBEnabled();
/**
* Compute cache array index for the given world coordinates. Use with
* {@link #angelica$getRGBByIndex}, {@link #angelica$getSkyRGBByIndex}, or
* {@link #angelica$getFusedByIndex}
*/
int angelica$getIndex(int x, int y, int z);
/** Like {@link #angelica$getRGB(int, int, int)} but with a pre-computed cache index. */
int angelica$getRGBByIndex(int idx, int x, int y, int z);
/** Like {@link #angelica$getSkyRGB(int, int, int)} but with a pre-computed cache index. */
int angelica$getSkyRGBByIndex(int idx, int x, int y, int z);
/**
* Single cache lookup returning both block and sky RGB in the <b>cache format</b>.
* Upper 32 bits = block word (packed RGB | SENTINEL), lower 32 bits = sky word (packed RGB | SENTINEL).
*/
long angelica$getFusedByIndex(int idx, int x, int y, int z);
}
@@ -0,0 +1,11 @@
package com.gtnewhorizons.angelica.api;
import net.minecraft.world.IBlockAccess;
/**
* Interface for {@code LightDataCache} exposing its block access reference.
*/
public interface ExtLightDataCache {
IBlockAccess angelica$getBlockAccess();
}
@@ -0,0 +1,21 @@
package com.gtnewhorizons.angelica.api;
/**
* Interface for {@code QuadLightData} providing per-vertex RGB light values.
*/
public interface ExtQuadLightData {
float[] angelica$getR();
float[] angelica$getG();
float[] angelica$getB();
boolean angelica$isRGBValid();
void angelica$setRGBValid(boolean valid);
float[] angelica$getSkyR();
float[] angelica$getSkyG();
float[] angelica$getSkyB();
boolean angelica$isSkyRGBValid();
void angelica$setSkyRGBValid(boolean valid);
}
@@ -0,0 +1,41 @@
package com.gtnewhorizons.angelica.api;
/**
* Provides RGB light data for a single chunk section. Implemented by external providers (e.g. Supernova)
* and returned from {@link BlockLightProvider#prepareSectionData}.
*
* <h3>Transport format</h3>
* {@link #getRGBAndSkyRGB} returns a compact <b>transport format</b>: {@code ((block & 0xFFFF) << 16) | (sky & 0xFFFF)}.
*/
public interface SectionLightData {
/**
* Get RGB block light at section-local coordinates.
*
* @param localX 0-15
* @param localY 0-15
* @param localZ 0-15
* @return packed {@code (r << 8) | (g << 4) | b}, each channel 0-15, or {@code -1} if unavailable
*/
int getRGB(int localX, int localY, int localZ);
/**
* Get RGB sky light at section-local coordinates.
*
* @param localX 0-15
* @param localY 0-15
* @param localZ 0-15
* @return packed {@code (r << 8) | (g << 4) | b}, each channel 0-15, or {@code -1} if unavailable
*/
default int getSkyRGB(int localX, int localY, int localZ) { return -1; }
/**
* Get both block and sky RGB in a single call (transport format). Implementations can override
* to share index computation and apply section-level fast paths.
*
* @return {@code ((block & 0xFFFF) << 16) | (sky & 0xFFFF)}
*/
default long getRGBAndSkyRGB(int localX, int localY, int localZ) {
return ((long)(getRGB(localX, localY, localZ) & 0xFFFF) << 16) | (getSkyRGB(localX, localY, localZ) & 0xFFFF);
}
}
@@ -0,0 +1,21 @@
package com.gtnewhorizons.angelica.api;
/**
* Computes an RGB tint from block light and sky light channel values. The lightmap handles brightness; the tint only controls color.
*/
@FunctionalInterface
public interface TintComputer {
/**
* Blend block light RGB and sky light RGB into a tint color.
*
* @param br block light red (0-15)
* @param bg block light green (0-15)
* @param bb block light blue (0-15)
* @param sr sky light red (0-15, already adjusted for sky subtraction)
* @param sg sky light green (0-15)
* @param sb sky light blue (0-15)
* @param out float[3] output: R, G, B tint multipliers (typically 0-1)
*/
void computeTint(float br, float bg, float bb, float sr, float sg, float sb, float[] out);
}
@@ -0,0 +1,82 @@
package com.gtnewhorizons.angelica.api;
import java.util.ArrayList;
import java.util.List;
/**
* Registry for tint blend modes used by the colored light pipeline. Provides a default no-tint mode.
* External mods (e.g. Supernova) can register additional modes via {@link #registerMode(String, TintComputer)}.
*
*/
public final class TintRegistry {
private static final TintComputer NO_TINT = (br, bg, bb, sr, sg, sb, out) -> {
out[0] = 1f;
out[1] = 1f;
out[2] = 1f;
};
private static final List<TintComputer> computers = new ArrayList<>();
private static final List<String> names = new ArrayList<>();
private static TintComputer current;
private static volatile int currentOrdinal;
static {
registerMode("NONE", NO_TINT);
current = NO_TINT;
currentOrdinal = 0;
}
private TintRegistry() {}
/** Register a named tint blend mode. Returns the ordinal assigned. */
public static int registerMode(String name, TintComputer computer) {
final int ordinal = computers.size();
computers.add(computer);
names.add(name);
return ordinal;
}
/** Returns the currently active tint computer. */
public static TintComputer getCurrent() {
return current;
}
/** Returns the ordinal of the current mode, or -1 if a custom (non-registered) computer is active. */
public static int getCurrentOrdinal() {
return currentOrdinal;
}
/** Switch to a registered mode by ordinal. */
public static void setCurrentByOrdinal(int ordinal) {
if (ordinal < 0 || ordinal >= computers.size()) {
throw new IllegalArgumentException("Invalid tint mode ordinal: " + ordinal + " (registered modes: " + computers.size() + ")");
}
current = computers.get(ordinal);
currentOrdinal = ordinal;
}
/** Set a custom tint computer directly. */
public static void setCurrent(TintComputer computer) {
current = computer;
// Resolve ordinal; custom computers not in the registry get -1
for (int i = 0; i < computers.size(); i++) {
if (computers.get(i) == computer) {
currentOrdinal = i;
return;
}
}
currentOrdinal = -1;
}
/** Returns the number of registered blend modes. */
public static int getModeCount() {
return computers.size();
}
/** Returns the display name of a registered mode by ordinal. */
public static String getModeName(int ordinal) {
if (ordinal < 0 || ordinal >= names.size()) return "UNKNOWN";
return names.get(ordinal);
}
}
@@ -4,6 +4,7 @@ import baubles.common.lib.PlayerHandler;
import com.gtnewhorizon.gtnhlib.blockpos.BlockPos;
import com.gtnewhorizon.gtnhlib.blockpos.IBlockPos;
import com.gtnewhorizon.gtnhlib.util.CoordinatePacker;
import com.gtnewhorizons.angelica.api.BlockLightProvider;
import com.gtnewhorizons.angelica.api.IDynamicLightProducer;
import com.gtnewhorizons.angelica.compat.ModStatus;
import com.gtnewhorizons.angelica.compat.backhand.BackhandReflectionCompat;
@@ -52,12 +53,18 @@ public class DynamicLights {
private static final double MAX_RADIUS = 7.75;
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
private final Set<IDynamicLightSource> dynamicLightSources = new ObjectOpenHashSet<>();
private IDynamicLightSource[] lightSourceArray = new IDynamicLightSource[0];
private final ReentrantReadWriteLock lightSourcesLock = new ReentrantReadWriteLock();
private volatile int lightSourceCount = 0;
private final ChunkRebuildManager chunkRebuildManager = new ChunkRebuildManager();
private long lastUpdate = System.currentTimeMillis();
private int lastUpdateCount = 0;
/** Must be called under write lock. */
private void rebuildLightSourceArray() {
this.lightSourceArray = this.dynamicLightSources.toArray(new IDynamicLightSource[0]);
}
public static DynamicLights get() {
if (instance == null)
instance = new DynamicLights();
@@ -93,7 +100,7 @@ public class DynamicLights {
if (!isEnabled())
return;
long now = System.currentTimeMillis();
final long now = System.currentTimeMillis();
if (now >= this.lastUpdate + Mode.getDelay()) {
this.lastUpdate = now;
this.lastUpdateCount = 0;
@@ -104,7 +111,7 @@ public class DynamicLights {
int worldTick = 0;
if (AdaptiveTickingEnabled) {
Minecraft mc = Minecraft.getMinecraft();
final Minecraft mc = Minecraft.getMinecraft();
if (mc.theWorld != null && mc.renderViewEntity != null) {
cameraX = mc.renderViewEntity.posX;
cameraY = mc.renderViewEntity.posY + mc.renderViewEntity.getEyeHeight();
@@ -112,15 +119,15 @@ public class DynamicLights {
worldTick = (int) (mc.theWorld.getTotalWorldTime() & 0x7FFFFFFF);
// Calculate look direction from yaw (normalized horizontal direction)
float yaw = mc.renderViewEntity.rotationYaw;
double yawRad = Math.toRadians(yaw);
final float yaw = mc.renderViewEntity.rotationYaw;
final double yawRad = Math.toRadians(yaw);
lookDirX = -Math.sin(yawRad);
lookDirZ = Math.cos(yawRad);
}
}
this.lightSourcesLock.readLock().lock();
for (var lightSource : this.dynamicLightSources) {
for (var lightSource : this.lightSourceArray) {
// Entity type filter
if (!EntityLightConfig.isEntityTypeEnabled(lightSource)) {
continue;
@@ -128,7 +135,7 @@ public class DynamicLights {
// Adaptive ticking filter
if (AdaptiveTickingEnabled) {
AdaptiveTickMode mode = AdaptiveTickCalculator.calculate(
final AdaptiveTickMode mode = AdaptiveTickCalculator.calculate(
lightSource, cameraX, cameraY, cameraZ, lookDirX, lookDirZ);
if (!mode.shouldTickThisFrame(worldTick, lightSource.hashCode())) {
continue;
@@ -150,6 +157,7 @@ public class DynamicLights {
this.lightSourcesLock.writeLock().lock();
if (this.dynamicLightSources.add(lightSource)) {
this.lightSourceCount = this.dynamicLightSources.size();
rebuildLightSourceArray();
}
this.lightSourcesLock.writeLock().unlock();
}
@@ -162,17 +170,11 @@ public class DynamicLights {
public void removeLightSource(@NotNull IDynamicLightSource lightSource) {
this.lightSourcesLock.writeLock().lock();
var dynamicLightSources = this.dynamicLightSources.iterator();
IDynamicLightSource it;
while (dynamicLightSources.hasNext()) {
it = dynamicLightSources.next();
if (it.equals(lightSource)) {
dynamicLightSources.remove();
this.lightSourceCount = this.dynamicLightSources.size();
if (activeRenderer != null)
lightSource.angelica$scheduleTrackedChunksRebuild(activeRenderer);
break;
}
if (this.dynamicLightSources.remove(lightSource)) {
this.lightSourceCount = this.dynamicLightSources.size();
rebuildLightSourceArray();
if (activeRenderer != null)
lightSource.angelica$scheduleTrackedChunksRebuild(activeRenderer);
}
this.lightSourcesLock.writeLock().unlock();
@@ -186,13 +188,14 @@ public class DynamicLights {
public void removeLightSources(@NotNull Predicate<IDynamicLightSource> filter) {
this.lightSourcesLock.writeLock().lock();
var dynamicLightSources = this.dynamicLightSources.iterator();
final var dynamicLightSources = this.dynamicLightSources.iterator();
IDynamicLightSource it;
boolean changed = false;
while (dynamicLightSources.hasNext()) {
it = dynamicLightSources.next();
if (filter.test(it)) {
dynamicLightSources.remove();
this.lightSourceCount = this.dynamicLightSources.size();
changed = true;
if (activeRenderer != null) {
if (it.angelica$getLuminance() > 0)
it.angelica$resetDynamicLight();
@@ -201,6 +204,10 @@ public class DynamicLights {
break;
}
}
if (changed) {
this.lightSourceCount = this.dynamicLightSources.size();
rebuildLightSourceArray();
}
this.lightSourcesLock.writeLock().unlock();
}
@@ -211,7 +218,7 @@ public class DynamicLights {
public void clearLightSources() {
this.lightSourcesLock.writeLock().lock();
var dynamicLightSources = this.dynamicLightSources.iterator();
final var dynamicLightSources = this.dynamicLightSources.iterator();
IDynamicLightSource it;
while (dynamicLightSources.hasNext()) {
it = dynamicLightSources.next();
@@ -223,6 +230,7 @@ public class DynamicLights {
}
}
this.lightSourceCount = 0;
this.lightSourceArray = new IDynamicLightSource[0];
this.lightSourcesLock.writeLock().unlock();
}
@@ -234,7 +242,7 @@ public class DynamicLights {
* @return {@code true} if the light source is tracked, else {@code false}
*/
public boolean containsLightSource(@NotNull IDynamicLightSource lightSource) {
boolean result;
final boolean result;
this.lightSourcesLock.readLock().lock();
result = this.dynamicLightSources.contains(lightSource);
this.lightSourcesLock.readLock().unlock();
@@ -247,7 +255,7 @@ public class DynamicLights {
* @return the number of dynamic light sources emitting light
*/
public int getLightSourcesCount() {
int result;
final int result;
this.lightSourcesLock.readLock().lock();
result = this.dynamicLightSources.size();
@@ -259,7 +267,7 @@ public class DynamicLights {
public double getDynamicLightLevel(int x, int y, int z) {
double result = 0;
this.lightSourcesLock.readLock().lock();
for (var lightSource : this.dynamicLightSources) {
for (var lightSource : this.lightSourceArray) {
result = maxDynamicLightLevel(x, y, z, lightSource, result);
}
this.lightSourcesLock.readLock().unlock();
@@ -273,7 +281,7 @@ public class DynamicLights {
public double getDynamicLightLevel(double x, double y, double z) {
double result = 0;
this.lightSourcesLock.readLock().lock();
for (var lightSource : this.dynamicLightSources) {
for (var lightSource : this.lightSourceArray) {
result = maxDynamicLightLevelExact(x, y, z, lightSource, result);
}
this.lightSourcesLock.readLock().unlock();
@@ -286,19 +294,19 @@ public class DynamicLights {
}
public static double maxDynamicLightLevel(int x, int y, int z, @NotNull IDynamicLightSource lightSource, double currentLightLevel) {
int luminance = lightSource.angelica$getLuminance();
final int luminance = lightSource.angelica$getLuminance();
if (luminance > 0) {
// Can't use Entity#squaredDistanceTo because of eye Y coordinate.
double dx = x - lightSource.angelica$getDynamicLightX() + 0.5;
double dy = y - lightSource.angelica$getDynamicLightY() + 0.5;
double dz = z - lightSource.angelica$getDynamicLightZ() + 0.5;
final double dx = x - lightSource.angelica$getDynamicLightX() + 0.5;
final double dy = y - lightSource.angelica$getDynamicLightY() + 0.5;
final double dz = z - lightSource.angelica$getDynamicLightZ() + 0.5;
double distanceSquared = dx * dx + dy * dy + dz * dz;
final double distanceSquared = dx * dx + dy * dy + dz * dz;
// 7.75 because else we would have to update more chunks and that's not a good idea.
// 15 (max range for blocks) would be too much and a bit cheaty.
if (distanceSquared <= MAX_RADIUS_SQUARED) {
double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
double lightLevel = multiplier * (double) luminance;
final double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
final double lightLevel = multiplier * (double) luminance;
if (lightLevel > currentLightLevel) {
return lightLevel;
}
@@ -312,16 +320,16 @@ public class DynamicLights {
* Used for smooth per-vertex lighting.
*/
public static double maxDynamicLightLevelExact(double x, double y, double z, @NotNull IDynamicLightSource lightSource, double currentLightLevel) {
int luminance = lightSource.angelica$getLuminance();
final int luminance = lightSource.angelica$getLuminance();
if (luminance > 0) {
double dx = x - lightSource.angelica$getDynamicLightX();
double dy = y - lightSource.angelica$getDynamicLightY();
double dz = z - lightSource.angelica$getDynamicLightZ();
final double dx = x - lightSource.angelica$getDynamicLightX();
final double dy = y - lightSource.angelica$getDynamicLightY();
final double dz = z - lightSource.angelica$getDynamicLightZ();
double distanceSquared = dx * dx + dy * dy + dz * dz;
final double distanceSquared = dx * dx + dy * dy + dz * dz;
if (distanceSquared <= MAX_RADIUS_SQUARED) {
double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
double lightLevel = multiplier * (double) luminance;
final double multiplier = 1.0 - Math.sqrt(distanceSquared) / MAX_RADIUS;
final double lightLevel = multiplier * (double) luminance;
if (lightLevel > currentLightLevel) {
return lightLevel;
}
@@ -360,11 +368,11 @@ public class DynamicLights {
this.lightSourcesLock.readLock().lock();
try {
for (IDynamicLightSource source : this.dynamicLightSources) {
double dx = source.angelica$getDynamicLightX() - centerX;
double dy = source.angelica$getDynamicLightY() - centerY;
double dz = source.angelica$getDynamicLightZ() - centerZ;
double distSq = dx * dx + dy * dy + dz * dz;
for (var source : this.lightSourceArray) {
final double dx = source.angelica$getDynamicLightX() - centerX;
final double dy = source.angelica$getDynamicLightY() - centerY;
final double dz = source.angelica$getDynamicLightZ() - centerZ;
final double distSq = dx * dx + dy * dy + dz * dz;
if (distSq <= searchRadiusSq) {
if (result == null) {
@@ -380,6 +388,53 @@ public class DynamicLights {
return result != null ? result : Collections.emptyList();
}
public int getDynamicLightRGB(double x, double y, double z) {
int accum = 0;
this.lightSourcesLock.readLock().lock();
try {
for (var lightSource : this.lightSourceArray) {
accum = accumulateSourceRGB(x, y, z, lightSource, accum);
}
} finally {
this.lightSourcesLock.readLock().unlock();
}
return accum;
}
public int getDynamicLightRGBFromSources(double x, double y, double z, List<IDynamicLightSource> sources) {
if (sources == null || sources.isEmpty()) return 0;
int accum = 0;
for (int i = 0, size = sources.size(); i < size; i++) {
accum = accumulateSourceRGB(x, y, z, sources.get(i), accum);
}
return accum;
}
private static int accumulateSourceRGB(double x, double y, double z, IDynamicLightSource source, int accum) {
final int luminance = source.angelica$getLuminance();
if (luminance <= 0) return accum;
final int rgb = source.angelica$getLuminanceRGB();
if (rgb == 0) return accum;
final double dx = x - source.angelica$getDynamicLightX();
final double dy = y - source.angelica$getDynamicLightY();
final double dz = z - source.angelica$getDynamicLightZ();
final double distSq = dx * dx + dy * dy + dz * dz;
if (distSq > MAX_RADIUS_SQUARED) return accum;
final double multiplier = 1.0 - Math.sqrt(distSq) / MAX_RADIUS;
final int r = (int) (BlockLightProvider.unpackR(rgb) * multiplier);
final int g = (int) (BlockLightProvider.unpackG(rgb) * multiplier);
final int b = (int) (BlockLightProvider.unpackB(rgb) * multiplier);
return BlockLightProvider.packRGB(
Math.max(BlockLightProvider.unpackR(accum), r),
Math.max(BlockLightProvider.unpackG(accum), g),
Math.max(BlockLightProvider.unpackB(accum), b));
}
public double getDynamicLightLevelFromSources(double x, double y, double z, List<IDynamicLightSource> sources) {
if (sources == null || sources.isEmpty()) {
return 0;
@@ -403,10 +458,10 @@ public class DynamicLights {
// lightmap is (skyLevel << 20 | blockLevel << 4)
// Get vanilla block light level.
int blockLevel = (lightmap & 0xFFFF) >> 4;
final int blockLevel = (lightmap & 0xFFFF) >> 4;
if (dynamicLightLevel > blockLevel) {
// Equivalent to a << 4 bitshift with a little quirk: this one ensure more precision (more decimals are saved).
int luminance = (int) (dynamicLightLevel * 16.0);
final int luminance = (int) (dynamicLightLevel * 16.0);
lightmap &= 0xfff00000;
lightmap |= luminance & 0x000fffff;
}
@@ -485,8 +540,8 @@ public class DynamicLights {
* @param lightSource the light source
*/
public static void updateTracking(@NotNull IDynamicLightSource lightSource) {
boolean enabled = lightSource.angelica$isDynamicLightEnabled();
int luminance = lightSource.angelica$getLuminance();
final boolean enabled = lightSource.angelica$isDynamicLightEnabled();
final int luminance = lightSource.angelica$getLuminance();
if (!enabled && luminance > 0) {
lightSource.angelica$setDynamicLightEnabled(true);
@@ -503,9 +558,9 @@ public class DynamicLights {
* @return the luminance of the item
*/
public static int getLuminanceFromItemStack(@NotNull ItemStack stack) {
Item item = stack.getItem();
final Item item = stack.getItem();
if (item instanceof ItemBlock itemBlock) {
Block block = itemBlock.field_150939_a;
final Block block = itemBlock.field_150939_a;
if (block != null) {
return block.getLightValue();
}
@@ -522,7 +577,7 @@ public class DynamicLights {
if (entity.isBurning()) return 15;
boolean inWater = entity.isInsideOfMaterial(Material.water);
final boolean inWater = entity.isInsideOfMaterial(Material.water);
// TODO only have certain items not glow in water?
if (inWater) return 0;
@@ -547,23 +602,23 @@ public class DynamicLights {
player instanceof IBattlePlayer battlePlayer &&
battlePlayer.battlegear2$isBattlemode()
) {
ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
final ItemStack offhand = Battlegear2Compat.getBattlegear2Offhand(player);
if (offhand != null) {
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand));
}
}
else if (ModStatus.isBackhandLoaded){
ItemStack offhand = BackhandReflectionCompat.getOffhandItem(player);
final ItemStack offhand = BackhandReflectionCompat.getOffhandItem(player);
if (offhand != null) {
luminance = Math.max(luminance, getLuminanceFromItemStack(offhand));
}
}
if (ModStatus.isBaublesLoaded){
var playerBaubles = PlayerHandler.getPlayerBaubles(player);
final var playerBaubles = PlayerHandler.getPlayerBaubles(player);
if (playerBaubles != null){
for (int i = 0; i < playerBaubles.getSizeInventory(); i++){
var stack = playerBaubles.getStackInSlot(i);
final var stack = playerBaubles.getStackInSlot(i);
if (stack != null){
luminance = Math.max(luminance, getLuminanceFromItemStack(stack));
}
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.dynamiclights;
import com.gtnewhorizons.angelica.api.BlockLightProvider;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -78,4 +79,13 @@ public interface IDynamicLightSource {
boolean angelica$updateDynamicLight(@NotNull IDynamicLightWorldRenderer renderer);
void angelica$scheduleTrackedChunksRebuild(@NotNull IDynamicLightWorldRenderer renderer);
/**
* Returns the RGB luminance of the light source. Each channel 0-15, packed as {@code (r << 8) | (g << 4) | b}.
* Default implementation returns white light at the scalar luminance level.
*/
default int angelica$getLuminanceRGB() {
final int l = angelica$getLuminance();
return BlockLightProvider.packRGB(l, l, l);
}
}
@@ -3,6 +3,7 @@ package com.gtnewhorizons.angelica.mixins;
import com.gtnewhorizon.gtnhmixins.builders.IMixins;
import com.gtnewhorizon.gtnhmixins.builders.MixinBuilder;
import com.gtnewhorizons.angelica.AngelicaMod;
import com.gtnewhorizons.angelica.api.BlockLightProvider;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.config.CompatConfig;
import jss.notfine.config.MCPatcherForgeConfig;
@@ -214,6 +215,22 @@ public enum Mixins implements IMixins {
)
),
CELERITAS_COLORED_LIGHT(new MixinBuilder("Colored light infrastructure for celeritas light pipeline")
.setPhase(Phase.EARLY)
.setApplyIf(() -> {
BlockLightProvider.freezeMixinConfig();
return AngelicaConfig.enableCeleritas && BlockLightProvider.coloredLightEnabled();
})
.addClientMixins(
"celeritas.light.MixinQuadLightData",
"celeritas.light.MixinLightDataAccess",
"celeritas.light.MixinLightDataCache",
"celeritas.light.MixinAoFaceData",
"celeritas.light.MixinSmoothLightPipeline",
"celeritas.light.MixinFlatLightPipeline"
)
),
IRIS_SHADERS(new MixinBuilder()
.setPhase(Phase.EARLY)
.setApplyIf(() -> AngelicaConfig.enableIris)
@@ -698,7 +715,7 @@ public enum Mixins implements IMixins {
private final MixinBuilder builder;
private static String[] addPrefix(String prefix, String... values) {
List<String> list = new ArrayList<>(values.length);
final List<String> list = new ArrayList<>(values.length);
for (String s : values) {
list.add(prefix + s);
}
@@ -46,9 +46,12 @@ import net.coderbot.iris.Iris;
import net.coderbot.iris.client.IrisDebugScreenHandler;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiVideoSettings;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
@@ -164,6 +167,8 @@ public class ClientProxy extends CommonProxy {
@SubscribeEvent
public void onKeypress(TickEvent.ClientTickEvent event) {
if (event.phase != TickEvent.Phase.END) return;
final boolean isPressed = glsmKeyBinding.getKeyCode() != 0 && GameSettings.isKeyDown(glsmKeyBinding);
if (isPressed && !wasGLSMKeyPressed) {
OpenGLDebugging.checkGLSM();
@@ -177,7 +182,7 @@ public class ClientProxy extends CommonProxy {
if (ModStatus.isLotrLoaded && AngelicaConfig.enableCeleritas && CompatConfig.fixLotr) {
try {
Class<?> lotrRendering = Class.forName("lotr.common.coremod.LOTRReplacedMethods$BlockRendering");
final Class<?> lotrRendering = Class.forName("lotr.common.coremod.LOTRReplacedMethods$BlockRendering");
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "naturalBlockClassTable");
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "naturalBlockTable");
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "cachedNaturalBlocks");
@@ -192,9 +197,9 @@ public class ClientProxy extends CommonProxy {
@SubscribeEvent
public void onTick(TickEvent.ServerTickEvent event) {
if (FMLCommonHandler.instance().getSide().isClient() && event.phase == TickEvent.Phase.END) {
IntegratedServer srv = Minecraft.getMinecraft().getIntegratedServer();
final IntegratedServer srv = Minecraft.getMinecraft().getIntegratedServer();
if (srv != null) {
long currentTickTime = srv.tickTimeArray[srv.getTickCounter() % 100];
final long currentTickTime = srv.tickTimeArray[srv.getTickCounter() % 100];
lastIntegratedTickTime = lastIntegratedTickTime * 0.8F + (float) currentTickTime / 1000000.0F * 0.2F;
} else lastIntegratedTickTime = 0;
}
@@ -211,30 +216,30 @@ public class ClientProxy extends CommonProxy {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onRenderOverlay(RenderGameOverlayEvent.Text event) {
Minecraft mc = Minecraft.getMinecraft();
if (!mc.gameSettings.showDebugInfo || event.left.isEmpty()) return;
final Minecraft mc = Minecraft.getMinecraft();
if (event.isCanceled() || !mc.gameSettings.showDebugInfo || event.left.isEmpty()) return;
NetHandlerPlayClient cl = mc.getNetHandler();
final NetHandlerPlayClient cl = mc.getNetHandler();
if (cl != null) {
IntegratedServer srv = mc.getIntegratedServer();
final IntegratedServer srv = mc.getIntegratedServer();
if (srv != null) {
String s = String.format("Integrated server @ %.0f ms ticks", lastIntegratedTickTime);
final String s = String.format("Integrated server @ %.0f ms ticks", lastIntegratedTickTime);
event.left.add(Math.min(event.left.size(), 1), s);
}
}
if (AngelicaConfig.showBlockDebugInfo && mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
if (!event.right.isEmpty() && !Objects.firstNonNull(event.right.get(event.right.size() - 1), "").isEmpty()) event.right.add("");
Block block = mc.theWorld.getBlock(mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, mc.objectMouseOver.blockZ);
int meta = mc.theWorld.getBlockMetadata(mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, mc.objectMouseOver.blockZ);
final Block block = mc.theWorld.getBlock(mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, mc.objectMouseOver.blockZ);
final int meta = mc.theWorld.getBlockMetadata(mc.objectMouseOver.blockX, mc.objectMouseOver.blockY, mc.objectMouseOver.blockZ);
event.right.add(Block.blockRegistry.getNameForObject(block));
event.right.add("meta: " + meta);
}
if (DynamicLights.isEnabled()) {
var builder = new StringBuilder("Dynamic Light Sources: ");
DynamicLights dl = DynamicLights.get();
final var builder = new StringBuilder("Dynamic Light Sources: ");
final DynamicLights dl = DynamicLights.get();
builder.append(dl.getLightSourcesCount()).append(" (U: ").append(dl.getLastUpdateCount()).append(')');
event.right.add(builder.toString());
@@ -248,8 +253,8 @@ public class ClientProxy extends CommonProxy {
.startsWith("y:") && Objects.firstNonNull(event.left.get(i + 2), "").startsWith("z:") && Objects.firstNonNull(event.left.get(i + 3), "")
.startsWith("f:")) {
hasReplacedXYZ = true;
int heading = MathHelper.floor_double((double) (mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
String heading_str = switch (heading) {
final int heading = MathHelper.floor_double((double) (mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
final String heading_str = switch (heading) {
case 0 -> "Towards positive Z";
case 1 -> "Towards negative X";
case 2 -> "Towards negative Z";
@@ -257,9 +262,9 @@ public class ClientProxy extends CommonProxy {
default -> throw new RuntimeException();
};
event.left.set(i, String.format("XYZ: %.3f / %.5f / %.3f", mc.thePlayer.posX, mc.thePlayer.boundingBox.minY, mc.thePlayer.posZ));
int bX = MathHelper.floor_double(mc.thePlayer.posX);
int bY = MathHelper.floor_double(mc.thePlayer.boundingBox.minY);
int bZ = MathHelper.floor_double(mc.thePlayer.posZ);
final int bX = MathHelper.floor_double(mc.thePlayer.posX);
final int bY = MathHelper.floor_double(mc.thePlayer.boundingBox.minY);
final int bZ = MathHelper.floor_double(mc.thePlayer.posZ);
event.left.set(i + 1, String.format("Block: %d %d %d [%d %d %d]", bX, bY, bZ, bX & 15, bY & 15, bZ & 15));
event.left.set(i + 2, String.format("Chunk: %d %d %d", bX >> 4, bY >> 4, bZ >> 4));
event.left.set(
@@ -270,15 +275,14 @@ public class ClientProxy extends CommonProxy {
MathHelper.wrapAngleTo180_float(mc.thePlayer.rotationYaw),
MathHelper.wrapAngleTo180_float(mc.thePlayer.rotationPitch)));
Chunk chunk = this.mc.theWorld.getChunkFromBlockCoords(bX, bZ);
event.left.set(
i + 4, String.format(
"lc: %d b: %s bl: %d sl: %d rl: %d",
chunk.getTopFilledSegment() + 15,
chunk.getBiomeGenForWorldCoords(bX & 15, bZ & 15, mc.theWorld.getWorldChunkManager()).biomeName,
chunk.getSavedLightValue(EnumSkyBlock.Block, bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15),
chunk.getSavedLightValue(EnumSkyBlock.Sky, bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15),
chunk.getBlockLightValue(bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15, 0)));
final Chunk chunk = this.mc.theWorld.getChunkFromBlockCoords(bX, bZ);
event.left.set(i + 4, String.format(
"lc: %d b: %s bl: %d sl: %d rl: %d",
chunk.getTopFilledSegment() + 15,
chunk.getBiomeGenForWorldCoords(bX & 15, bZ & 15, mc.theWorld.getWorldChunkManager()).biomeName,
chunk.getSavedLightValue(EnumSkyBlock.Block, bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15),
chunk.getSavedLightValue(EnumSkyBlock.Sky, bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15),
chunk.getBlockLightValue(bX & 15, MathHelper.clamp_int(bY, 0, 255), bZ & 15, 0)));
}
}
// Draw a frametime graph
@@ -1,6 +1,9 @@
package com.gtnewhorizons.angelica.rendering.celeritas;
import com.gtnewhorizons.angelica.AngelicaMod;
import com.gtnewhorizons.angelica.api.ExtQuadLightData;
import com.gtnewhorizons.angelica.api.TintComputer;
import com.gtnewhorizons.angelica.api.TintRegistry;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import com.gtnewhorizons.angelica.dynamiclights.IDynamicLightSource;
import com.gtnewhorizons.angelica.rendering.StateAwareTessellator;
@@ -17,8 +20,8 @@ import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import org.embeddedt.embeddium.api.util.ColorABGR;
import org.embeddedt.embeddium.impl.model.light.LightPipeline;
import org.embeddedt.embeddium.impl.model.light.data.LightDataAccess;
import org.embeddedt.embeddium.impl.model.light.data.QuadLightData;
import org.embeddedt.embeddium.impl.model.light.flat.FlatLightPipeline;
import org.embeddedt.embeddium.impl.model.light.smooth.SmoothLightPipeline;
@@ -33,7 +36,6 @@ import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material;
import org.embeddedt.embeddium.impl.render.chunk.vertex.format.ChunkVertexEncoder;
import org.embeddedt.embeddium.impl.util.QuadUtil;
import java.util.Arrays;
import java.util.List;
public class AngelicaChunkBuildContext extends ChunkBuildContext {
@@ -56,7 +58,8 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
private final VertexArrayQuadView quadView;
private boolean lightPipelineReady = false;
private int originX, originY, originZ;
private IBlockAccess blockAccess;
private float cachedSkylightSubtracted;
private final boolean hasColoredLight;
public AngelicaChunkBuildContext(RenderPassConfiguration<?> renderPassConfiguration, WorldClient world) {
super(renderPassConfiguration);
@@ -65,6 +68,7 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
this.smoothLightPipeline = new SmoothLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false);
this.flatLightPipeline = new FlatLightPipeline(lightDataCache, VanillaDiffuseProvider.INSTANCE, false);
this.quadView = new VertexArrayQuadView(vertices);
this.hasColoredLight = quadLightData instanceof ExtQuadLightData;
}
public void setupLightPipeline(int minBlockX, int minBlockY, int minBlockZ) {
@@ -72,7 +76,6 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
}
public void setupLightPipeline(IBlockAccess blockAccess, int minBlockX, int minBlockY, int minBlockZ) {
this.blockAccess = blockAccess;
this.originX = minBlockX;
this.originY = minBlockY;
this.originZ = minBlockZ;
@@ -81,6 +84,7 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
smoothLightPipeline.reset();
flatLightPipeline.reset();
lightPipelineReady = true;
cachedSkylightSubtracted = Minecraft.getMinecraft().theWorld.skylightSubtracted;
}
public void setupDynamicLights(int chunkOriginX, int chunkOriginY, int chunkOriginZ) {
@@ -219,10 +223,13 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
}
}
// Apply RGB block light tint from provider
applyBlockLightTint(worldX, worldY, worldZ, vertices);
final int faceBit = 1 << facing.ordinal();
final Material correctMaterial;
if ((facesAtBaseMaterial & faceBit) != 0) {
// Face already has a non-demoted quad — skip selectMaterial entirely
// Face already has a non-demoted quad, skip selectMaterial entirely
correctMaterial = material;
} else {
correctMaterial = selectMaterial(material, sprite, isShaderPackOverride);
@@ -239,4 +246,50 @@ public class AngelicaChunkBuildContext extends ChunkBuildContext {
builder.getVertexBuffer(facing).push(vertices, correctMaterial);
}
}
private final float[] tintResult = new float[3];
private void applyBlockLightTint(int x, int y, int z, ChunkVertexEncoder.Vertex[] vertices) {
if (!hasColoredLight) return;
final ExtQuadLightData ext = (ExtQuadLightData) quadLightData;
final boolean hasBlock = ext.angelica$isRGBValid();
final boolean hasSky = ext.angelica$isSkyRGBValid();
if (!hasBlock && !hasSky) return;
if (hasBlock) ext.angelica$setRGBValid(false);
if (hasSky) ext.angelica$setSkyRGBValid(false);
final float[] blockR = hasBlock ? ext.angelica$getR() : null;
final float[] blockG = hasBlock ? ext.angelica$getG() : null;
final float[] blockB = hasBlock ? ext.angelica$getB() : null;
final float[] skyR = hasSky ? ext.angelica$getSkyR() : null;
final float[] skyG = hasSky ? ext.angelica$getSkyG() : null;
final float[] skyB = hasSky ? ext.angelica$getSkyB() : null;
final float sub = cachedSkylightSubtracted;
final TintComputer tintComputer = TintRegistry.getCurrent();
for (int i = 0; i < 4; i++) {
final float br = hasBlock ? blockR[i] : 0;
final float bg = hasBlock ? blockG[i] : 0;
final float bb = hasBlock ? blockB[i] : 0;
final float sr = hasSky ? Math.max(0, skyR[i] - sub) : 0;
final float sg = hasSky ? Math.max(0, skyG[i] - sub) : 0;
final float sb = hasSky ? Math.max(0, skyB[i] - sub) : 0;
// Fast-path: full white sky with no block light, no tint needed
if (br == 0 && bg == 0 && bb == 0 && sr >= 15f && sg >= 15f && sb >= 15f) continue;
tintComputer.computeTint(br, bg, bb, sr, sg, sb, tintResult);
final float rTint = tintResult[0];
final float gTint = tintResult[1];
final float bTint = tintResult[2];
if (rTint >= 1.0f && gTint >= 1.0f && bTint >= 1.0f) continue;
final int color = vertices[i].color;
final int vr = Math.min(255, (int) (ColorABGR.unpackRed(color) * rTint));
final int vg = Math.min(255, (int) (ColorABGR.unpackGreen(color) * gTint));
final int vb = Math.min(255, (int) (ColorABGR.unpackBlue(color) * bTint));
vertices[i].color = ColorABGR.pack(vr, vg, vb, ColorABGR.unpackAlpha(color));
}
}
}
@@ -0,0 +1,85 @@
package com.gtnewhorizons.angelica.rendering.celeritas.compat;
import org.embeddedt.embeddium.impl.model.quad.properties.ModelQuadFacing;
/**
* Inlined data from package-private {@code AoNeighborInfo} -- edge face directions,
* bilinear corner weight formulas, and depth formulas per face direction.
*/
public final class AoHelper {
private static final ModelQuadFacing[][] FACES = {
{ ModelQuadFacing.NEG_Y, ModelQuadFacing.POS_Y, ModelQuadFacing.NEG_Z, ModelQuadFacing.POS_Z }, // POS_X
{ ModelQuadFacing.POS_X, ModelQuadFacing.NEG_X, ModelQuadFacing.NEG_Z, ModelQuadFacing.POS_Z }, // POS_Y
{ ModelQuadFacing.NEG_X, ModelQuadFacing.POS_X, ModelQuadFacing.NEG_Y, ModelQuadFacing.POS_Y }, // POS_Z
{ ModelQuadFacing.POS_Y, ModelQuadFacing.NEG_Y, ModelQuadFacing.NEG_Z, ModelQuadFacing.POS_Z }, // NEG_X
{ ModelQuadFacing.NEG_X, ModelQuadFacing.POS_X, ModelQuadFacing.NEG_Z, ModelQuadFacing.POS_Z }, // NEG_Y
{ ModelQuadFacing.POS_Y, ModelQuadFacing.NEG_Y, ModelQuadFacing.POS_X, ModelQuadFacing.NEG_X }, // NEG_Z
};
/**
* Corner remap table derived from each AoNeighborInfo.mapCorners.
* remap[outIdx] = inIdx.
*/
public static final int[][] CORNER_REMAP = {
{ 3, 0, 1, 2 }, // POS_X
{ 2, 3, 0, 1 }, // POS_Y
{ 0, 1, 2, 3 }, // POS_Z
{ 1, 2, 3, 0 }, // NEG_X
{ 0, 1, 2, 3 }, // NEG_Y
{ 1, 2, 3, 0 }, // NEG_Z
};
private AoHelper() {}
public static ModelQuadFacing[] getFaces(ModelQuadFacing direction) {
return FACES[direction.ordinal()];
}
public static void calculateCornerWeights(ModelQuadFacing direction, float x, float y, float z, float[] out) {
final float u, v;
switch (direction) {
case POS_X -> {
u = z;
v = 1.0f - y;
}
case POS_Y -> {
u = z;
v = x;
}
case POS_Z -> {
u = y;
v = 1.0f - x;
}
case NEG_X -> {
u = z;
v = y;
}
case NEG_Y -> {
u = z;
v = 1.0f - x;
}
case NEG_Z -> {
u = 1.0f - x;
v = y;
}
default -> throw new IllegalArgumentException();
}
out[0] = v * u;
out[1] = v * (1.0f - u);
out[2] = (1.0f - v) * (1.0f - u);
out[3] = (1.0f - v) * u;
}
public static float getDepth(ModelQuadFacing direction, float x, float y, float z) {
return switch (direction) {
case POS_X -> 1.0f - x;
case POS_Y -> 1.0f - y;
case POS_Z -> 1.0f - z;
case NEG_X -> x;
case NEG_Y -> y;
case NEG_Z -> z;
default -> throw new IllegalArgumentException();
};
}
}
@@ -1,5 +1,6 @@
package com.gtnewhorizons.angelica.rendering.celeritas.world;
import com.gtnewhorizons.angelica.api.SectionLightData;
import com.gtnewhorizons.angelica.api.IBlockAccessExtended;
import com.gtnewhorizons.angelica.compat.ModStatus;
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
@@ -84,11 +85,14 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
// Local Section->Light table
private final NibbleArray[][] lightArrays;
// Per-section RGB light data (captured from BlockLightProvider on main thread)
private final SectionLightData[] sectionLightData;
// Local section copies
private ClonedChunkSection[] sections;
// Biome data for each chunk section
private BiomeGenBase[][] biomeData;
private final BiomeGenBase[][] biomeData;
// The starting point from which this slice captures blocks
private int baseX, baseY, baseZ;
@@ -158,6 +162,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
this.metadataArrays = new int[SECTION_TABLE_ARRAY_SIZE][];
this.biomeData = new BiomeGenBase[SECTION_TABLE_ARRAY_SIZE][];
this.lightArrays = new NibbleArray[SECTION_TABLE_ARRAY_SIZE][LIGHT_TYPES.length];
this.sectionLightData = new SectionLightData[SECTION_TABLE_ARRAY_SIZE];
if (ModStatus.isFluidLoggedLoaded) {
this.fluidArrays = new Fluid[SECTION_TABLE_ARRAY_SIZE][];
@@ -220,6 +225,7 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
this.lightArrays[idx][EnumSkyBlock.Block.ordinal()] = section.getLightArray(EnumSkyBlock.Block);
this.lightArrays[idx][EnumSkyBlock.Sky.ordinal()] = section.getLightArray(EnumSkyBlock.Sky);
this.sectionLightData[idx] = section.getSectionLightData();
}
}
}
@@ -380,6 +386,24 @@ public class WorldSlice implements IBlockAccessExtended, FLBlockAccess {
return lightArray.get(relX & 15, relY & 15, relZ & 15);
}
public SectionLightData getSectionLightData(int x, int y, int z) {
if (!blockBoxContains(this.volume, x, y, z)) {
return null;
}
final int relX = x - this.baseX;
final int relY = y - this.baseY;
final int relZ = z - this.baseZ;
return this.sectionLightData[getLocalSectionIndex(relX >> 4, relY >> 4, relZ >> 4)];
}
public List<IDynamicLightSource> getChunkLightSources() {
return chunkLightSources;
}
public DynamicLights getDynamicLightsInstance() {
return dynamicLightsInstance;
}
@Override
public World getWorld() {
return this.world;
@@ -1,6 +1,8 @@
package com.gtnewhorizons.angelica.rendering.celeritas.world.cloned;
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
import com.gtnewhorizons.angelica.api.BlockLightProvider;
import com.gtnewhorizons.angelica.api.SectionLightData;
import com.gtnewhorizons.angelica.compat.ExtendedBlockStorageExt;
import com.gtnewhorizons.angelica.compat.ModStatus;
import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos;
@@ -33,6 +35,7 @@ public class ClonedChunkSection {
private ChunkSectionPos pos;
private ExtendedBlockStorageExt data;
private BiomeGenBase[] biomeData;
private SectionLightData sectionLightData;
private final Short2ObjectOpenHashMap<TileEntity> tileEntities;
private long lastUsedTimestamp = Long.MAX_VALUE;
@@ -75,6 +78,8 @@ public class ClonedChunkSection {
this.biomeData[(x & 15) | ((z & 15) << 4)] = world.getBiomeGenForCoords(x, z);
}
}
this.sectionLightData = BlockLightProvider.getInstance().prepareSectionData(chunk, pos.y);
}
@SuppressWarnings("unchecked")
@@ -127,6 +132,10 @@ public class ClonedChunkSection {
return data.getBlocklightArray();
}
public SectionLightData getSectionLightData() {
return this.sectionLightData;
}
public BiomeGenBase[] getBiomeData() {
return this.biomeData;
}
@@ -100,6 +100,10 @@ public class SodiumGameOptions {
config.configPath = path;
if (config.advanced.streamingUploadStrategy == null) {
config.advanced.streamingUploadStrategy = StreamingUploader.UploadStrategy.MAP_BUFFER_RANGE;
}
// Clamp render-ahead to 0 if GL 3.2 fences aren't available
if (GLStateManager.capabilities == null || !GLStateManager.capabilities.OpenGL32) {
config.performance.cpuRenderAheadLimit = 0;