Skip to content

Commit

Permalink
Add support for Trinkets and Accessories.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Nov 29, 2024
2 parents b0e484b + 2f595a5 commit 73d2337
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 0 deletions.
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.

## 4.0.0

- Added the ability to define entity light sources in resource packs.
Expand Down
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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 @@ -73,6 +78,10 @@ dependencies {
this.isTransitive = false
}

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

shadow(libs.yumi.commons.core) {
isTransitive = false
}
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.2"
spruceui = "6.2.0+1.21.3"
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 @@ -32,6 +34,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
11 changes: 11 additions & 0 deletions src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dev.lambdaurora.lambdynlights.api.behavior.DynamicLightBehaviorManager;
import dev.lambdaurora.lambdynlights.api.entity.EntityLightSourceManager;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
import dev.lambdaurora.lambdynlights.compat.CompatLayer;
import dev.lambdaurora.lambdynlights.engine.DynamicLightBehaviorSources;
import dev.lambdaurora.lambdynlights.engine.DynamicLightingEngine;
import dev.lambdaurora.lambdynlights.engine.source.DeferredDynamicLightSource;
Expand Down Expand Up @@ -510,6 +511,16 @@ public static int getLivingEntityLuminanceFromItems(LivingEntity entity) {
luminance = Math.max(luminance, INSTANCE.itemLightSources.getLuminance(equipped, submergedInFluid));
}

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

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

return luminance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
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(ItemLightSourceManager itemLightSources, 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, itemLightSources.getLuminance(equipped.stack(), submergedInWater));

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

return luminance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
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 itemLightSources the item light source manager
* @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(ItemLightSourceManager itemLightSources, 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,44 @@
/*
* 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 dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
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(ItemLightSourceManager itemLightSources, 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, itemLightSources.getLuminance(equipped.getB(), submergedInWater));

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

return luminance;
}
}

0 comments on commit 73d2337

Please sign in to comment.