Skip to content

Commit be6aa16

Browse files
committed
Add support for Trinkets and Accessories.
1 parent 5358741 commit be6aa16

File tree

8 files changed

+195
-1
lines changed

8 files changed

+195
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@
216216

217217
- Fixed item frames and other "block-attached" entities not ticking properly on the integrated server.
218218

219+
### 3.1.4
220+
221+
- Added support for Trinkets and Accessories.
222+
219223
[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
220224
[pridelib]: https://github.com/Queerbric/pridelib "Pridelib page"
221225
[Sodium]: https://modrinth.com/mod/sodium "Sodium Modrinth page"

build.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ repositories {
3333
name = "ParchmentMC"
3434
url = uri("https://maven.parchmentmc.org")
3535
}
36+
maven {
37+
name = "Ladysnake Libs"
38+
url = uri("https://maven.ladysnake.org/releases")
39+
}
40+
maven { url = uri("https://maven.wispforest.io/releases") }
3641
exclusiveContent {
3742
forRepository {
3843
maven {
@@ -66,6 +71,10 @@ dependencies {
6671
this.isTransitive = false
6772
}
6873

74+
// Mod compatibility
75+
modCompileOnly(libs.trinkets)
76+
modCompileOnly(libs.accessories)
77+
6978
modRuntimeOnly(libs.sodium)
7079

7180
shadow(project(":api", configuration = "namedElements")) {

build_logic/src/main/kotlin/lambdynamiclights/Constants.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.gradle.accessors.dm.LibrariesForLibs
55
object Constants {
66
const val GROUP = "dev.lambdaurora"
77
const val NAME = "lambdynamiclights"
8-
const val VERSION = "3.1.3"
8+
const val VERSION = "3.1.4"
99
const val JAVA_VERSION = 21
1010

1111
private var minecraftVersion: String? = null

gradle/libs.versions.toml

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ yumi-commons = "1.0.0-alpha.1"
1010
spruceui = "5.1.0+1.21"
1111
pridelib = "1.2.1+1.21"
1212
modmenu = "11.0.1"
13+
trinkets = "3.10.0"
14+
accessories = "1.1.0-beta.16+1.21.1"
1315
sodium = "mc1.21-0.5.9"
1416

1517
# Configuration
@@ -32,6 +34,8 @@ yumi-commons-event = { module = "dev.yumi.commons:yumi-commons-event", version.r
3234
spruceui = { module = "dev.lambdaurora:spruceui", version.ref = "spruceui" }
3335
pridelib = { module = "io.github.queerbric:pridelib", version.ref = "pridelib" }
3436
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
37+
trinkets = { module = "dev.emi:trinkets", version.ref = "trinkets" }
38+
accessories = { module = "io.wispforest:accessories-fabric", version.ref = "accessories" }
3539
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
3640

3741
# Configuration

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

+25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dev.lambdaurora.lambdynlights.accessor.WorldRendererAccessor;
1313
import dev.lambdaurora.lambdynlights.api.DynamicLightHandlers;
1414
import dev.lambdaurora.lambdynlights.api.DynamicLightsInitializer;
15+
import dev.lambdaurora.lambdynlights.compat.CompatLayer;
1516
import dev.lambdaurora.lambdynlights.engine.DynamicLightingEngine;
1617
import dev.lambdaurora.lambdynlights.resource.item.ItemLightSources;
1718
import dev.yumi.commons.event.EventManager;
@@ -347,6 +348,20 @@ public static void warn(Logger logger, String msg, Object... args) {
347348
logger.warn(msg, args);
348349
}
349350

351+
/**
352+
* Logs an error message.
353+
*
354+
* @param logger the logger to use
355+
* @param msg the message to log
356+
*/
357+
public static void error(Logger logger, String msg, Object... args) {
358+
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) {
359+
msg = "[LambDynLights] " + msg;
360+
}
361+
362+
logger.error(msg, args);
363+
}
364+
350365
/**
351366
* Schedules a chunk rebuild at the specified chunk position.
352367
*
@@ -423,6 +438,16 @@ public static int getLivingEntityLuminanceFromItems(LivingEntity entity) {
423438
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, submergedInFluid));
424439
}
425440

441+
if (luminance < 15) {
442+
for (var compat : CompatLayer.LAYERS) {
443+
luminance = Math.max(luminance, compat.getLivingEntityLuminanceFromItems(entity, submergedInFluid));
444+
445+
if (luminance >= 15) {
446+
break;
447+
}
448+
}
449+
}
450+
426451
return luminance;
427452
}
428453

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.compat;
11+
12+
import dev.lambdaurora.lambdynlights.LambDynLights;
13+
import io.wispforest.accessories.api.AccessoriesCapability;
14+
import net.minecraft.world.entity.LivingEntity;
15+
16+
/**
17+
* Represents the Accessories compatibility layer.
18+
*
19+
* @author LambdAurora
20+
* @version 3.1.4
21+
* @since 3.1.4
22+
*/
23+
final class AccessoriesCompat implements CompatLayer {
24+
@Override
25+
public int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater) {
26+
int luminance = 0;
27+
var component = AccessoriesCapability.get(entity);
28+
29+
if (component != null) {
30+
for (var equipped : component.getAllEquipped()) {
31+
if (!equipped.stack().isEmpty()) {
32+
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped.stack(), submergedInWater));
33+
34+
if (luminance >= 15) {
35+
break;
36+
}
37+
}
38+
}
39+
}
40+
41+
return luminance;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.compat;
11+
12+
import dev.lambdaurora.lambdynlights.LambDynLights;
13+
import net.fabricmc.loader.api.FabricLoader;
14+
import net.minecraft.world.entity.LivingEntity;
15+
import org.jetbrains.annotations.Range;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
/**
23+
* Represents a compatibility layer with another mod.
24+
*
25+
* @author LambdAurora
26+
* @version 3.1.4
27+
* @since 3.1.4
28+
*/
29+
public interface CompatLayer {
30+
Logger LOGGER = LoggerFactory.getLogger("LambDynamicLights|CompatLayer");
31+
32+
/**
33+
* Loaded compatibility layers.
34+
*/
35+
List<CompatLayer> LAYERS = initLayers();
36+
37+
/**
38+
* Gets the luminance of a living entity from its equipped items.
39+
*
40+
* @param entity the living entity for which to get the luminance from
41+
* @param submergedInWater {@code true} if the entity is submerged in water, or {@code false} otherwise
42+
* @return the luminance of a living entity from its equipped items
43+
*/
44+
@Range(from = 0, to = 15)
45+
int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater);
46+
47+
private static List<CompatLayer> initLayers() {
48+
var layers = new ArrayList<CompatLayer>();
49+
50+
try {
51+
if (FabricLoader.getInstance().isModLoaded("accessories")) {
52+
layers.add(new AccessoriesCompat());
53+
} else if (FabricLoader.getInstance().isModLoaded("trinkets")) {
54+
layers.add(new TrinketsCompat());
55+
}
56+
} catch (LinkageError e) {
57+
LambDynLights.error(
58+
LOGGER,
59+
"Could not load a compatibility layer: THIS IS VERY WRONG, PLEASE REPORT THIS ERROR TO LAMBDYNAMICLIGHTS' AUTHOR ASAP.",
60+
e
61+
);
62+
}
63+
64+
return layers;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.compat;
11+
12+
import dev.emi.trinkets.api.TrinketsApi;
13+
import dev.lambdaurora.lambdynlights.LambDynLights;
14+
import net.minecraft.world.entity.LivingEntity;
15+
16+
/**
17+
* Represents the Trinkets compatibility layer.
18+
*
19+
* @author LambdAurora
20+
* @version 3.1.4
21+
* @since 3.1.4
22+
*/
23+
final class TrinketsCompat implements CompatLayer {
24+
@Override
25+
public int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater) {
26+
int luminance = 0;
27+
var component = TrinketsApi.getTrinketComponent(entity);
28+
29+
if (component.isPresent()) {
30+
for (var equipped : component.get().getAllEquipped()) {
31+
if (!equipped.getB().isEmpty()) {
32+
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped.getB(), submergedInWater));
33+
34+
if (luminance >= 15) {
35+
break;
36+
}
37+
}
38+
}
39+
}
40+
41+
return luminance;
42+
}
43+
}

0 commit comments

Comments
 (0)