Skip to content

Commit 18284ed

Browse files
committed
LambDynamicLights 2.0.2. Fix #63, fix #70, fix #71, fix #72, fix #75, fix #76.
1 parent bf36d6e commit 18284ed

19 files changed

+285
-131
lines changed

.github/workflows/gradlepublish.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- '*'
77

88
jobs:
9-
build:
9+
publish:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
@@ -17,14 +17,6 @@ jobs:
1717
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
1818
settings-path: ${{ github.workspace }} # location for the settings.xml file
1919

20-
- name: Build with Gradle
21-
run: ./gradlew build
22-
23-
- uses: actions/upload-artifact@v2
24-
with:
25-
name: Artifacts
26-
path: ./build/libs/
27-
2820
# The USERNAME and PASSWORD need to correspond to the credentials environment variables used in
2921
# the publishing section of your build.gradle
3022
- name: Publish to GitHub Packages and other Mavens

.github/workflows/modrinth_update.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Gradle Build
1+
name: Modrinth Publish
22

33
on:
44
release:

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@
102102
- Removed any usage of a library.
103103
- Updated [SpruceUI].
104104

105+
### 2.0.2
106+
107+
- Added Swedish translations ([#68](https://github.com/LambdAurora/LambDynamicLights/pull/68)).
108+
- Block items now respect the `BlockStateTag` in item's NBT ([#71](https://github.com/LambdAurora/LambDynamicLights/issues/71)).
109+
- Fixed glow item frames not emitting light ([#63](https://github.com/LambdAurora/LambDynamicLights/issues/63)).
110+
- Fixed minecart not emitting light when holding a light source ([#70](https://github.com/LambdAurora/LambDynamicLights/issues/70)).
111+
- Fixed glow berries not emitting light ([#72](https://github.com/LambdAurora/LambDynamicLights/issues/72)).
112+
- Fixed glow squids not dimming when attacked ([#75](https://github.com/LambdAurora/LambDynamicLights/issues/75)).
113+
- Fixed LambDynamicLights not rebuilding the correct chunks when at Y -18 or Y -50 ([#76](https://github.com/LambdAurora/LambDynamicLights/issues/76)).
114+
105115
[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
106116
[Sodium]: https://modrinth.com/mod/sodium "Sodium Modrinth page"
107117
[Canvas Renderer]: https://www.curseforge.com/minecraft/mc-mods/canvas-renderer "Canvas Renderer CurseForge page"

build.gradle

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
2-
id 'fabric-loom' version '0.9.+'
2+
id 'fabric-loom' version '0.9.25'
3+
id 'io.github.juuxel.loom-quiltflower' version '1.1.1'
34
id 'java-library'
45
id 'maven-publish'
56
id 'com.github.johnrengelman.shadow' version '7.0.0'
@@ -58,23 +59,23 @@ repositories {
5859
mavenLocal()
5960
mavenCentral()
6061
maven {
61-
name = 'Terraformers'
62-
url = 'https://maven.terraformersmc.com/releases/'
62+
name 'Terraformers'
63+
url 'https://maven.terraformersmc.com/releases/'
6364
}
6465
maven {
65-
name = 'AperLambda'
66-
url = 'https://aperlambda.github.io/maven'
66+
name 'AperLambda'
67+
url 'https://aperlambda.github.io/maven'
6768
}
6869
maven {
6970
name 'Gegy'
7071
url 'https://maven.gegy.dev'
7172
}
7273
maven {
73-
name = "grondag"
74-
url = "https://grondag-repo.appspot.com"
74+
name 'grondag'
75+
url 'https://grondag-repo.appspot.com'
7576
credentials {
76-
username "guest"
77-
password ""
77+
username 'guest'
78+
password ''
7879
}
7980
}
8081
}

gradle.properties

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

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.17
7-
yarn_mappings=1
8-
loader_version=0.11.3
6+
minecraft_version=1.17.1
7+
yarn_mappings=31
8+
loader_version=0.11.6
99
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
10-
fabric_api_version=0.34.9+1.17
10+
fabric_api_version=0.37.1+1.17
1111

1212
# Mod Properties
13-
mod_version = 2.0.1
13+
mod_version = 2.0.2
1414
maven_group = dev.lambdaurora
1515
archives_base_name = lambdynamiclights
1616
modrinth_id=yBW8D80W
1717

1818
# Dependencies
1919
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
2020
spruceui_version=3.2.0+1.17
21-
modmenu_version=2.0.0-beta.7
21+
modmenu_version=2.0.4

settings.gradle

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
pluginManagement {
22
repositories {
33
maven {
4-
name = 'Fabric'
5-
url = 'https://maven.fabricmc.net/'
4+
name 'Quilt'
5+
url 'https://maven.quiltmc.org/repository/release'
6+
}
7+
maven {
8+
name 'Fabric'
9+
url 'https://maven.fabricmc.net/'
10+
}
11+
maven {
12+
name 'Cotton'
13+
url 'https://server.bbkr.space/artifactory/libs-release/'
614
}
715
gradlePluginPortal()
816
}

src/main/java/dev/lambdaurora/lambdynlights/api/DynamicLightHandlers.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.minecraft.entity.Entity;
1616
import net.minecraft.entity.EntityType;
1717
import net.minecraft.util.math.BlockPos;
18+
import net.minecraft.util.math.MathHelper;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021

@@ -23,7 +24,7 @@
2324

2425
/**
2526
* @author LambdAurora
26-
* @version 1.3.2
27+
* @version 2.0.2
2728
* @since 1.1.0
2829
*/
2930
public final class DynamicLightHandlers {
@@ -51,9 +52,15 @@ public static void registerDefaultHandlers() {
5152
var world = entity.getEntityWorld();
5253
return LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty());
5354
});
55+
registerDynamicLightHandler(EntityType.GLOW_ITEM_FRAME, entity -> {
56+
var world = entity.getEntityWorld();
57+
return Math.max(14, LambDynLights.getLuminanceFromItemStack(entity.getHeldItemStack(), !world.getFluidState(entity.getBlockPos()).isEmpty()));
58+
});
5459
registerDynamicLightHandler(EntityType.MAGMA_CUBE, entity -> (entity.stretch > 0.6) ? 11 : 8);
5560
registerDynamicLightHandler(EntityType.SPECTRAL_ARROW, entity -> 8);
56-
registerDynamicLightHandler(EntityType.GLOW_SQUID, entity -> 12);
61+
registerDynamicLightHandler(EntityType.GLOW_SQUID,
62+
entity -> (int) MathHelper.clampedLerp(0.f, 12.f, 1.f - entity.getDarkTicksRemaining() / 10.f)
63+
);
5764
}
5865

5966
/**

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

+111-28
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
import com.google.gson.JsonObject;
1313
import dev.lambdaurora.lambdynlights.LambDynLights;
14+
import net.minecraft.block.BlockState;
1415
import net.minecraft.block.Blocks;
1516
import net.minecraft.item.BlockItem;
1617
import net.minecraft.item.Item;
1718
import net.minecraft.item.ItemStack;
1819
import net.minecraft.item.Items;
20+
import net.minecraft.state.property.Property;
1921
import net.minecraft.util.Identifier;
2022
import net.minecraft.util.registry.Registry;
2123
import org.jetbrains.annotations.NotNull;
@@ -26,34 +28,64 @@
2628
* Represents an item light source.
2729
*
2830
* @author LambdAurora
29-
* @version 2.0.0
31+
* @version 2.0.2
3032
* @since 1.3.0
3133
*/
32-
public record ItemLightSource(Identifier id, Item item, int luminance, boolean waterSensitive) {
33-
public ItemLightSource(@NotNull Identifier id, @NotNull Item item, int luminance) {
34-
this(id, item, luminance, false);
34+
public abstract class ItemLightSource {
35+
private final Identifier id;
36+
private final Item item;
37+
private final boolean waterSensitive;
38+
39+
public ItemLightSource(Identifier id, Item item, boolean waterSensitive) {
40+
this.id = id;
41+
this.item = item;
42+
this.waterSensitive = waterSensitive;
43+
}
44+
45+
public ItemLightSource(Identifier id, Item item) {
46+
this(id, item, false);
47+
}
48+
49+
public Identifier id() {
50+
return this.id;
51+
}
52+
53+
public Item item() {
54+
return this.item;
55+
}
56+
57+
public boolean waterSensitive() {
58+
return this.waterSensitive;
3559
}
3660

3761
/**
3862
* Gets the luminance of the item.
3963
*
40-
* @param stack The item stack.
41-
* @param submergedInWater True if submerged in water, else false.
42-
* @return The luminance value between 0 and 15.
64+
* @param stack the item stack
65+
* @param submergedInWater {@code true} if submerged in water, else {@code false}.
66+
* @return the luminance value between {@code 0} and {@code 15}
4367
*/
44-
public int getLuminance(@NotNull ItemStack stack, boolean submergedInWater) {
45-
if (this.waterSensitive && LambDynLights.get().config.hasWaterSensitiveCheck() && submergedInWater)
68+
public int getLuminance(ItemStack stack, boolean submergedInWater) {
69+
if (this.waterSensitive() && LambDynLights.get().config.hasWaterSensitiveCheck() && submergedInWater)
4670
return 0; // Don't emit light with water sensitive items while submerged in water.
4771

48-
return this.luminance;
72+
return this.getLuminance(stack);
4973
}
5074

75+
/**
76+
* Gets the luminance of the item.
77+
*
78+
* @param stack the item stack
79+
* @return the luminance value between {@code 0} and {@code 15}
80+
*/
81+
public abstract int getLuminance(ItemStack stack);
82+
5183
@Override
5284
public String toString() {
5385
return "ItemLightSource{" +
54-
"item=" + item +
55-
", luminance=" + luminance +
56-
", water_sensitive=" + waterSensitive +
86+
"id=" + this.id() +
87+
"item=" + this.item() +
88+
", water_sensitive=" + this.waterSensitive() +
5789
'}';
5890
}
5991

@@ -69,34 +101,85 @@ public String toString() {
69101
if (item == Items.AIR)
70102
return Optional.empty();
71103

72-
int luminance;
104+
boolean waterSensitive = false;
105+
if (json.has("water_sensitive"))
106+
waterSensitive = json.get("water_sensitive").getAsBoolean();
107+
73108
var luminanceElement = json.get("luminance").getAsJsonPrimitive();
74109
if (luminanceElement.isNumber()) {
75-
luminance = luminanceElement.getAsInt();
110+
return Optional.of(new StaticItemLightSource(id, item, luminanceElement.getAsInt(), waterSensitive));
76111
} else if (luminanceElement.isString()) {
77112
var luminanceStr = luminanceElement.getAsString();
78113
if (luminanceStr.equals("block")) {
79114
if (item instanceof BlockItem blockItem) {
80-
luminance = blockItem.getBlock().getDefaultState().getLuminance();
81-
} else {
82-
return Optional.empty();
115+
return Optional.of(new BlockItemLightSource(id, item, blockItem.getBlock().getDefaultState(), waterSensitive));
83116
}
84117
} else {
85-
var block = Registry.BLOCK.get(new Identifier(luminanceStr));
86-
if (block == Blocks.AIR)
87-
return Optional.empty();
88-
89-
luminance = block.getDefaultState().getLuminance();
118+
var blockId = Identifier.tryParse(luminanceStr);
119+
if (blockId != null) {
120+
var block = Registry.BLOCK.get(blockId);
121+
if (block != Blocks.AIR)
122+
return Optional.of(new BlockItemLightSource(id, item, block.getDefaultState(), waterSensitive));
123+
}
90124
}
91125
} else {
92126
LambDynLights.get().warn("Failed to parse item light source \"" + id + "\", invalid format: \"luminance\" field value isn't string or integer.");
93-
return Optional.empty();
94127
}
95128

96-
boolean waterSensitive = false;
97-
if (json.has("water_sensitive"))
98-
waterSensitive = json.get("water_sensitive").getAsBoolean();
129+
return Optional.empty();
130+
}
131+
132+
public static class StaticItemLightSource extends ItemLightSource {
133+
private final int luminance;
134+
135+
public StaticItemLightSource(Identifier id, Item item, int luminance, boolean waterSensitive) {
136+
super(id, item, waterSensitive);
137+
this.luminance = luminance;
138+
}
139+
140+
public StaticItemLightSource(Identifier id, Item item, int luminance) {
141+
super(id, item);
142+
this.luminance = luminance;
143+
}
144+
145+
@Override
146+
public int getLuminance(ItemStack stack) {
147+
return this.luminance;
148+
}
149+
}
99150

100-
return Optional.of(new ItemLightSource(id, item, luminance, waterSensitive));
151+
public static class BlockItemLightSource extends ItemLightSource {
152+
private final BlockState mimic;
153+
154+
public BlockItemLightSource(Identifier id, Item item, BlockState block, boolean waterSensitive) {
155+
super(id, item, waterSensitive);
156+
this.mimic = block;
157+
}
158+
159+
@Override
160+
public int getLuminance(ItemStack stack) {
161+
return getLuminance(stack, this.mimic);
162+
}
163+
164+
static int getLuminance(ItemStack stack, BlockState state) {
165+
var nbt = stack.getNbt();
166+
if (nbt != null) {
167+
var blockStateTag = nbt.getCompound("BlockStateTag");
168+
var stateManager = state.getBlock().getStateManager();
169+
170+
for (var key : blockStateTag.getKeys()) {
171+
var property = stateManager.getProperty(key);
172+
if (property != null) {
173+
var value = blockStateTag.get(key).asString();
174+
state = with(state, property, value);
175+
}
176+
}
177+
}
178+
return state.getLuminance();
179+
}
180+
181+
private static <T extends Comparable<T>> BlockState with(BlockState state, Property<T> property, String name) {
182+
return property.parse(name).map(value -> state.with(property, value)).orElse(state);
183+
}
101184
}
102185
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Represents an item light sources manager.
2828
*
2929
* @author LambdAurora
30-
* @version 2.0.1
30+
* @version 2.0.2
3131
* @since 1.3.0
3232
*/
3333
public final class ItemLightSources {
@@ -87,7 +87,7 @@ private static void register(@NotNull ItemLightSource data) {
8787
/**
8888
* Registers an item light source data.
8989
*
90-
* @param data The item light source data.
90+
* @param data the item light source data
9191
*/
9292
public static void registerItemLightSource(@NotNull ItemLightSource data) {
9393
for (var other : STATIC_ITEM_LIGHT_SOURCES) {
@@ -104,9 +104,9 @@ public static void registerItemLightSource(@NotNull ItemLightSource data) {
104104
/**
105105
* Returns the luminance of the item in the stack.
106106
*
107-
* @param stack The item stack.
108-
* @param submergedInWater True if the stack is submerged in water, else false.
109-
* @return A luminance value.
107+
* @param stack the item stack
108+
* @param submergedInWater {@code true} if the stack is submerged in water, else {@code false}
109+
* @return a luminance value
110110
*/
111111
public static int getLuminance(@NotNull ItemStack stack, boolean submergedInWater) {
112112
for (var data : ITEM_LIGHT_SOURCES) {
@@ -115,7 +115,7 @@ public static int getLuminance(@NotNull ItemStack stack, boolean submergedInWate
115115
}
116116
}
117117
if (stack.getItem() instanceof BlockItem blockItem)
118-
return blockItem.getBlock().getDefaultState().getLuminance();
119-
return 0;
118+
return ItemLightSource.BlockItemLightSource.getLuminance(stack, blockItem.getBlock().getDefaultState());
119+
else return 0;
120120
}
121121
}

0 commit comments

Comments
 (0)