Skip to content

Commit

Permalink
WIP: dynamic lights compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamalam360 committed Dec 13, 2024
1 parent 17de10d commit fa80972
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 35 deletions.
1 change: 0 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dependencies {
modImplementation(libs.accessories.common) {
exclude group: "mezz.jei"
}
modImplementation libs.owo.lib.fabric // Dependency of Accessories

compileOnly libs.mixin.extras.common
annotationProcessor libs.mixin.extras.common
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.github.jamalam360.utility_belt.compat;

import io.github.jamalam360.utility_belt.UtilityBeltInventory;
import io.github.jamalam360.utility_belt.state.StateManager;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

// LambDynamicLights and RyoamicLights
public class LambDynamicLightsLikeCompat {
public static void init(LambDynamicLightsLike lights) {
lights.registerDynamicLightHandler(EntityType.PLAYER, (player) -> getLuminanceInBelt(player, lights));
}

private static int getLuminanceInBelt(Player player, LambDynamicLightsLike lights) {
boolean submerged = isEyeSubmergedInFluid(player, lights);
int luminance = 0;

StateManager stateManager = StateManager.getStateManager(player);
if (stateManager.hasBelt(player)) {
UtilityBeltInventory inv = stateManager.getInventory(player);

for (ItemStack stack : inv.items()) {
luminance = Math.max(luminance, lights.getLuminanceFromItemStack(stack, submerged));
}
}

return luminance;
}

// From LambDynLights mod
private static boolean isEyeSubmergedInFluid(LivingEntity entity, LambDynamicLightsLike lights) {
if (!lights.isWaterSensitiveCheckEnabled()) {
return false;
} else {
BlockPos eyePos = BlockPos.containing(entity.getX(), entity.getEyeY(), entity.getZ());
return !entity.level().getFluidState(eyePos).isEmpty();
}
}

public interface LambDynamicLightsLike {
<T extends LivingEntity> void registerDynamicLightHandler(EntityType<T> type, Function<T, Integer> handler);

int getLuminanceFromItemStack(@NotNull ItemStack stack, boolean submergedInWater);

boolean isWaterSensitiveCheckEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package io.github.jamalam360.utility_belt.util;

import com.google.common.base.Suppliers;
import dev.architectury.platform.Platform;
import io.github.jamalam360.utility_belt.UtilityBelt;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class DynamicTags {
private static final String LAMB_DYNAMIC_LIGHTS = "lambdynlights";
private static final String RYOAMIC_LIGHTS = "ryoamiclights";
private static List<ResourceLocation> extraItems = null;

public static List<ResourceLocation> getExtraItemsAllowedInUtilityBelt() {
if (extraItems == null) {
List<ResourceLocation> list = new ArrayList<>();

if (Platform.isModLoaded(LAMB_DYNAMIC_LIGHTS)) {
UtilityBelt.LOGGER.info("Registering extra Utility Belt entries for LambDynamicLights compatibility.");
if (Platform.isModLoaded(LAMB_DYNAMIC_LIGHTS) || Platform.isModLoaded(RYOAMIC_LIGHTS)) {
UtilityBelt.LOGGER.info("Registering extra Utility Belt entries for dynamic lights compatibility.");
list.add(minecraft("torch"));
list.add(minecraft("redstone_torch"));
list.add(minecraft("soul_torch"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,33 @@
import dev.lambdaurora.lambdynlights.api.DynamicLightsInitializer;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
import io.github.jamalam360.utility_belt.state.StateManager;
import net.minecraft.core.BlockPos;
import io.github.jamalam360.utility_belt.compat.LambDynamicLightsLikeCompat;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

public class LambDynamicLightsCompat implements DynamicLightsInitializer {
@Override
public void onInitializeDynamicLights(ItemLightSourceManager manager) {
UtilityBelt.LOGGER.info("Initializing LambDynamicLights compat for Utility Belt.");
DynamicLightHandlers.registerDynamicLightHandler(EntityType.PLAYER, DynamicLightHandler.makeHandler(this::getLuminanceInBelt, player -> false));
}

private int getLuminanceInBelt(Player player) {
boolean submerged = isEyeSubmergedInFluid(player);
int luminance = 0;

StateManager stateManager = StateManager.getStateManager(player);
if (stateManager.hasBelt(player)) {
UtilityBeltInventory inv = stateManager.getInventory(player);

for (ItemStack stack : inv.items()) {
luminance = Math.max(luminance, LambDynLights.getLuminanceFromItemStack(stack, submerged));
LambDynamicLightsLikeCompat.init(new LambDynamicLightsLikeCompat.LambDynamicLightsLike() {
@Override
public <T extends LivingEntity> void registerDynamicLightHandler(EntityType<T> type, Function<T, Integer> handler) {
DynamicLightHandlers.registerDynamicLightHandler(type, DynamicLightHandler.makeHandler(handler, player -> false));
}
}

return luminance;
}
@Override
public int getLuminanceFromItemStack(@NotNull ItemStack stack, boolean submergedInWater) {
return LambDynLights.getLuminanceFromItemStack(stack, submergedInWater);
}

// From LambDynLights mod
private static boolean isEyeSubmergedInFluid(LivingEntity entity) {
if (!LambDynLights.get().config.getWaterSensitiveCheck().get()) {
return false;
} else {
BlockPos eyePos = BlockPos.containing(entity.getX(), entity.getEyeY(), entity.getZ());
return !entity.level().getFluidState(eyePos).isEmpty();
}
@Override
public boolean isWaterSensitiveCheckEnabled() {
return LambDynLights.get().config.getWaterSensitiveCheck().get();
}
});
}
}
9 changes: 7 additions & 2 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jamlib = "1.2.1+1.21"
# https://modrinth.com/mod/accessories/versions
accessories = "1.1.0-beta.11+1.21.1"

# https://modrinth.com/mod/owo/versions
# https://modrinth.com/mod/owo-lib/versions
owo-lib-fabric = "0.12.15+1.21"
owo-lib-neoforge = "0.12.15-beta.5+1.21"
owo-lib-neoforge = "0.12.15-beta.7+1.21"

# https://github.com/LlamaLad7/MixinExtras/releases
mixin-extras = "0.4.1"
Expand All @@ -28,6 +28,9 @@ modmenu = "11.0.1"
# https://modrinth.com/mod/lambdynamiclights/versions
lambdynamiclights = "3.1.0+1.21.1"

# https://modrinth.com/mod/ryoamiclights
ryoamic-lights = "0.2.11+mc1.21.1-neoforge"

# https://modrinth.com/mod/sodium/versions
sodium = "mc1.21-0.6.0-beta.2-fabric"

Expand Down Expand Up @@ -58,4 +61,6 @@ modmenu = { module = "maven.modrinth:modmenu", version.ref = "modmenu" }

lambdynamiclights = { module = "dev.lambdaurora.lambdynamiclights:lambdynamiclights-runtime", version.ref = "lambdynamiclights" }

ryoamic-lights = { module = "maven.modrinth:ryoamiclights", version.ref = "ryoamic-lights" }

sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
3 changes: 3 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
modImplementation libs.accessories.neoforge
modImplementation libs.owo.lib.neoforge // Dependency of Accessories

// Compat
modImplementation libs.ryoamic.lights

forgeRuntimeLibrary "blue.endless:jankson:1.2.3" // Dependency of JamLib
forgeRuntimeLibrary "io.wispforest:endec:0.1.5" // Dependency of Accessories

Expand Down

0 comments on commit fa80972

Please sign in to comment.