Skip to content

Commit

Permalink
Fix in-world item light source data reload not applying.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Oct 23, 2024
1 parent ba51d64 commit d1107a0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@
- Added settings access in Sodium.
- Updated Simplified Chinese translations ([#242](https://github.com/LambdAurora/LambDynamicLights/pull/242)).

### 3.1.1

- Fixed in-world item light source data reload not applying.

[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 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.1.1"
const val JAVA_VERSION = 21

private var minecraftVersion: String? = null
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.CommonLifecycleEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.minecraft.client.Minecraft;
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.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -54,7 +52,7 @@
* Represents the LambDynamicLights mod.
*
* @author LambdAurora
* @version 3.1.0
* @version 3.1.1
* @since 1.0.0
*/
public class LambDynLights implements ClientModInitializer {
Expand Down Expand Up @@ -82,17 +80,7 @@ public void onInitializeClient() {
.map(EntrypointContainer::getEntrypoint)
.forEach(initializer -> initializer.onInitializeDynamicLights(this.itemLightSources));

ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return Identifier.of(LambDynLightsConstants.NAMESPACE, "dynamiclights_resources");
}

@Override
public void reload(ResourceManager manager) {
LambDynLights.this.itemLightSources.load(manager);
}
});
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(this.itemLightSources);

CommonLifecycleEvents.TAGS_LOADED.register((registries, client) -> {
this.itemLightSources.apply(registries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;
import dev.lambdaurora.lambdynlights.LambDynLights;
import dev.lambdaurora.lambdynlights.LambDynLightsConstants;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSource;
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;
import dev.yumi.commons.TriState;
import dev.yumi.commons.Unit;
import dev.yumi.commons.event.Event;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.io.Resource;
import net.minecraft.resources.io.ResourceManager;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import org.slf4j.Logger;
Expand All @@ -34,25 +39,48 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

/**
* Represents an item light sources manager.
*
* @author LambdAurora
* @version 3.0.0
* @version 3.1.1
* @since 1.3.0
*/
public final class ItemLightSources implements ItemLightSourceManager {
public final class ItemLightSources implements ItemLightSourceManager, IdentifiableResourceReloadListener {
private static final Logger LOGGER = LoggerFactory.getLogger("LambDynamicLights|ItemLightSources");
private static final Identifier RESOURCE_RELOADER_ID = Identifier.of(LambDynLightsConstants.NAMESPACE, "dynamiclights_resources");
private static final String SILENCE_ERROR_KEY = "silence_error";
private static final boolean FORCE_LOG_ERRORS = TriState.fromProperty("lambdynamiclights.resource.force_log_errors")
.toBooleanOrElse(FabricLoader.getInstance().isDevelopmentEnvironment());

private final Event<Identifier, OnRegister> onRegisterEvent = LambDynLights.EVENT_MANAGER.create(OnRegister.class);
private final Minecraft client = Minecraft.getInstance();

private final List<LoadedItemLightSource> loadedLightSources = new ArrayList<>();
private final List<ItemLightSource> lightSources = new ArrayList<>();

@Override
public Identifier getFabricId() {
return RESOURCE_RELOADER_ID;
}

@Override
public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager resourceManager, Profiler prepareProfiler, Profiler applyProfiler, Executor prepareExecutor, Executor applyExecutor) {
return CompletableFuture.supplyAsync(() -> {
this.load(resourceManager);
return Unit.INSTANCE;
}, prepareExecutor)
.thenCompose(synchronizer::whenPrepared)
.thenAcceptAsync((reloadState) -> {
if (this.client.level != null) {
this.apply(this.client.level.registryAccess());
}
}, applyExecutor);
}

/**
* Loads the item light source data from resource pack.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/lambdynlights/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"lambdynlights.tooltip.mode.3": "%s is smooth dynamic lighting.",
"lambdynlights.tooltip.self_light_source": "Enables first-person dynamic lighting. It's recommended to disable this if you're using shaders that has their own dynamic lighting.",
"lambdynlights.tooltip.tnt_lighting": "Sets the TNT dynamic lighting mode.\n- %s disables TNT dynamic lighting.\n- %s sets a constant luminance.\n- %s sets a dynamic luminance.",
"lambdynlights.tooltip.water_sensitive": "Enables the water-sensitive light sources check. This means that some items will not emit light while being submerged in water."
"lambdynlights.tooltip.water_sensitive": "Enables the water-sensitive light sources check. This means that some items will not emit light while being submerged in water.",
"modmenu.bluesky": "Bluesky"
}
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"modmenu.discord": "https://discord.lambdaurora.dev/",
"modmenu.github_releases": "https://github.com/LambdAurora/LambDynamicLights/releases",
"modmenu.modrinth": "https://modrinth.com/mod/lambdynamiclights",
"modmenu.bluesky": "https://bsky.app/profile/lambdaurora.dev",
"modmenu.twitter": "https://twitter.com/LambdAurora"
}
},
Expand Down

0 comments on commit d1107a0

Please sign in to comment.