From e86b721c77c4002ef447225c52a2e355642a94a9 Mon Sep 17 00:00:00 2001 From: TexTrue <65154269+TexBlock@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:02:31 +0800 Subject: [PATCH] fix compatible with `include LDL` mods (maybe? idk), use `renderWorldLastEvent`, change modid to `ryoamiclights` --- .github/workflows/release.yml | 5 ++- CHANGELOG.md | 4 +- gradle.properties | 2 +- .../lambdynlights/DynamicLightSource.java | 22 ++++----- .../lambdynlights/LambDynLights.java | 45 ++++++++++++------- .../mixin/EntityRendererMixin.java | 2 +- .../lambdynlights/mixin/WorldMixin.java | 2 +- .../mixin/forge/WorldRendererMixin.java | 28 ------------ .../AbstractDecorationEntityMixin.java | 4 +- .../AbstractMinecartEntityMixin.java | 6 +-- .../mixin/lightsource/BlockEntityMixin.java | 26 +++++------ .../mixin/lightsource/EntityMixin.java | 28 ++++++------ .../ExplosiveProjectileEntityMixin.java | 4 +- .../mixin/lightsource/LivingEntityMixin.java | 4 +- .../mixin/lightsource/PlayerEntityMixin.java | 4 +- .../mixin/lightsource/TntEntityMixin.java | 8 ++-- src/main/resources/META-INF/mods.toml | 12 ++--- src/main/resources/lambdynlights.mixins.json | 1 - 18 files changed, 97 insertions(+), 110 deletions(-) delete mode 100644 src/main/java/dev/lambdaurora/lambdynlights/mixin/forge/WorldRendererMixin.java diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48283046..974f3263 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,9 @@ name: Publish Release -on: [workflow_dispatch] # Manual trigger +on: + release: + types: + - published permissions: contents: write diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ff73b0..e9a2cd44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,4 @@ ## Changelog -- port to forge \ No newline at end of file +- change modid to `ryoamiclights` +- fix compatible with `include LDL` mods (maybe? idk). +- use `renderWorldLastEvent`. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e3ece835..c9b9e6c7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ quilt_mappings=1.19.3+build.8 forge_version=1.19.3-44.1.23 # Mod Properties -mod_version = 0.1.1 +mod_version = 0.1.2 maven_group = dev.lambdaurora archives_base_name = Ryoamiclights modrinth_id=reCfnRvJ diff --git a/src/main/java/dev/lambdaurora/lambdynlights/DynamicLightSource.java b/src/main/java/dev/lambdaurora/lambdynlights/DynamicLightSource.java index 1e287f40..4f8c89a9 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/DynamicLightSource.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/DynamicLightSource.java @@ -27,28 +27,28 @@ public interface DynamicLightSource { * * @return the X coordinate */ - double getDynamicLightX(); + double ryoamicLights$getDynamicLightX(); /** * Returns the dynamic light source Y coordinate. * * @return the Y coordinate */ - double getDynamicLightY(); + double ryoamicLights$getDynamicLightY(); /** * Returns the dynamic light source Z coordinate. * * @return the Z coordinate */ - double getDynamicLightZ(); + double ryoamicLights$getDynamicLightZ(); /** * Returns the dynamic light source world. * * @return the world instance */ - World getDynamicLightWorld(); + World ryoamicLights$getDynamicLightWorld(); /** * Returns whether the dynamic light is enabled or not. @@ -68,14 +68,14 @@ default boolean isDynamicLightEnabled() { */ @ApiStatus.Internal default void setDynamicLightEnabled(boolean enabled) { - this.resetDynamicLight(); + this.ryoamicLights$resetDynamicLight(); if (enabled) LambDynLights.get().addLightSource(this); else LambDynLights.get().removeLightSource(this); } - void resetDynamicLight(); + void ryoamicLights$resetDynamicLight(); /** * Returns the luminance of the light source. @@ -83,21 +83,21 @@ default void setDynamicLightEnabled(boolean enabled) { * * @return the luminance of the light source */ - int getLuminance(); + int ryoamicLights$getLuminance(); /** * Executed at each tick. */ - void dynamicLightTick(); + void ryoamicLights$dynamicLightTick(); /** * Returns whether this dynamic light source should update. * * @return {@code true} if this dynamic light source should update, else {@code false} */ - boolean shouldUpdateDynamicLight(); + boolean ryoamicLights$shouldUpdateDynamicLight(); - boolean lambdynlights$updateDynamicLight(@NotNull WorldRenderer renderer); + boolean ryoamicLights$updateDynamicLight(@NotNull WorldRenderer renderer); - void lambdynlights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer); + void ryoamicLights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer); } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java b/src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java index dadd995f..cab4d7ae 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/LambDynLights.java @@ -32,6 +32,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderLevelStageEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.IExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; @@ -55,7 +57,7 @@ */ @Mod(LambDynLights.NAMESPACE) public class LambDynLights { - public static final String NAMESPACE = "lambdynlights"; + public static final String NAMESPACE = "ryoamiclights"; private static final double MAX_RADIUS = 7.75; private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS; private static LambDynLights INSTANCE; @@ -69,6 +71,7 @@ public class LambDynLights { public LambDynLights() { ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); EnvExecutor.runInEnv(Dist.CLIENT, () -> this::onInitializeClient); + EnvExecutor.runInEnv(Dist.CLIENT, () -> () -> Mod.EventBusSubscriber.Bus.FORGE.bus().get().addListener(this::renderWorldLastEvent)); } public void onInitializeClient() { @@ -83,6 +86,14 @@ public void onInitializeClient() { DynamicLightHandlers.registerDefaultHandlers(); } + @SubscribeEvent + public void renderWorldLastEvent(RenderLevelStageEvent event) { + if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRIPWIRE_BLOCKS) { + MinecraftClient.getInstance().getProfiler().push("dynamic_lighting"); + get().updateAll(event.getLevelRenderer()); + } + } + /** * Updates all light sources. * @@ -99,7 +110,7 @@ public void updateAll(@NotNull WorldRenderer renderer) { this.lightSourcesLock.readLock().lock(); for (var lightSource : this.dynamicLightSources) { - if (lightSource.lambdynlights$updateDynamicLight(renderer)) this.lastUpdateCount++; + if (lightSource.ryoamicLights$updateDynamicLight(renderer)) this.lastUpdateCount++; } this.lightSourcesLock.readLock().unlock(); } @@ -134,7 +145,7 @@ public int getLightmapWithDynamicLight(@NotNull BlockPos pos, int lightmap) { */ public int getLightmapWithDynamicLight(@NotNull Entity entity, int lightmap) { int posLightLevel = (int) this.getDynamicLightLevel(entity.getBlockPos()); - int entityLuminance = ((DynamicLightSource) entity).getLuminance(); + int entityLuminance = ((DynamicLightSource) entity).ryoamicLights$getLuminance(); return this.getLightmapWithDynamicLight(Math.max(posLightLevel, entityLuminance), lightmap); } @@ -189,12 +200,12 @@ public double getDynamicLightLevel(@NotNull BlockPos pos) { * @return the dynamic light level at the specified position */ public static double maxDynamicLightLevel(@NotNull BlockPos pos, @NotNull DynamicLightSource lightSource, double currentLightLevel) { - int luminance = lightSource.getLuminance(); + int luminance = lightSource.ryoamicLights$getLuminance(); if (luminance > 0) { // Can't use Entity#squaredDistanceTo because of eye Y coordinate. - double dx = pos.getX() - lightSource.getDynamicLightX() + 0.5; - double dy = pos.getY() - lightSource.getDynamicLightY() + 0.5; - double dz = pos.getZ() - lightSource.getDynamicLightZ() + 0.5; + double dx = pos.getX() - lightSource.ryoamicLights$getDynamicLightX() + 0.5; + double dy = pos.getY() - lightSource.ryoamicLights$getDynamicLightY() + 0.5; + double dz = pos.getZ() - lightSource.ryoamicLights$getDynamicLightZ() + 0.5; double distanceSquared = dx * dx + dy * dy + dz * dz; // 7.75 because else we would have to update more chunks and that's not a good idea. @@ -216,7 +227,7 @@ public static double maxDynamicLightLevel(@NotNull BlockPos pos, @NotNull Dynami * @param lightSource the light source to add */ public void addLightSource(@NotNull DynamicLightSource lightSource) { - if (!lightSource.getDynamicLightWorld().isClient()) + if (!lightSource.ryoamicLights$getDynamicLightWorld().isClient()) return; if (!this.config.getDynamicLightsMode().isEnabled()) return; @@ -234,7 +245,7 @@ public void addLightSource(@NotNull DynamicLightSource lightSource) { * @return {@code true} if the light source is tracked, else {@code false} */ public boolean containsLightSource(@NotNull DynamicLightSource lightSource) { - if (!lightSource.getDynamicLightWorld().isClient()) + if (!lightSource.ryoamicLights$getDynamicLightWorld().isClient()) return false; boolean result; @@ -274,7 +285,7 @@ public void removeLightSource(@NotNull DynamicLightSource lightSource) { if (it.equals(lightSource)) { dynamicLightSources.remove(); if (MinecraftClient.getInstance().worldRenderer != null) - lightSource.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); + lightSource.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); break; } } @@ -294,9 +305,9 @@ public void clearLightSources() { it = dynamicLightSources.next(); dynamicLightSources.remove(); if (MinecraftClient.getInstance().worldRenderer != null) { - if (it.getLuminance() > 0) - it.resetDynamicLight(); - it.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); + if (it.ryoamicLights$getLuminance() > 0) + it.ryoamicLights$resetDynamicLight(); + it.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); } } @@ -318,9 +329,9 @@ public void removeLightSources(@NotNull Predicate filter) { if (filter.test(it)) { dynamicLightSources.remove(); if (MinecraftClient.getInstance().worldRenderer != null) { - if (it.getLuminance() > 0) - it.resetDynamicLight(); - it.lambdynlights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); + if (it.ryoamicLights$getLuminance() > 0) + it.ryoamicLights$resetDynamicLight(); + it.ryoamicLights$scheduleTrackedChunksRebuild(MinecraftClient.getInstance().worldRenderer); } break; } @@ -424,7 +435,7 @@ public static void updateTrackedChunks(@NotNull BlockPos chunkPos, @Nullable Lon */ public static void updateTracking(@NotNull DynamicLightSource lightSource) { boolean enabled = lightSource.isDynamicLightEnabled(); - int luminance = lightSource.getLuminance(); + int luminance = lightSource.ryoamicLights$getLuminance(); if (!enabled && luminance > 0) { lightSource.setDynamicLightEnabled(true); diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityRendererMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityRendererMixin.java index bd8318c2..3ffdf4c2 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityRendererMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/EntityRendererMixin.java @@ -27,7 +27,7 @@ private void onGetBlockLight(T entity, BlockPos pos, CallbackInfoReturnable= 15) cir.setReturnValue(entityLuminance); diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/WorldMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/WorldMixin.java index fa4d79a9..e037d2ac 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/WorldMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/WorldMixin.java @@ -43,7 +43,7 @@ private void onBlockEntityTick(CallbackInfo ci, Profiler profiler, Iterator 0.1D || Math.abs(deltaY) > 0.1D || Math.abs(deltaZ) > 0.1D || luminance != this.lambdynlights$lastLuminance) { this.lambdynlights$prevX = this.getX(); @@ -197,7 +197,7 @@ public int getLuminance() { } // Schedules the rebuild of removed chunks. - this.lambdynlights$scheduleTrackedChunksRebuild(renderer); + this.ryoamicLights$scheduleTrackedChunksRebuild(renderer); // Update tracked lit chunks. this.lambdynlights$trackedLitChunkPos = newPos; return true; @@ -206,7 +206,7 @@ public int getLuminance() { } @Override - public void lambdynlights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer) { + public void ryoamicLights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer) { if (MinecraftClient.getInstance().world == this.world) for (long pos : this.lambdynlights$trackedLitChunkPos) { LambDynLights.scheduleChunkRebuild(renderer, pos); diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/ExplosiveProjectileEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/ExplosiveProjectileEntityMixin.java index 8fd2d3e8..dc2c37c3 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/ExplosiveProjectileEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/ExplosiveProjectileEntityMixin.java @@ -25,13 +25,13 @@ public ExplosiveProjectileEntityMixin(EntityType type, World world) { } @Override - public void dynamicLightTick() { + public void ryoamicLights$dynamicLightTick() { if (!this.isDynamicLightEnabled()) this.setDynamicLightEnabled(true); } @Override - public int getLuminance() { + public int ryoamicLights$getLuminance() { if (LambDynLights.get().config.getEntitiesLightSource().get() && DynamicLightHandlers.canLightUp(this)) return 14; return 0; diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java index 0d1b3ac0..b7098cfe 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/LivingEntityMixin.java @@ -30,7 +30,7 @@ public LivingEntityMixin(EntityType type, World world) { } @Override - public void dynamicLightTick() { + public void ryoamicLights$dynamicLightTick() { if (!LambDynLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this)) { this.lambdynlights$luminance = 0; return; @@ -56,7 +56,7 @@ public void dynamicLightTick() { } @Override - public int getLuminance() { + public int ryoamicLights$getLuminance() { return this.lambdynlights$luminance; } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java index c9662f19..d44f9536 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/PlayerEntityMixin.java @@ -37,7 +37,7 @@ protected PlayerEntityMixin(EntityType entityType, World } @Override - public void dynamicLightTick() { + public void ryoamicLights$dynamicLightTick() { if (!DynamicLightHandlers.canLightUp(this)) { this.lambdynlights$luminance = 0; return; @@ -68,7 +68,7 @@ public void dynamicLightTick() { } @Override - public int getLuminance() { + public int ryoamicLights$getLuminance() { return this.lambdynlights$luminance; } } diff --git a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java index 2829f67c..150a0f74 100644 --- a/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java +++ b/src/main/java/dev/lambdaurora/lambdynlights/mixin/lightsource/TntEntityMixin.java @@ -54,16 +54,16 @@ private void onTick(CallbackInfo ci) { this.setDynamicLightEnabled(false); } else { if (!LambDynLights.get().config.getEntitiesLightSource().get() || !DynamicLightHandlers.canLightUp(this)) - this.resetDynamicLight(); + this.ryoamicLights$resetDynamicLight(); else - this.dynamicLightTick(); + this.ryoamicLights$dynamicLightTick(); LambDynLights.updateTracking(this); } } } @Override - public void dynamicLightTick() { + public void ryoamicLights$dynamicLightTick() { if (this.isOnFire()) { this.lambdynlights$luminance = 15; } else { @@ -78,7 +78,7 @@ public void dynamicLightTick() { } @Override - public int getLuminance() { + public int ryoamicLights$getLuminance() { return this.lambdynlights$luminance; } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b863754f..42bb08e3 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -3,7 +3,7 @@ loaderVersion="[44,)" license="MIT" [[mods]] -modId="lambdynlights" +modId="ryoamiclights" version="${version}" displayName="RyoamicLights" displayURL="https://github.com/ThinkingStudios/LambDynamicLights-Forge" @@ -16,28 +16,28 @@ LambDynamicLights unofficial forge port. Adds dynamic lights to the game. ''' -[[dependencies.lambdynlights]] +[[dependencies.ryoamiclights]] modId = "forge" mandatory = true versionRange = "[44,)" ordering = "NONE" side = "BOTH" -[[dependencies.lambdynlights]] +[[dependencies.ryoamiclights]] modId = "minecraft" mandatory = true versionRange = "[1.19.3,]" ordering = "NONE" side = "BOTH" -[[dependencies.lambdynlights]] +[[dependencies.ryoamiclights]] modId = "architectury" mandatory = true -versionRange = "[7,)" +versionRange = "*" ordering = "NONE" side = "BOTH" -[[dependencies.lambdynlights]] +[[dependencies.ryoamiclights]] modId = "spruceui" mandatory = true versionRange = "*" diff --git a/src/main/resources/lambdynlights.mixins.json b/src/main/resources/lambdynlights.mixins.json index 2b000443..d7f192d4 100644 --- a/src/main/resources/lambdynlights.mixins.json +++ b/src/main/resources/lambdynlights.mixins.json @@ -13,7 +13,6 @@ "MinecraftClientMixin", "VideoOptionsScreenMixin", "WorldMixin", - "forge.WorldRendererMixin", "ltr.LilTaterBlockEntityMixin", "ltr.LilTaterBlocksMixin" ],