Skip to content

Commit b2e26ac

Browse files
committed
Adjust entity lighting mixins
1 parent 836e920 commit b2e26ac

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/mixin/entity/entity_rendering/EntityRendererMixin.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.ryanhcode.sable.mixin.entity.entity_rendering;
22

3+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
34
import dev.ryanhcode.sable.Sable;
4-
import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil;
55
import dev.ryanhcode.sable.companion.math.BoundingBox3d;
66
import dev.ryanhcode.sable.companion.math.JOMLConversion;
77
import dev.ryanhcode.sable.sublevel.ClientSubLevel;
@@ -35,35 +35,32 @@ public abstract class EntityRendererMixin {
3535
@Final
3636
protected EntityRenderDispatcher entityRenderDispatcher;
3737

38-
/**
39-
* @author RyanH
40-
* @reason Account for sub-levels with sky lighting
41-
*/
42-
@Overwrite
43-
public final int getPackedLightCoords(final Entity arg, final float f) {
38+
@ModifyReturnValue(method = "getPackedLightCoords", at = @At("RETURN"))
39+
public final int getPackedLightCoords(final int original, final Entity arg, final float f) {
4440
final Vec3 lightProbeOffset = arg.getLightProbePosition(f).subtract(arg.getEyePosition(f));
4541
final Vector3d lightProbePosition = JOMLConversion.toJOML(Sable.HELPER.getEyePositionInterpolated(arg, f)).add(lightProbeOffset.x, lightProbeOffset.y, lightProbeOffset.z);
4642
final BlockPos blockpos = BlockPos.containing(lightProbePosition.x, lightProbePosition.y, lightProbePosition.z);
47-
return LightTexture.pack(sable$getSubLevelAccountedBlockLight(arg.level(), LightLayer.BLOCK, blockpos, lightProbePosition), sable$getSubLevelAccountedLight(arg.level(), LightLayer.SKY, blockpos, lightProbePosition));
43+
return LightTexture.pack(sable$getSubLevelAccountedBlockLight(original, arg.level(), LightLayer.BLOCK, blockpos, lightProbePosition),
44+
sable$getSubLevelAccountedSkyLight(original, arg.level(), LightLayer.SKY, blockpos, lightProbePosition));
4845
}
4946

5047
@Redirect(method = "getSkyLightLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBrightness(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/BlockPos;)I"))
5148
private int sable$getSkyLightLevel(final Level instance, final LightLayer lightLayer, final BlockPos blockPos) {
52-
return sable$getSubLevelAccountedLight(instance, lightLayer, blockPos, JOMLConversion.atCenterOf(blockPos));
49+
return sable$getSubLevelAccountedSkyLight(-1, instance, lightLayer, blockPos, JOMLConversion.atCenterOf(blockPos));
5350
}
5451

5552
@Unique
56-
private static int sable$getSubLevelAccountedLight(final Level instance, final LightLayer lightLayer, final BlockPos blockPos, final Vector3dc probePosition) {
53+
private static int sable$getSubLevelAccountedSkyLight(final int original, final Level instance, final LightLayer lightLayer, final BlockPos blockPos, final Vector3dc probePosition) {
5754
final Iterable<SubLevel> all = Sable.HELPER.getAllIntersecting(instance, new BoundingBox3d(blockPos));
5855

59-
int baseBrightness = instance.getBrightness(lightLayer, blockPos);
56+
int baseBrightness = original == -1 ? instance.getBrightness(lightLayer, blockPos) : LightTexture.sky(original);
6057
final BlockPos.MutableBlockPos localPosition = new BlockPos.MutableBlockPos();
6158
final BlockPos.MutableBlockPos heightmapPos = new BlockPos.MutableBlockPos();
6259
final Vector3d tempProbePosition = new Vector3d();
6360

6461
for (final SubLevel subLevel : all) {
6562
final ClientSubLevel clientSubLevel = (ClientSubLevel) subLevel;
66-
// final BlockPos localPosition = BlockPos.containing(clientSubLevel.renderPose().transformPositionInverse(probePosition));
63+
6764
clientSubLevel.renderPose().transformPositionInverse(probePosition, tempProbePosition);
6865
localPosition.set(tempProbePosition.x, tempProbePosition.y, tempProbePosition.z);
6966

@@ -96,14 +93,14 @@ public final int getPackedLightCoords(final Entity arg, final float f) {
9693

9794
@Redirect(method = "getBlockLightLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBrightness(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/BlockPos;)I"))
9895
private int sable$getBlockLightLevel(final Level instance, final LightLayer lightLayer, final BlockPos blockPos) {
99-
return sable$getSubLevelAccountedBlockLight(instance, lightLayer, blockPos, JOMLConversion.atCenterOf(blockPos));
96+
return sable$getSubLevelAccountedBlockLight(-1, instance, lightLayer, blockPos, JOMLConversion.atCenterOf(blockPos));
10097
}
10198

10299
@Unique
103-
private static int sable$getSubLevelAccountedBlockLight(final Level instance, final LightLayer lightLayer, final BlockPos blockPos, final Vector3dc lightProbePosition) {
104-
final Iterable<SubLevel> all = Sable.HELPER.getAllIntersecting(instance, new BoundingBox3d(blockPos));
100+
private static int sable$getSubLevelAccountedBlockLight(final int original, final Level instance, final LightLayer lightLayer, final BlockPos blockPos, final Vector3dc lightProbePosition) {
101+
final Iterable<SubLevel> all = Sable.HELPER.getAllIntersecting(instance, new BoundingBox3d(blockPos).expand(2.0));
105102

106-
int l = instance.getBrightness(LightLayer.BLOCK, blockPos);
103+
int l = original == -1 ? instance.getBrightness(lightLayer, blockPos) : LightTexture.block(original);
107104
final BlockPos.MutableBlockPos probeBlockPos = new BlockPos.MutableBlockPos();
108105
final Vector3d tempProbePosition = new Vector3d();
109106

0 commit comments

Comments
 (0)