Skip to content

Commit 31a3e08

Browse files
committed
LambDynamicLights v1.3.1: Fix issues with Sodium.
1 parent 3485a40 commit 31a3e08

13 files changed

+167
-49
lines changed

CHANGELOG.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
- Added water-sensitive check for items and light sources.
2626
- Added data item tag `#lambdynlights:water_sensitive` which lists every item which can't light up in the water.
2727
- Added an option to enable/disable the feature
28-
- Updated SpruceUI to v1.5.6 to fix latest snapshots issues.
29-
- Added "early/WIP" compatibility with [Canvas Renderer](https://www.curseforge.com/minecraft/mc-mods/canvas-renderer).
28+
- Updated [SpruceUI] to v1.5.6 to fix latest snapshots issues.
29+
- Added "early/WIP" compatibility with [Canvas Renderer].
3030
- Added a warning message about performance issues.
31-
- Fixed a crash with Sodium rc7 with smooth lighting set to HIGH.
31+
- Fixed a crash with [Sodium] rc7 with smooth lighting set to HIGH.
3232

3333
### v1.2.1
3434

3535
- Added TNT dynamic lighting.
3636
- Added lighting options for TNT and Creepers.
3737
- Added luminance value to Fire charge item.
38-
- Updated SpruceUI to v1.5.8
38+
- Updated [SpruceUI] to v1.5.8
3939
- Fixed player dynamic lighting not getting tracked when changing dimensions.
4040

4141
### v1.2.2
@@ -53,9 +53,17 @@
5353
- Added spectral arrow as item emitting light ([#17](https://github.com/LambdAurora/LambDynamicLights/pull/17)).
5454
- Added dynamic lighting on glowing entities ([#17](https://github.com/LambdAurora/LambDynamicLights/pull/17)).
5555
- Updated to Minecraft 1.16.2
56-
- Updated [SpruceUI](https://github.com/LambdAurora/SpruceUI) to v1.6.2.
56+
- Updated [SpruceUI] to v1.6.2.
5757
- Fixed dynamic lighting update issues at chunk borders ([#12](https://github.com/LambdAurora/LambDynamicLights/issues/12)).
5858
- Fixed water-sensitive items lighting up in water on dedicated servers. ([#3](https://github.com/LambdAurora/LambDynamicLights/issues/3))
5959
- Added new JSON API to add item luminance and water-sensitivity through resource packs.
6060
- Added `DynamicLightHandler#isWaterSensitive` to make some entities water-sensitive like the blaze.
61-
- Fixed incompatibility with future Sodium versions. ([#6](https://github.com/LambdAurora/LambDynamicLights/issues/6))
61+
- Fixed incompatibility with future [Sodium] versions. ([#6](https://github.com/LambdAurora/LambDynamicLights/issues/6))
62+
63+
## v1.3.1
64+
65+
- Fixed entity lighting issue with [Sodium] 0.1.0. ([#23](https://github.com/LambdAurora/LambDynamicLights/issues/23))
66+
67+
[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
68+
[Sodium]: https://www.curseforge.com/minecraft/mc-mods/sodium "Sodium CurseForge page"
69+
[Canvas Renderer]: https://www.curseforge.com/minecraft/mc-mods/canvas-renderer "Canvas Renderer CurseForge page"

HOW_DOES_IT_WORK.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ UpcraftLP method can be found here: https://gist.github.com/UpcraftLP/93db478535
1212
AtomicStryker method can be found here: https://github.com/AtomicStryker/atomicstrykers-minecraft-mods/tree/1.14.3/DynamicLights
1313

1414
Both methods suffer from a "laggy" dynamic lighting, the way the light moves is too much tied to
15-
the block positions as it only injects at luminance getters in `WorldChunk` or a lighting provider.
15+
the block positions as it only injects at light level getters in `WorldChunk` or a lighting provider.
1616
It will only provide the dynamic light value of the light source if the block position is the position
1717
of the light source.
1818

@@ -36,16 +36,16 @@ light sources, their distances and the luminance), if the dynamic value is highe
3636
then we replace it.
3737

3838
This also means that we can't just do like the previous method and only give the source luminance but
39-
we also have to calculate the surrounding luminance created by the dynamic light source in a specified
39+
we also have to calculate the surrounding light level created by the dynamic light sources in a specified
4040
range (which is 7.75 to limit chunk rebuilding to 8 chunks (which is still a lot)).
4141

4242
When getting the dynamic light value at the specified position, it has to be a `double` and not
43-
an integer as the light value calculated with the range has to be precise.
43+
an integer as the light level calculated within the range has to be precise.
4444
To modify the lightmap with the dynamic light value, it has to be multiplied by 16.0 instead of
4545
using a bitshift to preserve as much as possible the precision.
4646

47-
Dynamic light value at a specified position is calculated in a for-loop with all the dynamic light
48-
sources, only the highest light value is kept. The light value is calculated as follow:
47+
Dynamic light level at a specified position is calculated in a for-loop with all the dynamic light
48+
sources, only the highest light level is kept. The light level is calculated as follow:
4949

5050
```java
5151
// dist being the distance between the light source origin and the position where the

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656

5757
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
5858
//modImplementation "grondag:canvas-mc116:1.0.+"
59-
//modImplementation "me.jellysquid.mods:sodium:0.1.0+v8-SNAPSHOT"
59+
modImplementation "com.github.jellysquid3:sodium-fabric:mc1.16.3-0.1.0"
6060

6161
shadow "com.electronwill.night-config:core:3.6.3"
6262
shadow "com.electronwill.night-config:toml:3.6.3"

gradle.properties

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.16.2
7-
yarn_mappings=1.16.2+build.6
8-
loader_version=0.9.1+build.205
6+
minecraft_version=1.16.3
7+
yarn_mappings=1.16.3+build.17
8+
loader_version=0.9.3+build.207
99

1010
# Mod Properties
11-
mod_version = 1.3.0
11+
mod_version = 1.3.1
1212
maven_group = me.lambdaurora
1313
archives_base_name = lambdynamiclights
1414

1515
# Dependencies
1616
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
17-
fabric_version=0.17.2+build.396-1.16
18-
spruceui_version=1.6.2
17+
fabric_version=0.20.2+build.402-1.16
18+
spruceui_version=1.6.4
1919
modmenu_version=1.14.6+build.31

src/main/java/me/lambdaurora/lambdynlights/LambDynLights.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* Represents the LambDynamicLights mod.
4949
*
5050
* @author LambdAurora
51-
* @version 1.3.0
51+
* @version 1.3.1
5252
* @since 1.0.0
5353
*/
5454
public class LambDynLights implements ClientModInitializer
@@ -129,7 +129,7 @@ public void updateAll(@NotNull WorldRenderer renderer)
129129
*/
130130
public int getLightmapWithDynamicLight(@NotNull BlockPos pos, int lightmap)
131131
{
132-
return this.getLightmapWithDynamicLight(this.getDynamicLuminance(pos), lightmap);
132+
return this.getLightmapWithDynamicLight(this.getDynamicLightLevel(pos), lightmap);
133133
}
134134

135135
/**
@@ -141,29 +141,29 @@ public int getLightmapWithDynamicLight(@NotNull BlockPos pos, int lightmap)
141141
*/
142142
public int getLightmapWithDynamicLight(@NotNull Entity entity, int lightmap)
143143
{
144-
int posLuminance = (int) this.getDynamicLuminance(entity.getBlockPos());
144+
int posLightLevel = (int) this.getDynamicLightLevel(entity.getBlockPos());
145145
int entityLuminance = ((DynamicLightSource) entity).getLuminance();
146146

147-
return this.getLightmapWithDynamicLight(Math.max(posLuminance, entityLuminance), lightmap);
147+
return this.getLightmapWithDynamicLight(Math.max(posLightLevel, entityLuminance), lightmap);
148148
}
149149

150150
/**
151151
* Returns the lightmap with combined light levels.
152152
*
153-
* @param dynamicLuminance The dynamic light level.
154-
* @param lightmap The vanilla lightmap.
153+
* @param dynamicLightLevel The dynamic light level.
154+
* @param lightmap The vanilla lightmap.
155155
* @return The modified lightmap.
156156
*/
157-
public int getLightmapWithDynamicLight(double dynamicLuminance, int lightmap)
157+
public int getLightmapWithDynamicLight(double dynamicLightLevel, int lightmap)
158158
{
159-
if (dynamicLuminance > 0) {
159+
if (dynamicLightLevel > 0) {
160160
// lightmap is (skyLevel << 20 | blockLevel << 4)
161161

162162
// Get vanilla block light level.
163163
int blockLevel = LightmapTextureManager.getBlockLightCoordinates(lightmap);
164-
if (dynamicLuminance > blockLevel) {
164+
if (dynamicLightLevel > blockLevel) {
165165
// Equivalent to a << 4 bitshift with a little quirk: this one ensure more precision (more decimals are saved).
166-
int luminance = (int) (dynamicLuminance * 16.0);
166+
int luminance = (int) (dynamicLightLevel * 16.0);
167167
lightmap &= 0xfff00000;
168168
lightmap |= luminance & 0x000fffff;
169169
}
@@ -178,11 +178,11 @@ public int getLightmapWithDynamicLight(double dynamicLuminance, int lightmap)
178178
* @param pos The position.
179179
* @return The dynamic light level at the spec
180180
*/
181-
public double getDynamicLuminance(@NotNull BlockPos pos)
181+
public double getDynamicLightLevel(@NotNull BlockPos pos)
182182
{
183183
double result = 0;
184184
for (DynamicLightSource lightSource : this.dynamicLightSources) {
185-
result = maxDynamicLuminance(pos, lightSource, result);
185+
result = maxDynamicLightLevel(pos, lightSource, result);
186186
}
187187

188188
return MathHelper.clamp(result, 0, 15);
@@ -191,12 +191,12 @@ public double getDynamicLuminance(@NotNull BlockPos pos)
191191
/**
192192
* Returns the dynamic light level generated by the light source at the specified position.
193193
*
194-
* @param pos The position.
195-
* @param lightSource The light source.
196-
* @param currentLuminance The current surrounding dynamic luminance.
194+
* @param pos The position.
195+
* @param lightSource The light source.
196+
* @param currentLightLevel The current surrounding dynamic light level.
197197
* @return The dynamic light level.
198198
*/
199-
public static double maxDynamicLuminance(@NotNull BlockPos pos, @NotNull DynamicLightSource lightSource, double currentLuminance)
199+
public static double maxDynamicLightLevel(@NotNull BlockPos pos, @NotNull DynamicLightSource lightSource, double currentLightLevel)
200200
{
201201
int luminance = lightSource.getLuminance();
202202
if (luminance > 0) {
@@ -211,12 +211,12 @@ public static double maxDynamicLuminance(@NotNull BlockPos pos, @NotNull Dynamic
211211
if (distance <= MAX_RADIUS) {
212212
double multiplier = 1.0 - distance / MAX_RADIUS;
213213
double lightLevel = multiplier * (double) luminance;
214-
if (lightLevel > currentLuminance) {
215-
currentLuminance = lightLevel;
214+
if (lightLevel > currentLightLevel) {
215+
currentLightLevel = lightLevel;
216216
}
217217
}
218218
}
219-
return currentLuminance;
219+
return currentLightLevel;
220220
}
221221

222222
/**

src/main/java/me/lambdaurora/lambdynlights/LambDynLightsCompat.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Represents a utility class for compatibility.
1616
*
1717
* @author LambdAurora
18-
* @version 1.3.0
18+
* @version 1.3.1
1919
* @since 1.0.0
2020
*/
2121
public final class LambDynLightsCompat
@@ -50,4 +50,15 @@ public static boolean isSodiumInstalled()
5050
{
5151
return FabricLoader.getInstance().isModLoaded("sodium");
5252
}
53+
54+
/**
55+
* Returns whether Sodium 0.1.0 is installed.
56+
*
57+
* @return True if Sodium 0.1.0 is installed, else false.
58+
*/
59+
public static boolean isSodium010Installed()
60+
{
61+
return FabricLoader.getInstance().getModContainer("sodium").map(mod -> mod.getMetadata().getVersion().getFriendlyString().equalsIgnoreCase("0.1.0"))
62+
.orElse(false);
63+
}
5364
}

src/main/java/me/lambdaurora/lambdynlights/LambDynLightsMixinPlugin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* LambDynamicLights mixin plugin for conditional mixins.
2222
*
2323
* @author LambdAurora
24-
* @version 1.3.0
24+
* @version 1.3.1
2525
* @since 1.0.0
2626
*/
2727
public class LambDynLightsMixinPlugin implements IMixinConfigPlugin
@@ -37,6 +37,7 @@ public LambDynLightsMixinPlugin()
3737
boolean canvasInstalled = LambDynLightsCompat.isCanvasInstalled();
3838
boolean sodiumInstalled = LambDynLightsCompat.isSodiumInstalled();
3939
this.conditionalMixins.put("me.lambdaurora.lambdynlights.mixin.WorldRendererMixin", !sodiumInstalled && !canvasInstalled);
40+
this.conditionalMixins.put("me.lambdaurora.lambdynlights.mixin.EntityLighterMixin", LambDynLightsCompat.isSodium010Installed());
4041
}
4142

4243
@Override

src/main/java/me/lambdaurora/lambdynlights/api/item/ItemLightSource.java

+29-2
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@
1616
import net.minecraft.block.Blocks;
1717
import net.minecraft.item.BlockItem;
1818
import net.minecraft.item.Item;
19+
import net.minecraft.item.ItemStack;
1920
import net.minecraft.item.Items;
2021
import net.minecraft.util.Identifier;
2122
import net.minecraft.util.registry.Registry;
2223
import org.jetbrains.annotations.NotNull;
2324

25+
import java.util.Objects;
2426
import java.util.Optional;
2527

2628
/**
2729
* Represents an item light source.
2830
*
2931
* @author LambdAurora
30-
* @version 1.3.0
32+
* @version 1.3.1
3133
* @since 1.3.0
3234
*/
3335
public class ItemLightSource
@@ -50,14 +52,39 @@ public ItemLightSource(@NotNull Identifier id, @NotNull Item item, int luminance
5052
this.waterSensitive = waterSensitive;
5153
}
5254

53-
public int getLuminance(boolean submergedInWater)
55+
/**
56+
* Gets the luminance of the item.
57+
*
58+
* @param stack The item stack.
59+
* @param submergedInWater True if submerged in water, else false.
60+
* @return The luminance value between 0 and 15.
61+
*/
62+
public int getLuminance(@NotNull ItemStack stack, boolean submergedInWater)
5463
{
5564
if (this.waterSensitive && LambDynLights.get().config.hasWaterSensitiveCheck() && submergedInWater)
5665
return 0; // Don't emit light with water sensitive items while submerged in water.
5766

5867
return this.luminance;
5968
}
6069

70+
@Override
71+
public boolean equals(Object o)
72+
{
73+
if (this == o) return true;
74+
if (o == null || getClass() != o.getClass()) return false;
75+
ItemLightSource that = (ItemLightSource) o;
76+
return luminance == that.luminance &&
77+
waterSensitive == that.waterSensitive &&
78+
Objects.equals(id, that.id) &&
79+
Objects.equals(item, that.item);
80+
}
81+
82+
@Override
83+
public int hashCode()
84+
{
85+
return Objects.hash(id, item, luminance, waterSensitive);
86+
}
87+
6188
@Override
6289
public String toString()
6390
{

src/main/java/me/lambdaurora/lambdynlights/api/item/ItemLightSources.java

+29-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
* Represents an item light sources manager.
3131
*
3232
* @author LambdAurora
33-
* @version 1.3.0
33+
* @version 1.3.1
3434
* @since 1.3.0
3535
*/
3636
public final class ItemLightSources
3737
{
38-
private static final List<ItemLightSource> ITEM_LIGHT_SOURCES = new ArrayList<>();
38+
private static final List<ItemLightSource> ITEM_LIGHT_SOURCES = new ArrayList<>();
39+
private static final List<ItemLightSource> STATIC_ITEM_LIGHT_SOURCES = new ArrayList<>();
3940

4041
/**
4142
* Loads the item light source data from resource pack.
@@ -47,6 +48,8 @@ public static void load(@NotNull ResourceManager resourceManager)
4748
ITEM_LIGHT_SOURCES.clear();
4849

4950
resourceManager.findResources("dynamiclights/item", path -> path.endsWith(".json")).forEach(id -> load(resourceManager, id));
51+
52+
ITEM_LIGHT_SOURCES.addAll(STATIC_ITEM_LIGHT_SOURCES);
5053
}
5154

5255
private static void load(@NotNull ResourceManager resourceManager, @NotNull Identifier resourceId)
@@ -61,7 +64,10 @@ private static void load(@NotNull ResourceManager resourceManager, @NotNull Iden
6164
return;
6265
}
6366

64-
register(result.get());
67+
ItemLightSource data = result.get();
68+
if (STATIC_ITEM_LIGHT_SOURCES.contains(data))
69+
return;
70+
register(data);
6571
} catch (IOException | IllegalStateException e) {
6672
LambDynLights.get().warn("Failed to load item light source \"" + id + "\".");
6773
}
@@ -72,7 +78,7 @@ private static void load(@NotNull ResourceManager resourceManager, @NotNull Iden
7278
*
7379
* @param data The item light source data.
7480
*/
75-
public static void register(@NotNull ItemLightSource data)
81+
private static void register(@NotNull ItemLightSource data)
7682
{
7783
for (ItemLightSource other : ITEM_LIGHT_SOURCES) {
7884
if (other.item == data.item) {
@@ -85,6 +91,24 @@ public static void register(@NotNull ItemLightSource data)
8591
ITEM_LIGHT_SOURCES.add(data);
8692
}
8793

94+
/**
95+
* Registers an item light source data.
96+
*
97+
* @param data The item light source data.
98+
*/
99+
public static void registerItemLightSource(@NotNull ItemLightSource data)
100+
{
101+
for (ItemLightSource other : STATIC_ITEM_LIGHT_SOURCES) {
102+
if (other.item == data.item) {
103+
LambDynLights.get().warn("Failed to register item light source \"" + data.id + "\", duplicates item \""
104+
+ Registry.ITEM.getId(data.item) + "\" found in \"" + other.id + "\".");
105+
return;
106+
}
107+
}
108+
109+
STATIC_ITEM_LIGHT_SOURCES.add(data);
110+
}
111+
88112
/**
89113
* Returns the luminance of the item in the stack.
90114
*
@@ -96,7 +120,7 @@ public static int getLuminance(@NotNull ItemStack stack, boolean submergedInWate
96120
{
97121
for (ItemLightSource data : ITEM_LIGHT_SOURCES) {
98122
if (data.item == stack.getItem()) {
99-
return data.getLuminance(submergedInWater);
123+
return data.getLuminance(stack, submergedInWater);
100124
}
101125
}
102126
if (stack.getItem() instanceof BlockItem)

0 commit comments

Comments
 (0)