-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/dev/lambdaurora/lambdynlights/compat/AccessoriesCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/dev/lambdaurora/lambdynlights/compat/CompatLayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/dev/lambdaurora/lambdynlights/compat/TrinketsCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |