|
1 | 1 | package dev.ryanhcode.sable.mixin.entity.entity_rendering; |
2 | 2 |
|
| 3 | +import com.llamalad7.mixinextras.injector.ModifyReturnValue; |
3 | 4 | import dev.ryanhcode.sable.Sable; |
4 | | -import dev.ryanhcode.sable.api.entity.EntitySubLevelUtil; |
5 | 5 | import dev.ryanhcode.sable.companion.math.BoundingBox3d; |
6 | 6 | import dev.ryanhcode.sable.companion.math.JOMLConversion; |
7 | 7 | import dev.ryanhcode.sable.sublevel.ClientSubLevel; |
@@ -35,35 +35,32 @@ public abstract class EntityRendererMixin { |
35 | 35 | @Final |
36 | 36 | protected EntityRenderDispatcher entityRenderDispatcher; |
37 | 37 |
|
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) { |
44 | 40 | final Vec3 lightProbeOffset = arg.getLightProbePosition(f).subtract(arg.getEyePosition(f)); |
45 | 41 | final Vector3d lightProbePosition = JOMLConversion.toJOML(Sable.HELPER.getEyePositionInterpolated(arg, f)).add(lightProbeOffset.x, lightProbeOffset.y, lightProbeOffset.z); |
46 | 42 | 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)); |
48 | 45 | } |
49 | 46 |
|
50 | 47 | @Redirect(method = "getSkyLightLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBrightness(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/BlockPos;)I")) |
51 | 48 | 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)); |
53 | 50 | } |
54 | 51 |
|
55 | 52 | @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) { |
57 | 54 | final Iterable<SubLevel> all = Sable.HELPER.getAllIntersecting(instance, new BoundingBox3d(blockPos)); |
58 | 55 |
|
59 | | - int baseBrightness = instance.getBrightness(lightLayer, blockPos); |
| 56 | + int baseBrightness = original == -1 ? instance.getBrightness(lightLayer, blockPos) : LightTexture.sky(original); |
60 | 57 | final BlockPos.MutableBlockPos localPosition = new BlockPos.MutableBlockPos(); |
61 | 58 | final BlockPos.MutableBlockPos heightmapPos = new BlockPos.MutableBlockPos(); |
62 | 59 | final Vector3d tempProbePosition = new Vector3d(); |
63 | 60 |
|
64 | 61 | for (final SubLevel subLevel : all) { |
65 | 62 | final ClientSubLevel clientSubLevel = (ClientSubLevel) subLevel; |
66 | | -// final BlockPos localPosition = BlockPos.containing(clientSubLevel.renderPose().transformPositionInverse(probePosition)); |
| 63 | + |
67 | 64 | clientSubLevel.renderPose().transformPositionInverse(probePosition, tempProbePosition); |
68 | 65 | localPosition.set(tempProbePosition.x, tempProbePosition.y, tempProbePosition.z); |
69 | 66 |
|
@@ -96,14 +93,14 @@ public final int getPackedLightCoords(final Entity arg, final float f) { |
96 | 93 |
|
97 | 94 | @Redirect(method = "getBlockLightLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBrightness(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/BlockPos;)I")) |
98 | 95 | 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)); |
100 | 97 | } |
101 | 98 |
|
102 | 99 | @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)); |
105 | 102 |
|
106 | | - int l = instance.getBrightness(LightLayer.BLOCK, blockPos); |
| 103 | + int l = original == -1 ? instance.getBrightness(lightLayer, blockPos) : LightTexture.block(original); |
107 | 104 | final BlockPos.MutableBlockPos probeBlockPos = new BlockPos.MutableBlockPos(); |
108 | 105 | final Vector3d tempProbePosition = new Vector3d(); |
109 | 106 |
|
|
0 commit comments