Skip to content

Commit

Permalink
Update to 1.21.2 and improve settings GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Oct 22, 2024
1 parent ba51d64 commit d03b73d
Show file tree
Hide file tree
Showing 35 changed files with 266 additions and 364 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@
- Added settings access in Sodium.
- Updated Simplified Chinese translations ([#242](https://github.com/LambdAurora/LambDynamicLights/pull/242)).

## 3.2.0

- Updated to Minecraft 1.21.2.
- Added base light of 8 to allays.
- Improved settings GUI, especially the entity dynamic light sources list.
- Tweaked the new dynamic lighting engine introduced in 3.1.0.
- Updated Estonian translations ([#243](https://github.com/LambdAurora/LambDynamicLights/pull/243)).
- Updated [SpruceUI].

[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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- modrinth_exclude.start -->
![Java 21](https://img.shields.io/badge/language-Java%2021-9115ff.svg?style=flat-square) <!-- modrinth_exclude.end -->
[![GitHub license](https://img.shields.io/badge/license-Lambda%20License-c7136d?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambDynamicLights/1.21/LICENSE)
[![GitHub license](https://img.shields.io/badge/license-Lambda%20License-c7136d?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambDynamicLights/1.21.2/LICENSE)
![Environment: Client](https://img.shields.io/badge/environment-client-1976d2?style=flat-square)
[![Mod loader: Fabric]][fabric] <!-- modrinth_exclude.start -->
![Version](https://img.shields.io/github/v/tag/LambdAurora/LambDynamicLights?label=version&style=flat-square)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.yumi.commons.event.Event;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
Expand Down Expand Up @@ -82,7 +83,12 @@ interface RegisterContext {
* @see #register(ItemLike, ItemLuminance)
*/
default void register(ItemLike item, int luminance) {
this.register(new ItemLightSource(ItemPredicate.Builder.item().of(item).build(), luminance));
this.register(new ItemLightSource(
ItemPredicate.Builder.item()
.of(this.registryAccess().lookupOrThrow(Registries.ITEM), item)
.build(),
luminance
));
}

/**
Expand All @@ -94,7 +100,12 @@ default void register(ItemLike item, int luminance) {
* @see #register(ItemLike, int)
*/
default void register(ItemLike item, ItemLuminance luminance) {
this.register(new ItemLightSource(ItemPredicate.Builder.item().of(item).build(), luminance));
this.register(new ItemLightSource(
ItemPredicate.Builder.item()
.of(this.registryAccess().lookupOrThrow(Registries.ITEM), item)
.build(),
luminance
));
}
}
}
18 changes: 0 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,14 @@ logger.lifecycle("Preparing version ${version}...")

repositories {
mavenLocal()
mavenCentral()
maven {
name = "Terraformers"
url = uri("https://maven.terraformersmc.com/releases/")
}
maven {
name = "Gegy"
url = uri("https://maven.gegy.dev")
}
maven {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter {
includeGroup("maven.modrinth")
}
}
}

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

modRuntimeOnly(libs.sodium)

shadow(project(":api", configuration = "namedElements")) {
isTransitive = false
}
Expand Down
8 changes: 8 additions & 0 deletions build_logic/src/main/kotlin/lambdynamiclights.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ loom {
runtimeOnlyLog4j = true
}

repositories {
mavenCentral()
maven {
name = "Gegy"
url = uri("https://maven.gegy.dev")
}
}

dependencies {
minecraft(libs.minecraft)
@Suppress("UnstableApiUsage")
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.1.0"
const val VERSION = "3.2.0"
const val JAVA_VERSION = 21

private var minecraftVersion: String? = null
Expand Down
2 changes: 1 addition & 1 deletion build_logic/src/main/kotlin/lambdynamiclights/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Utils {
}

readme = lines.joinToString("\n")
readme = readme.replace(linkRegex.toRegex(), "![\$1](https://raw.githubusercontent.com/LambdAurora/LambDynamicLights/1.21/\$2)")
readme = readme.replace(linkRegex.toRegex(), "![\$1](https://raw.githubusercontent.com/LambdAurora/LambDynamicLights/1.21.2/\$2)")
return readme
}

Expand Down
16 changes: 7 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[versions]
minecraft = "1.21.1"
fabric-loader = "0.16.5"
fabric-api = "0.105.0+1.21.1"
mappings-yalmm = "2"
minecraft = "1.21.2"
fabric-loader = "0.16.7"
fabric-api = "0.106.1+1.21.2"
mappings-yalmm = "7"
mappings-parchment = "2024.07.28"

# Dependencies
yumi-commons = "1.0.0-alpha.1"
spruceui = "5.1.0+1.21"
pridelib = "1.2.1+1.21"
modmenu = "11.0.1"
sodium = "mc1.21-0.5.9"
spruceui = "6.1.0+1.21.2"
pridelib = "1.3.0+1.21.2"
modmenu = "12.0.0-beta.1"

# Configuration
nightconfig = "3.8.1"
Expand All @@ -32,7 +31,6 @@ 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" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }

# Configuration
nightconfig-core = { module = "com.electronwill.night-config:core", version.ref = "nightconfig" }
Expand Down
28 changes: 8 additions & 20 deletions src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.io.ResourceManager;
import net.minecraft.resources.io.ResourceType;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.PrimedTnt;
Expand Down Expand Up @@ -107,7 +109,7 @@ public void reload(ResourceManager manager) {
});

WorldRenderEvents.START.register(context -> {
Minecraft.getInstance().getProfiler().swap("dynamic_lighting");
Profiler.get().swap("dynamic_lighting");
this.updateAll(context.worldRenderer());
});

Expand Down Expand Up @@ -152,21 +154,10 @@ public int getLastUpdateCount() {
* @return the modified lightmap coordinates
*/
public int getLightmapWithDynamicLight(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, int lightmap) {
return this.getLightmapWithDynamicLight(this.getDynamicLightLevel(pos), lightmap);
}

/**
* Returns the lightmap with combined light levels.
*
* @param entity the entity
* @param lightmap the vanilla lightmap coordinates
* @return the modified lightmap coordinates
*/
public int getLightmapWithDynamicLight(@NotNull Entity entity, int lightmap) {
int posLightLevel = (int) this.getDynamicLightLevel(entity.getOnPos());
int entityLuminance = ((DynamicLightSource) entity).getLuminance();

return this.getLightmapWithDynamicLight(Math.max(posLightLevel, entityLuminance), lightmap);
if (!(level instanceof ClientLevel)) this.lightSourcesLock.readLock().lock();
double light = this.getDynamicLightLevel(pos);
if (!(level instanceof ClientLevel)) this.lightSourcesLock.readLock().unlock();
return this.getLightmapWithDynamicLight(light, lightmap);
}

/**
Expand Down Expand Up @@ -200,10 +191,7 @@ public int getLightmapWithDynamicLight(double dynamicLightLevel, int lightmap) {
* @return the dynamic light level at the specified position
*/
public double getDynamicLightLevel(@NotNull BlockPos pos) {
this.lightSourcesLock.readLock().lock();
double light = this.engine.getDynamicLightLevel(pos);
this.lightSourcesLock.readLock().unlock();
return light;
return this.engine.getDynamicLightLevel(pos);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
package dev.lambdaurora.lambdynlights;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;

/**
* Represents a utility class for compatibility.
Expand All @@ -30,20 +28,10 @@ public static boolean isCanvasInstalled() {
return FabricLoader.getInstance().isModLoaded("canvas");
}

/**
* {@return {@code true} if Sodium is installed, or {@code false} otherwise}
*/
public static boolean isSodiumInstalled() {
return FabricLoader.getInstance().isModLoaded("sodium");
}

public static boolean isSodium05XInstalled() {
return FabricLoader.getInstance().getModContainer("sodium").map(mod -> {
try {
var sodium050 = Version.parse("0.5.0");
var sodium060 = Version.parse("0.6.0-beta.1");
return mod.getMetadata().getVersion().compareTo(sodium050) >= 0
&& mod.getMetadata().getVersion().compareTo(sodium060) < 0;
} catch (VersionParsingException e) {
throw new RuntimeException(e);
}
}).orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ public class LambDynLightsMixinPlugin implements IMixinConfigPlugin {
private final Object2BooleanMap<String> conditionalMixins = new Object2BooleanOpenHashMap<>();

public LambDynLightsMixinPlugin() {
boolean sodium05XInstalled = LambDynLightsCompat.isSodium05XInstalled();
this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.sodium.ArrayLightDataCacheMixin", sodium05XInstalled);
this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.sodium.FlatLightPipelineMixin", sodium05XInstalled);
this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.sodium.LightDataAccessMixin", sodium05XInstalled);
this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.sodium.SodiumOptionsGuiMixin", LambDynLightsCompat.isSodiumInstalled());

this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.DevModeMixin", LambDynLightsConstants.isDevMode());
this.conditionalMixins.put("dev.lambdaurora.lambdynlights.mixin.sodium.SodiumOptionsGuiMixin", LambDynLightsCompat.isSodiumInstalled());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.lambdaurora.lambdynlights.api.DynamicLightHandler;
import dev.lambdaurora.lambdynlights.config.LightSourceSettingEntry;
import net.minecraft.network.chat.Text;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -30,6 +31,8 @@ public interface DynamicLightHandlerHolder<T> {

Text lambdynlights$getName();

Identifier lambdynlights$getId();

@SuppressWarnings("unchecked")
static <T extends Entity> DynamicLightHandlerHolder<T> cast(EntityType<T> entityType) {
return (DynamicLightHandlerHolder<T>) entityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* @author LambdAurora
* @version 3.0.0
* @version 3.2.0
* @since 1.1.0
*/
public final class DynamicLightHandlers {
Expand All @@ -32,6 +32,7 @@ private DynamicLightHandlers() {
* Registers the default handlers.
*/
public static void registerDefaultHandlers() {
registerDynamicLightHandler(EntityType.ALLAY, DynamicLightHandler.makeHandler(blaze -> 8, blaze -> true));
registerDynamicLightHandler(EntityType.BLAZE, DynamicLightHandler.makeHandler(blaze -> 10, blaze -> true));
registerDynamicLightHandler(EntityType.CREEPER, DynamicLightHandler.makeCreeperEntityHandler(null));
registerDynamicLightHandler(EntityType.ENDERMAN, entity -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dev.lambdaurora.spruceui.SpruceTexts;
import dev.lambdaurora.spruceui.option.SpruceBooleanOption;
import dev.lambdaurora.spruceui.option.SpruceOption;
import dev.lambdaurora.spruceui.option.SpruceToggleBooleanOption;
import net.minecraft.TextFormatting;
import net.minecraft.network.chat.Text;
import org.jetbrains.annotations.Nullable;
Expand All @@ -39,16 +40,14 @@ protected SpruceOption buildOption(@Nullable Text tooltip) {
);
}

public static final class Option extends SpruceBooleanOption {
public static final class Option extends SpruceToggleBooleanOption {
public Option(String key, Supplier<Boolean> getter, Consumer<Boolean> setter, @Nullable Text tooltip) {
super(key, getter, setter, tooltip, true);
super(key, getter, setter, tooltip);
}

@Override
public Text getDisplayText() {
boolean value = this.get();
return SpruceTexts.getToggleText(value).copy()
.withStyle(value ? TextFormatting.GREEN : TextFormatting.RED);
return Text.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class DynamicLightingEngine {
private static final double MAX_RADIUS = 7.75;
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
private static final int CELL_SIZE = MathHelper.ceil(MAX_RADIUS);
private static final int MAX_LIGHT_SOURCES = 1024;
public static final int MAX_LIGHT_SOURCES = 1024;
private static final Vec3i[] CELL_OFFSETS;

private final SpatialLookupEntry[] spatialLookupEntries = new SpatialLookupEntry[MAX_LIGHT_SOURCES];
Expand Down
Loading

0 comments on commit d03b73d

Please sign in to comment.