|
| 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 | +} |
0 commit comments