Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
implementation("dev.redstudio:Red-Core-MC:$redCoreVersion")

compileOnly(rfg.deobf("curse.maven:dynamic-lights-227874:2563244"))
compileOnly(rfg.deobf("curse.maven:fluidlogged-api-485654:3697254")) // Earliest support version (v1.7)

annotationProcessor("org.ow2.asm:asm-debug-all:5.2")
annotationProcessor("com.google.guava:guava:32.1.2-jre")
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/redstudio/alfheim/Alfheim.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class Alfheim {
public static final byte FLAG_COUNT = 32;

public static final boolean IS_DYNAMIC_LIGHTS_LOADED = Loader.isModLoaded("dynamiclights");
public static final boolean IS_FLUIDLOGGED_API_LOADED = Loader.isModLoaded("fluidlogged_api");
public static final boolean IS_NOTHIRIUM_LOADED = Loader.isModLoaded("nothirium");
public static final boolean IS_VINTAGIUM_LOADED = Loader.isModLoaded("vintagium");
public static final boolean IS_CELERITAS_LOADED = Loader.isModLoaded("celeritas");
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/dev/redstudio/alfheim/lighting/LightUtil.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
package dev.redstudio.alfheim.lighting;

import atomicstryker.dynamiclights.client.DynamicLights;
import git.jbredwards.fluidlogged_api.api.util.FluidState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.chunk.Chunk;

import static dev.redstudio.alfheim.Alfheim.IS_DYNAMIC_LIGHTS_LOADED;
import static dev.redstudio.alfheim.Alfheim.IS_FLUIDLOGGED_API_LOADED;

/// @author Luna Mira Lage (Desoroxxx)
/// @author embeddedt
/// @since 1.0
public final class LightUtil {

public static int getLightOpacityForPos(final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos, final Chunk chunk) {
if (IS_FLUIDLOGGED_API_LOADED) {
// Check Fluidlogged API FluidState
final int fluidStateOpacity = FluidState.getFromProvider(chunk, blockPos).getState().getLightOpacity(blockAccess, blockPos);
return Math.max(fluidStateOpacity, blockState.getLightOpacity(blockAccess, blockPos));
} else {
return blockState.getLightOpacity(blockAccess, blockPos);
}
}

public static int getLightValueForPos(final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos, final Chunk chunk) {
if (IS_FLUIDLOGGED_API_LOADED) {
// Check Fluidlogged API FluidState
final int fluidStateLight = FluidState.getFromProvider(chunk, blockPos).getState().getLightValue(blockAccess, blockPos);
return Math.max(fluidStateLight, getLightValueForState(blockState, blockAccess, blockPos));
} else {
return getLightValueForState(blockState, blockAccess, blockPos);
}
}

public static int getLightValueForState(final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos) {
if (IS_DYNAMIC_LIGHTS_LOADED) {
return DynamicLights.getLightValue(blockState.getBlock(), blockState, blockAccess, blockPos); // Use the Dynamic Lights implementation
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/dev/redstudio/alfheim/lighting/LightingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ private void processLightUpdatesForTypeInner(final EnumSkyBlock lightType, final
continue;

final IBlockState blockState = currentChunk.getBlockState(currentPos);
final byte luminosity = getCursorLuminosity(blockState, lightType);
final byte luminosity = getCursorLuminosity(blockState, lightType, currentChunk);
final byte opacity; // If luminosity is high enough, opacity is irrelevant

if (luminosity >= MAX_LIGHT_LEVEL - 1) {
opacity = 1;
} else {
opacity = getPosOpacity(currentPos, blockState);
opacity = getPosOpacity(currentPos, blockState, currentChunk);
}

// Only darken neighbors if we indeed became darker
Expand All @@ -311,7 +311,7 @@ private void processLightUpdatesForTypeInner(final EnumSkyBlock lightType, final

final MutableBlockPos neighborPos = neighborInfo.mutableBlockPos;

if (currentLight - getPosOpacity(neighborPos, neighborChunk.getBlockState(neighborPos)) >= neighborLight) /*Schedule neighbor for darkening if we possibly light it*/ {
if (currentLight - getPosOpacity(neighborPos, neighborChunk.getBlockState(neighborPos), neighborChunk) >= neighborLight) /*Schedule neighbor for darkening if we possibly light it*/ {
enqueueDarkening(neighborPos, neighborInfo.key, neighborLight, neighborChunk, lightType);
} else /*Only use for new light calculation if not*/ {
// If we can't darken the neighbor, no one else can (because of processing order) -> safe to let us be illuminated by it
Expand Down Expand Up @@ -402,13 +402,13 @@ private static byte getCachedLightFor(final Chunk chunk, final ExtendedBlockStor
private byte calculateNewLightFromCursor(final EnumSkyBlock lightType) {
final IBlockState blockState = currentChunk.getBlockState(currentPos);

final byte luminosity = getCursorLuminosity(blockState, lightType);
final byte luminosity = getCursorLuminosity(blockState, lightType, currentChunk);
final byte opacity;

if (luminosity >= MAX_LIGHT_LEVEL - 1) {
opacity = 1;
} else {
opacity = getPosOpacity(currentPos, blockState);
opacity = getPosOpacity(currentPos, blockState, currentChunk);
}

return calculateNewLightFromCursor(luminosity, opacity, lightType);
Expand Down Expand Up @@ -443,7 +443,7 @@ private void spreadLightFromCursor(final byte currentLight, final EnumSkyBlock l

final BlockPos neighborBlockPos = neighborInfo.mutableBlockPos;

final byte newLight = (byte) (currentLight - getPosOpacity(neighborBlockPos, neighborChunk.getBlockState(neighborBlockPos)));
final byte newLight = (byte) (currentLight - getPosOpacity(neighborBlockPos, neighborChunk.getBlockState(neighborBlockPos), neighborChunk));

if (newLight > neighborInfo.light)
enqueueBrightening(neighborBlockPos, neighborInfo.key, newLight, neighborChunk, lightType);
Expand Down Expand Up @@ -506,15 +506,15 @@ private byte getCursorCachedLight(final EnumSkyBlock lightType) {
}

/// Calculates the luminosity for [#currentPos], taking into account the light type
private byte getCursorLuminosity(final IBlockState state, final EnumSkyBlock lightType) {
private byte getCursorLuminosity(final IBlockState state, final EnumSkyBlock lightType, final Chunk chunk) {
if (lightType == EnumSkyBlock.SKY)
return currentChunk.canSeeSky(currentPos) ? (byte) EnumSkyBlock.SKY.defaultLightValue : 0;

return (byte) ClampUtil.clampMinFirst(LightUtil.getLightValueForState(state, world, currentPos), 0, MAX_LIGHT_LEVEL);
return (byte) ClampUtil.clampMinFirst(LightUtil.getLightValueForPos(state, world, currentPos, chunk), 0, MAX_LIGHT_LEVEL);
}

private byte getPosOpacity(final BlockPos blockPos, final IBlockState blockState) {
return (byte) ClampUtil.clampMinFirst(blockState.getLightOpacity(world, blockPos), 1, MAX_LIGHT_LEVEL);
private byte getPosOpacity(final BlockPos blockPos, final IBlockState blockState, final Chunk chunk) {
return (byte) ClampUtil.clampMinFirst(LightUtil.getLightOpacityForPos(blockState, world, blockPos, chunk), 1, MAX_LIGHT_LEVEL);
}

private Chunk getChunk(final BlockPos blockPos) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/redstudio/alfheim/mixin/ChunkMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ private int fakeGetLightFor(final Chunk chunk, final EnumSkyBlock lightType, fin
for (int x = 0; x < 16; x++) {
mutableBlockPos.setPos(xBase + x, yBase + y, zBase + z);

if (LightUtil.getLightValueForState(storage.getData().get(x, y, z), world, mutableBlockPos) > 0) {
if (LightUtil.getLightValueForPos(storage.getData().get(x, y, z), world, mutableBlockPos, chunk) > 0) {
world.checkLightFor(EnumSkyBlock.BLOCK, mutableBlockPos);
}
}
Expand Down
Loading