Skip to content

Commit

Permalink
Merge v3.1.4 changes into 1.21.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Nov 29, 2024
2 parents 3a40f39 + be6aa16 commit 2f595a5
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@

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

### 3.1.4

- Added support for Trinkets and Accessories.

## 3.2.0

- Updated to Minecraft 1.21.2.
Expand All @@ -241,6 +245,11 @@
- Same changes as v3.1.3 but for 1.21.3.
- Fixed item frames and other "block-attached" entities not ticking properly on the integrated server.

### 3.2.4

- Same changes as v3.1.4 but for 1.21.3.
- Added support for Trinkets and Accessories.

[SpruceUI]: https://github.com/LambdAurora/SpruceUI "SpruceUI page"
[pridelib]: https://github.com/Queerbric/pridelib "Pridelib page"
[Sodium]: https://modrinth.com/mod/sodium "Sodium Modrinth page"
Expand Down
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ repositories {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
maven {
name = "Ladysnake Libs"
url = uri("https://maven.ladysnake.org/releases")
}
maven { url = uri("https://maven.wispforest.io/releases") }
}

loom {
Expand All @@ -50,6 +55,10 @@ dependencies {
this.isTransitive = false
}

// Mod compatibility
modCompileOnly(libs.trinkets)
modCompileOnly(libs.accessories)

shadow(project(":api", configuration = "namedElements")) {
isTransitive = false
}
Expand Down
2 changes: 1 addition & 1 deletion build_logic/src/main/kotlin/lambdynamiclights/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.accessors.dm.LibrariesForLibs
object Constants {
const val GROUP = "dev.lambdaurora"
const val NAME = "lambdynamiclights"
const val VERSION = "3.2.3"
const val VERSION = "3.2.4"
const val JAVA_VERSION = 21

private var minecraftVersion: String? = null
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ yumi-commons = "1.0.0-alpha.1"
spruceui = "6.1.0+1.21.2"
pridelib = "1.3.0+1.21.2"
modmenu = "12.0.0-beta.1"
trinkets = "3.10.0"
accessories = "1.2.1-beta.2+1.21.2"

# Configuration
nightconfig = "3.8.1"
Expand All @@ -31,6 +33,8 @@ yumi-commons-event = { module = "dev.yumi.commons:yumi-commons-event", version.r
spruceui = { module = "dev.lambdaurora:spruceui", version.ref = "spruceui" }
pridelib = { module = "io.github.queerbric:pridelib", version.ref = "pridelib" }
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
trinkets = { module = "dev.emi:trinkets", version.ref = "trinkets" }
accessories = { module = "io.wispforest:accessories-fabric", version.ref = "accessories" }

# Configuration
nightconfig-core = { module = "com.electronwill.night-config:core", version.ref = "nightconfig" }
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.lambdaurora.lambdynlights.accessor.WorldRendererAccessor;
import dev.lambdaurora.lambdynlights.api.DynamicLightHandlers;
import dev.lambdaurora.lambdynlights.api.DynamicLightsInitializer;
import dev.lambdaurora.lambdynlights.compat.CompatLayer;
import dev.lambdaurora.lambdynlights.engine.DynamicLightingEngine;
import dev.lambdaurora.lambdynlights.resource.item.ItemLightSources;
import dev.yumi.commons.event.EventManager;
Expand Down Expand Up @@ -335,6 +336,20 @@ public static void warn(Logger logger, String msg, Object... args) {
logger.warn(msg, args);
}

/**
* Logs an error message.
*
* @param logger the logger to use
* @param msg the message to log
*/
public static void error(Logger logger, String msg, Object... args) {
if (!FabricLoader.getInstance().isDevelopmentEnvironment()) {
msg = "[LambDynLights] " + msg;
}

logger.error(msg, args);
}

/**
* Schedules a chunk rebuild at the specified chunk position.
*
Expand Down Expand Up @@ -411,6 +426,16 @@ public static int getLivingEntityLuminanceFromItems(LivingEntity entity) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped, submergedInFluid));
}

if (luminance < 15) {
for (var compat : CompatLayer.LAYERS) {
luminance = Math.max(luminance, compat.getLivingEntityLuminanceFromItems(entity, submergedInFluid));

if (luminance >= 15) {
break;
}
}
}

return luminance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright © 2024 LambdAurora <[email protected]>
*
* This file is part of LambDynamicLights.
*
* Licensed under the Lambda License. For more information,
* see the LICENSE file.
*/

package dev.lambdaurora.lambdynlights.compat;

import dev.lambdaurora.lambdynlights.LambDynLights;
import io.wispforest.accessories.api.AccessoriesCapability;
import net.minecraft.world.entity.LivingEntity;

/**
* Represents the Accessories compatibility layer.
*
* @author LambdAurora
* @version 3.1.4
* @since 3.1.4
*/
final class AccessoriesCompat implements CompatLayer {
@Override
public int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater) {
int luminance = 0;
var component = AccessoriesCapability.get(entity);

if (component != null) {
for (var equipped : component.getAllEquipped()) {
if (!equipped.stack().isEmpty()) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped.stack(), submergedInWater));

if (luminance >= 15) {
break;
}
}
}
}

return luminance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright © 2024 LambdAurora <[email protected]>
*
* This file is part of LambDynamicLights.
*
* Licensed under the Lambda License. For more information,
* see the LICENSE file.
*/

package dev.lambdaurora.lambdynlights.compat;

import dev.lambdaurora.lambdynlights.LambDynLights;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.Range;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
* Represents a compatibility layer with another mod.
*
* @author LambdAurora
* @version 3.1.4
* @since 3.1.4
*/
public interface CompatLayer {
Logger LOGGER = LoggerFactory.getLogger("LambDynamicLights|CompatLayer");

/**
* Loaded compatibility layers.
*/
List<CompatLayer> LAYERS = initLayers();

/**
* Gets the luminance of a living entity from its equipped items.
*
* @param entity the living entity for which to get the luminance from
* @param submergedInWater {@code true} if the entity is submerged in water, or {@code false} otherwise
* @return the luminance of a living entity from its equipped items
*/
@Range(from = 0, to = 15)
int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater);

private static List<CompatLayer> initLayers() {
var layers = new ArrayList<CompatLayer>();

try {
if (FabricLoader.getInstance().isModLoaded("accessories")) {
layers.add(new AccessoriesCompat());
} else if (FabricLoader.getInstance().isModLoaded("trinkets")) {
layers.add(new TrinketsCompat());
}
} catch (LinkageError e) {
LambDynLights.error(
LOGGER,
"Could not load a compatibility layer: THIS IS VERY WRONG, PLEASE REPORT THIS ERROR TO LAMBDYNAMICLIGHTS' AUTHOR ASAP.",
e
);
}

return layers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright © 2024 LambdAurora <[email protected]>
*
* This file is part of LambDynamicLights.
*
* Licensed under the Lambda License. For more information,
* see the LICENSE file.
*/

package dev.lambdaurora.lambdynlights.compat;

import dev.emi.trinkets.api.TrinketsApi;
import dev.lambdaurora.lambdynlights.LambDynLights;
import net.minecraft.world.entity.LivingEntity;

/**
* Represents the Trinkets compatibility layer.
*
* @author LambdAurora
* @version 3.1.4
* @since 3.1.4
*/
final class TrinketsCompat implements CompatLayer {
@Override
public int getLivingEntityLuminanceFromItems(LivingEntity entity, boolean submergedInWater) {
int luminance = 0;
var component = TrinketsApi.getTrinketComponent(entity);

if (component.isPresent()) {
for (var equipped : component.get().getAllEquipped()) {
if (!equipped.getB().isEmpty()) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(equipped.getB(), submergedInWater));

if (luminance >= 15) {
break;
}
}
}
}

return luminance;
}
}

0 comments on commit 2f595a5

Please sign in to comment.