Skip to content

Commit a47cb73

Browse files
committed
Fully add data-driven item lighting.
1 parent e39c01e commit a47cb73

File tree

11 files changed

+196
-76
lines changed

11 files changed

+196
-76
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@
1212
import net.minecraft.world.item.ItemStack;
1313

1414
public interface ItemLightSourceManager {
15+
/**
16+
* {@return the luminance value of the item stack}
17+
*
18+
* @param stack the item stack
19+
*/
20+
default int getLuminance(ItemStack stack) {
21+
return this.getLuminance(stack, false);
22+
}
1523

16-
17-
int getLuminance(ItemStack stack);
18-
24+
/**
25+
* {@return the luminance value of the item stack}
26+
*
27+
* @param stack the item stack
28+
* @param submergedInWater {@code true} if the stack is submerged in water, else {@code false}
29+
*/
1930
int getLuminance(ItemStack stack, boolean submergedInWater);
2031
}

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ if (!(System.getenv("CURSEFORGE_TOKEN") != null || System.getenv("MODRINTH_TOKEN
1818
}
1919
logger.lifecycle("Preparing version ${version}...")
2020

21-
configurations["api"].extendsFrom(configurations["shadow"])
22-
2321
repositories {
2422
mavenLocal()
2523
mavenCentral()
@@ -57,10 +55,13 @@ loom {
5755
}
5856

5957
dependencies {
60-
shadow(project(":api"))
58+
implementation(project(":api", configuration = "namedElements"))
59+
implementation(libs.yumi.commons.core)
6160

6261
modImplementation(libs.fabric.api)
6362

63+
implementation(libs.nightconfig.core)
64+
implementation(libs.nightconfig.toml)
6465
modImplementation(libs.spruceui)
6566
include(libs.spruceui)
6667
modImplementation(libs.pridelib)
@@ -72,6 +73,8 @@ dependencies {
7273

7374
modRuntimeOnly(libs.sodium)
7475

76+
shadow(project(":api", configuration = "namedElements"))
77+
shadow(libs.yumi.commons.core)
7578
shadow(libs.nightconfig.core)
7679
shadow(libs.nightconfig.toml)
7780
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mappings-yalmm = "8"
66
mappings-parchment = "2024.07.07"
77

88
# Dependencies
9+
yumi-commons = "1.0.0-alpha.1"
910
spruceui = "5.1.0+1.21"
1011
pridelib = "1.2.1+1.21"
1112
modmenu = "11.0.1"
@@ -25,6 +26,7 @@ fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-l
2526
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
2627

2728
# Dependencies
29+
yumi-commons-core = { module = "dev.yumi.commons:yumi-commons-core", version.ref = "yumi-commons" }
2830
spruceui = { module = "dev.lambdaurora:spruceui", version.ref = "spruceui" }
2931
pridelib = { module = "io.github.queerbric:pridelib", version.ref = "pridelib" }
3032
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }

src/main/java/dev/lambdaurora/lambdynlights/DynamicLightsConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
import net.minecraft.client.player.LocalPlayer;
2121
import net.minecraft.network.chat.Text;
2222
import org.jetbrains.annotations.NotNull;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2325

2426
import java.nio.file.Path;
2527

2628
/**
2729
* Represents the mod configuration.
2830
*
2931
* @author LambdAurora
30-
* @version 2.3.1
32+
* @version 3.0.0
3133
* @since 1.0.0
3234
*/
3335
public class DynamicLightsConfig {
36+
private static final Logger LOGGER = LoggerFactory.getLogger("LambDynamicLights|Config");
3437
private static final DynamicLightsMode DEFAULT_DYNAMIC_LIGHTS_MODE = DynamicLightsMode.FANCY;
3538
private static final boolean DEFAULT_ENTITIES_LIGHT_SOURCE = true;
3639
private static final boolean DEFAULT_SELF_LIGHT_SOURCE = true;
@@ -106,7 +109,7 @@ public void load() {
106109
this.tntLightingMode = ExplosiveLightingMode.byId(this.config.getOrElse("light_sources.tnt", DEFAULT_TNT_LIGHTING_MODE.getName()))
107110
.orElse(DEFAULT_TNT_LIGHTING_MODE);
108111

109-
this.mod.log("Configuration loaded.");
112+
LambDynLights.log(LOGGER, "Configuration loaded.");
110113
}
111114

112115
/**

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@
4949
* Represents the LambDynamicLights mod.
5050
*
5151
* @author LambdAurora
52-
* @version 2.3.2
52+
* @version 3.0.0
5353
* @since 1.0.0
5454
*/
5555
public class LambDynLights implements ClientModInitializer {
5656
public static final String NAMESPACE = "lambdynlights";
57+
private static final Logger LOGGER = LoggerFactory.getLogger("LambDynamicLights");
5758
private static final double MAX_RADIUS = 7.75;
5859
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
5960
private static LambDynLights INSTANCE;
60-
public final Logger logger = LoggerFactory.getLogger(NAMESPACE);
6161
public final DynamicLightsConfig config = new DynamicLightsConfig(this);
62+
public final ItemLightSources itemLightSources = new ItemLightSources();
6263
private final Set<DynamicLightSource> dynamicLightSources = new HashSet<>();
6364
private final ReentrantReadWriteLock lightSourcesLock = new ReentrantReadWriteLock();
6465
private long lastUpdate = System.currentTimeMillis();
@@ -67,7 +68,7 @@ public class LambDynLights implements ClientModInitializer {
6768
@Override
6869
public void onInitializeClient() {
6970
INSTANCE = this;
70-
this.log("Initializing LambDynamicLights...");
71+
log(LOGGER, "Initializing LambDynamicLights...");
7172

7273
this.config.load();
7374

@@ -83,7 +84,7 @@ public Identifier getFabricId() {
8384

8485
@Override
8586
public void reload(ResourceManager manager) {
86-
ItemLightSources.load(manager);
87+
LambDynLights.this.itemLightSources.load(manager);
8788
}
8889
});
8990

@@ -365,21 +366,45 @@ public void removeBlockEntitiesLightSource() {
365366
}
366367

367368
/**
368-
* Prints a message to the terminal.
369+
* Logs an informational message.
369370
*
370-
* @param info the message to print
371+
* @param logger the logger to use
372+
* @param msg the message to log
371373
*/
372-
public void log(String info) {
373-
this.logger.info("[LambDynLights] " + info);
374+
public static void log(Logger logger, String msg) {
375+
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) {
376+
msg = "[LambDynLights] " + msg;
377+
}
378+
379+
logger.info(msg);
374380
}
375381

376382
/**
377-
* Prints a warning message to the terminal.
383+
* Logs a warning message.
378384
*
379-
* @param info the message to print
385+
* @param logger the logger to use
386+
* @param msg the message to log
380387
*/
381-
public void warn(String info) {
382-
this.logger.warn("[LambDynLights] " + info);
388+
public static void warn(Logger logger, String msg) {
389+
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) {
390+
msg = "[LambDynLights] " + msg;
391+
}
392+
393+
logger.warn(msg);
394+
}
395+
396+
/**
397+
* Logs a warning message.
398+
*
399+
* @param logger the logger to use
400+
* @param msg the message to log
401+
*/
402+
public static void warn(Logger logger, String msg, Object... args) {
403+
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) {
404+
msg = "[LambDynLights] " + msg;
405+
}
406+
407+
logger.warn(msg, args);
383408
}
384409

385410
/**
@@ -462,14 +487,13 @@ public static int getLivingEntityLuminanceFromItems(LivingEntity entity) {
462487
}
463488

464489
/**
465-
* Returns the luminance from an item stack.
490+
* {@return the luminance value of the item stack}
466491
*
467492
* @param stack the item stack
468493
* @param submergedInWater {@code true} if the stack is submerged in water, else {@code false}
469-
* @return the luminance of the item
470494
*/
471495
public static int getLuminanceFromItemStack(@NotNull ItemStack stack, boolean submergedInWater) {
472-
return ItemLightSources.getLuminance(stack, submergedInWater);
496+
return INSTANCE.itemLightSources.getLuminance(stack, submergedInWater);
473497
}
474498

475499
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright © 2024 LambdAurora <[email protected]>
3+
*
4+
* This file is part of LambDynamicLights.
5+
*
6+
* Licensed under the Lambda License. For more information,
7+
* see the LICENSE file.
8+
*/
9+
10+
package dev.lambdaurora.lambdynlights.mixin;
11+
12+
import dev.lambdaurora.lambdynlights.LambDynLights;
13+
import dev.lambdaurora.lambdynlights.resource.item.ItemLightSources;
14+
import net.minecraft.client.multiplayer.TagCollector;
15+
import net.minecraft.core.Registry;
16+
import net.minecraft.core.RegistryAccess;
17+
import net.minecraft.resources.ResourceKey;
18+
import org.spongepowered.asm.mixin.Mixin;
19+
import org.spongepowered.asm.mixin.injection.At;
20+
import org.spongepowered.asm.mixin.injection.Inject;
21+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
22+
23+
import java.util.function.Predicate;
24+
25+
@Mixin(TagCollector.class)
26+
public class TagCollectorMixin {
27+
@Inject(
28+
method = "applyTags(Lnet/minecraft/core/RegistryAccess;Ljava/util/function/Predicate;)V",
29+
at = @At("RETURN")
30+
)
31+
private void onTagSynchronization(
32+
RegistryAccess registryAccess, Predicate<ResourceKey<? extends Registry<?>>> predicate,
33+
CallbackInfo ci
34+
) {
35+
LambDynLights.get().itemLightSources.apply(registryAccess);
36+
}
37+
}

0 commit comments

Comments
 (0)