From bb736cae174e2ff9a9133d1cc0b4b10a75583f1b Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Wed, 20 Sep 2023 04:26:19 +0800 Subject: [PATCH 1/5] change: Add basic beacon beam culling --- .../MixinBeaconBlockEntityRenderer.java | 26 ++++++++++++++----- .../WorldRendererAccessor.java | 12 +++++++++ src/main/resources/sodium-extra.mixins.json | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/WorldRendererAccessor.java diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java index e77c6bae..1286fe45 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/MixinBeaconBlockEntityRenderer.java @@ -5,13 +5,13 @@ import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex; -import net.minecraft.client.render.LightmapTextureManager; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.block.entity.BeaconBlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RotationAxis; import org.joml.Matrix3f; @@ -26,9 +26,23 @@ @Mixin(value = BeaconBlockEntityRenderer.class, priority = 1500) public class MixinBeaconBlockEntityRenderer { + @Inject(method = "render(Lnet/minecraft/block/entity/BeaconBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", at = @At(value = "HEAD"), cancellable = true) + public void render(BeaconBlockEntity beaconBlockEntity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci) { + Frustum frustum = ((WorldRendererAccessor) MinecraftClient.getInstance().worldRenderer).getFrustum(); + Box box = new Box( + beaconBlockEntity.getPos().getX() - 1.0, + beaconBlockEntity.getPos().getY() - 1.0, + beaconBlockEntity.getPos().getZ() - 1.0, + beaconBlockEntity.getPos().getX() + 1.0, + beaconBlockEntity.getPos().getY() + (beaconBlockEntity.getBeamSegments().isEmpty() ? 1.0 : 1024.0), // todo: probably want to limit this to max height vanilla overshoots as well + beaconBlockEntity.getPos().getZ() + 1.0); + + if (!frustum.isVisible(box)) { + ci.cancel(); + } + } + /** - * For Sodium 0.5 is method will only reduce allocations - * * @author FlashyReese * @reason Use optimized vertex writer, also avoids unnecessary allocations */ diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/WorldRendererAccessor.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/WorldRendererAccessor.java new file mode 100644 index 00000000..3ec14dc3 --- /dev/null +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/beacon_beam_rendering/WorldRendererAccessor.java @@ -0,0 +1,12 @@ +package me.flashyreese.mods.sodiumextra.mixin.optimizations.beacon_beam_rendering; + +import net.minecraft.client.render.Frustum; +import net.minecraft.client.render.WorldRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(WorldRenderer.class) +public interface WorldRendererAccessor { + @Accessor + Frustum getFrustum(); +} \ No newline at end of file diff --git a/src/main/resources/sodium-extra.mixins.json b/src/main/resources/sodium-extra.mixins.json index 90512f32..fbdcbbe5 100644 --- a/src/main/resources/sodium-extra.mixins.json +++ b/src/main/resources/sodium-extra.mixins.json @@ -18,6 +18,7 @@ "light_updates.MixinLightingProvider", "optimizations.beacon_beam_rendering.MixinBeaconBlockEntityRenderer", "optimizations.beacon_beam_rendering.MixinVertexSerializerRegistryImpl", + "optimizations.beacon_beam_rendering.WorldRendererAccessor", "optimizations.draw_helpers.MixinDrawContext", "optimizations.fast_weather.MixinWorldRenderer", "particle.MixinParticleManager", From fb65bf5de2e7b8c986c1b5e65e21b5b7a93f993d Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Wed, 20 Sep 2023 05:24:59 +0800 Subject: [PATCH 2/5] change: Ignore Y range in occlusion culler --- build.gradle | 4 +- gradle.properties | 2 +- .../client/SodiumExtraClientMod.java | 1 + .../mods/sodiumextra/common/util/Utils.java | 18 +++ .../fast_weather/MixinWorldRenderer.java | 125 +++++++++--------- .../sodium/fog/MixinOcclusionCuller.java | 35 +++++ src/main/resources/sodium-extra.mixins.json | 1 + 7 files changed, 121 insertions(+), 65 deletions(-) create mode 100644 src/main/java/me/flashyreese/mods/sodiumextra/common/util/Utils.java create mode 100644 src/main/java/me/flashyreese/mods/sodiumextra/mixin/sodium/fog/MixinOcclusionCuller.java diff --git a/build.gradle b/build.gradle index 25d9ba0e..77f74ebb 100644 --- a/build.gradle +++ b/build.gradle @@ -58,8 +58,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - //modImplementation "me.jellysquid.mods:sodium-fabric:0.5.1+git.49ed59d" - modImplementation "maven.modrinth:sodium:${project.sodium_version}" + modImplementation "me.jellysquid.mods:sodium-fabric:0.5.3+git.fcb3ad2" + //modImplementation "maven.modrinth:sodium:${project.sodium_version}" /*modImplementation("me.flashyreese.mods:reeses-sodium-options:${project.reeses_sodium_options}") { exclude group: "net.coderbot.iris_mc1_19", module: "iris" }*/ diff --git a/gradle.properties b/gradle.properties index dc29c945..14556e99 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,6 +15,6 @@ org.gradle.jvmargs=-Xmx1G # Dependencies reeses_sodium_options=1.5.1+mc1.20-build.74 - sodium_version=mc1.20.1-0.5.1 + sodium_version=mc1.20.1-0.5.3 fabric_version=0.85.0+1.20.1 crowdin_translate=1.4+1.19.3 diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java index 6ece6925..25fc091f 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java @@ -65,6 +65,7 @@ public static CaffeineConfig mixinConfig() { .addMixinOption("sky_colors", true) .addMixinOption("sodium", true) .addMixinOption("sodium.accessibility", true) + .addMixinOption("sodium.fog", true) .addMixinOption("sodium.resolution", true) .addMixinOption("sodium.scrollable_page", true) .addMixinOption("sodium.vsync", true) diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/common/util/Utils.java b/src/main/java/me/flashyreese/mods/sodiumextra/common/util/Utils.java new file mode 100644 index 00000000..68af920a --- /dev/null +++ b/src/main/java/me/flashyreese/mods/sodiumextra/common/util/Utils.java @@ -0,0 +1,18 @@ +package me.flashyreese.mods.sodiumextra.common.util; + +public class Utils { + public static int packLight(int lightU, int lightV) { + return (lightV << 16) | (lightU & 0xFFFF); + } + + public static long packPosition(int x, int z) { + return ((long) x << 32) | (z & 0xFFFFFFFFL); + } + + public static int[] unpackIntegers(long packedValue) { + int int1 = (int) (packedValue >> 32); + int int2 = (int) (packedValue & 0xFFFFFFFFL); + + return new int[]{int1, int2}; + } +} diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/fast_weather/MixinWorldRenderer.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/fast_weather/MixinWorldRenderer.java index 1ee537a8..3e16a2da 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/fast_weather/MixinWorldRenderer.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/optimizations/fast_weather/MixinWorldRenderer.java @@ -1,7 +1,10 @@ package me.flashyreese.mods.sodiumextra.mixin.optimizations.fast_weather; import com.mojang.blaze3d.systems.RenderSystem; +import it.unimi.dsi.fastutil.longs.Long2ReferenceMap; +import it.unimi.dsi.fastutil.longs.Long2ReferenceOpenHashMap; import me.flashyreese.mods.sodiumextra.client.render.vertex.formats.WeatherVertex; +import me.flashyreese.mods.sodiumextra.common.util.Utils; import net.caffeinemc.mods.sodium.api.util.ColorABGR; import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter; import net.minecraft.client.MinecraftClient; @@ -17,6 +20,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -31,6 +35,8 @@ public class MixinWorldRenderer { @Shadow @Final private static Identifier SNOW; + @Unique + private final Long2ReferenceMap biomeLong2ReferenceMap = new Long2ReferenceOpenHashMap<>(); @Shadow @Final private MinecraftClient client; @@ -50,9 +56,9 @@ public class MixinWorldRenderer { if (!(f <= 0.0F)) { manager.enable(); World world = this.client.world; - int i = MathHelper.floor(cameraX); - int j = MathHelper.floor(cameraY); - int k = MathHelper.floor(cameraZ); + int abX = MathHelper.floor(cameraX); + int abY = MathHelper.floor(cameraY); + int abZ = MathHelper.floor(cameraZ); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); RenderSystem.disableCull(); @@ -69,17 +75,18 @@ public class MixinWorldRenderer { RenderSystem.setShader(GameRenderer::getParticleProgram); BlockPos.Mutable mutable = new BlockPos.Mutable(); - for (int n = k - l; n <= k + l; ++n) { - for (int o = i - l; o <= i + l; ++o) { - int p = (n - k + 16) * 32 + o - i + 16; + for (int z = abZ - l; z <= abZ + l; ++z) { + for (int x = abX - l; x <= abX + l; ++x) { + int p = (z - abZ + 16) * 32 + x - abX + 16; double d = (double) this.NORMAL_LINE_DX[p] * 0.5; double e = (double) this.NORMAL_LINE_DZ[p] * 0.5; - mutable.set(o, cameraY, n); - Biome biome = world.getBiome(mutable).value(); + mutable.set(x, cameraY, z); + long biomePacked = Utils.packPosition(x, z); + Biome biome = this.biomeLong2ReferenceMap.computeIfAbsent(biomePacked, key -> world.getBiome(mutable).value()); if (biome.hasPrecipitation()) { - int q = world.getTopY(Heightmap.Type.MOTION_BLOCKING, o, n); - int r = j - l; - int s = j + l; + int q = world.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z); + int r = abY - l; + int s = abY + l; if (r < q) { r = q; } @@ -88,11 +95,11 @@ public class MixinWorldRenderer { s = q; } - int t = Math.max(q, j); + int t = Math.max(q, abY); if (r != s) { - Random random = Random.create((long) o * o * 3121 + o * 45238971L ^ (long) n * n * 418711 + n * 13761L); - mutable.set(o, r, n); + Random random = Random.create((long) x * x * 3121 + x * 45238971L ^ (long) z * z * 418711 + z * 13761L); + mutable.set(x, r, z); Biome.Precipitation precipitation = biome.getPrecipitation(mutable); if (precipitation == Biome.Precipitation.RAIN) { if (m != 0) { @@ -105,37 +112,20 @@ public class MixinWorldRenderer { bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); } - int u = this.ticks + o * o * 3121 + o * 45238971 + n * n * 418711 + n * 13761 & 31; - float h = -((float) u + tickDelta) / 32.0F * (3.0F + random.nextFloat()); - double v = (double) o + 0.5 - cameraX; - double w = (double) n + 0.5 - cameraZ; - float x = (float) Math.sqrt(v * v + w * w) / (float) l; - float y = ((1.0F - x * x) * 0.5F + 0.5F) * f; - mutable.set(o, t, n); - int z = getLightmapCoordinates(world, mutable); + int u = this.ticks + x * x * 3121 + x * 45238971 + z * z * 418711 + z * 13761 & 31; + float rainOffset = -((float) u + tickDelta) / 32.0F * (3.0F + random.nextFloat()); + double v = (double) x + 0.5 - cameraX; + double w = (double) z + 0.5 - cameraZ; + float distance = (float) Math.sqrt(v * v + w * w) / (float) l; + float y = ((1.0F - distance * distance) * 0.5F + 0.5F) * f; + mutable.set(x, t, z); + int light = getLightmapCoordinates(world, mutable); VertexBufferWriter writer = VertexBufferWriter.of(bufferBuilder); int color = ColorABGR.pack(1.0F, 1.0F, 1.0F, y); - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * WeatherVertex.STRIDE); - long ptr = buffer; - - WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (s - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) r * 0.25F + h, z); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (s - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) r * 0.25F + h, z); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (r - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) s * 0.25F + h, z); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (r - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) s * 0.25F + h, z); - ptr += WeatherVertex.STRIDE; - - writer.push(stack, buffer, 4, WeatherVertex.FORMAT); - } + writeVertices(cameraX, cameraY, cameraZ, z, x, d, e, r, s, rainOffset, light, writer, color); } else if (precipitation == Biome.Precipitation.SNOW) { if (m != 1) { if (m >= 0) { @@ -147,12 +137,12 @@ public class MixinWorldRenderer { bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); } - float h = (float) (random.nextDouble() + (double) g * 0.01 * (double) ((float) random.nextGaussian())); - double ac = (double) o + 0.5 - cameraX; - double ad = (double) n + 0.5 - cameraZ; + float snowOffset = (float) (random.nextDouble() + (double) g * 0.01 * (double) ((float) random.nextGaussian())); + double ac = (double) x + 0.5 - cameraX; + double ad = (double) z + 0.5 - cameraZ; float y = (float) Math.sqrt(ac * ac + ad * ad) / (float) l; float ae = ((1.0F - y * y) * 0.3F + 0.5F) * f; - mutable.set(o, t, n); + mutable.set(x, t, z); int af = getLightmapCoordinates(world, mutable); int ag = af >> 16 & 65535; int ah = af & 65535; @@ -162,24 +152,8 @@ public class MixinWorldRenderer { VertexBufferWriter writer = VertexBufferWriter.of(bufferBuilder); int color = ColorABGR.pack(1.0F, 1.0F, 1.0F, ae); - try (MemoryStack stack = MemoryStack.stackPush()) { - long buffer = stack.nmalloc(4 * WeatherVertex.STRIDE); - long ptr = buffer; - - WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (s - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) r * 0.25F + h, aj, ai); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (s - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) r * 0.25F + h, aj, ai); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (r - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) s * 0.25F + h, aj, ai); - ptr += WeatherVertex.STRIDE; - - WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (r - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) s * 0.25F + h, aj, ai); - ptr += WeatherVertex.STRIDE; - - writer.push(stack, buffer, 4, WeatherVertex.FORMAT); - } + int light = Utils.packLight(aj, ai); + writeVertices(cameraX, cameraY, cameraZ, z, x, d, e, r, s, snowOffset, light, writer, color); } } } @@ -196,4 +170,31 @@ public class MixinWorldRenderer { } ci.cancel(); } + + @Inject(method = "reload()V", at = @At(value = "TAIL")) + private void postReload(CallbackInfo ci) { + this.biomeLong2ReferenceMap.clear(); + } + + @Unique + private void writeVertices(double cameraX, double cameraY, double cameraZ, int n, int o, double d, double e, int r, int s, float h, int light, VertexBufferWriter writer, int color) { + try (MemoryStack stack = MemoryStack.stackPush()) { + long buffer = stack.nmalloc(4 * WeatherVertex.STRIDE); + long ptr = buffer; + + WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (s - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) r * 0.25F + h, light); + ptr += WeatherVertex.STRIDE; + + WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (s - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) r * 0.25F + h, light); + ptr += WeatherVertex.STRIDE; + + WeatherVertex.put(ptr, (float) (o - cameraX + d + 0.5), (float) (r - cameraY), (float) (n - cameraZ + e + 0.5), color, 1.0F, (float) s * 0.25F + h, light); + ptr += WeatherVertex.STRIDE; + + WeatherVertex.put(ptr, (float) (o - cameraX - d + 0.5), (float) (r - cameraY), (float) (n - cameraZ - e + 0.5), color, 0.0F, (float) s * 0.25F + h, light); + ptr += WeatherVertex.STRIDE; + + writer.push(stack, buffer, 4, WeatherVertex.FORMAT); + } + } } diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/sodium/fog/MixinOcclusionCuller.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/sodium/fog/MixinOcclusionCuller.java new file mode 100644 index 00000000..f861d0e4 --- /dev/null +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/sodium/fog/MixinOcclusionCuller.java @@ -0,0 +1,35 @@ +package me.flashyreese.mods.sodiumextra.mixin.sodium.fog; + +import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod; +import me.jellysquid.mods.sodium.client.render.chunk.RenderSection; +import me.jellysquid.mods.sodium.client.render.chunk.occlusion.OcclusionCuller; +import me.jellysquid.mods.sodium.client.render.viewport.CameraTransform; +import net.minecraft.client.MinecraftClient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = OcclusionCuller.class, remap = false) +public abstract class MixinOcclusionCuller { + @Shadow + private static int nearestToZero(int min, int max) { + return 0; + } + + @Inject(method = "isOutsideRenderDistance", at = @At(value = "HEAD"), cancellable = true) + private static void isOutsideRenderDistance(CameraTransform camera, RenderSection section, float maxDistance, CallbackInfoReturnable cir) { + int fogDistance = SodiumExtraClientMod.options().renderSettings.multiDimensionFogControl ? + SodiumExtraClientMod.options().renderSettings.dimensionFogDistanceMap.getOrDefault(MinecraftClient.getInstance().world.getDimension().effects(), 0) : + SodiumExtraClientMod.options().renderSettings.fogDistance; + if (fogDistance == 33) { + int ox = section.getOriginX() - camera.intX; + int oz = section.getOriginZ() - camera.intZ; + float dx = (float)nearestToZero(ox, ox + 16) - camera.fracX; + float dz = (float)nearestToZero(oz, oz + 16) - camera.fracZ; + boolean result = dx * dx + dz * dz > maxDistance * maxDistance; + cir.setReturnValue(result); + } + } +} diff --git a/src/main/resources/sodium-extra.mixins.json b/src/main/resources/sodium-extra.mixins.json index fbdcbbe5..ae213c4a 100644 --- a/src/main/resources/sodium-extra.mixins.json +++ b/src/main/resources/sodium-extra.mixins.json @@ -35,6 +35,7 @@ "sky.MixinWorldRenderer", "sky_colors.MixinBiome", "sodium.accessibility.MixinSodiumGameOptionPages", + "sodium.fog.MixinOcclusionCuller", "sodium.resolution.MixinSodiumGameOptionPages", "sodium.scrollable_page.MixinSodiumOptionsGUI", "sodium.vsync.MixinSodiumGameOptionsPages", From 93756ab0ceb43e69e17d5cdcf4f847ea39c1a183 Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Wed, 20 Sep 2023 23:12:23 +0800 Subject: [PATCH 3/5] change: Update animation list --- .../client/SodiumExtraClientMod.java | 6 +- .../animation/MixinSpriteAtlasTexture.java | 83 ++++++++++++++----- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java index 25fc091f..f13fae11 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/SodiumExtraClientMod.java @@ -50,10 +50,10 @@ public static CaffeineConfig mixinConfig() { .addMixinOption("gui", true) .addMixinOption("instant_sneak", true) .addMixinOption("light_updates", true) - .addMixinOption("optimizations", false) + .addMixinOption("optimizations", true) .addMixinOption("optimizations.beacon_beam_rendering", true) - .addMixinOption("optimizations.draw_helpers", true) - .addMixinOption("optimizations.fast_weather", true) + .addMixinOption("optimizations.draw_helpers", false) + .addMixinOption("optimizations.fast_weather", false) .addMixinOption("particle", true) .addMixinOption("prevent_shaders", true) .addMixinOption("reduce_resolution_on_mac", true) diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/animation/MixinSpriteAtlasTexture.java b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/animation/MixinSpriteAtlasTexture.java index e405ebd0..d21a89d9 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/mixin/animation/MixinSpriteAtlasTexture.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/mixin/animation/MixinSpriteAtlasTexture.java @@ -10,8 +10,67 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + @Mixin(SpriteAtlasTexture.class) public abstract class MixinSpriteAtlasTexture extends AbstractTexture { + @Unique + private final Map, List> animatedSprites = Map.of( + () -> SodiumExtraClientMod.options().animationSettings.water, List.of( + new Identifier("minecraft", "block/water_still"), + new Identifier("minecraft", "block/water_flow") + ), + () -> SodiumExtraClientMod.options().animationSettings.lava, List.of( + new Identifier("minecraft", "block/lava_still"), + new Identifier("minecraft", "block/lava_flow") + ), + () -> SodiumExtraClientMod.options().animationSettings.portal, List.of( + new Identifier("minecraft", "block/nether_portal") + ), + () -> SodiumExtraClientMod.options().animationSettings.fire, List.of( + new Identifier("minecraft", "block/fire_0"), + new Identifier("minecraft", "block/fire_1"), + new Identifier("minecraft", "block/soul_fire_0"), + new Identifier("minecraft", "block/soul_fire_1"), + new Identifier("minecraft", "block/campfire_fire"), + new Identifier("minecraft", "block/campfire_log_lit"), + new Identifier("minecraft", "block/soul_campfire_fire"), + new Identifier("minecraft", "block/soul_campfire_log_lit") + ), + () -> SodiumExtraClientMod.options().animationSettings.blockAnimations, List.of( + new Identifier("minecraft", "block/magma"), + new Identifier("minecraft", "block/lantern"), + new Identifier("minecraft", "block/sea_lantern"), + new Identifier("minecraft", "block/soul_lantern"), + new Identifier("minecraft", "block/kelp"), + new Identifier("minecraft", "block/kelp_plant"), + new Identifier("minecraft", "block/seagrass"), + new Identifier("minecraft", "block/tall_seagrass_top"), + new Identifier("minecraft", "block/tall_seagrass_bottom"), + new Identifier("minecraft", "block/warped_stem"), + new Identifier("minecraft", "block/crimson_stem"), + new Identifier("minecraft", "block/blast_furnace_front_on"), + new Identifier("minecraft", "block/smoker_front_on"), + new Identifier("minecraft", "block/stonecutter_saw"), + new Identifier("minecraft", "block/prismarine"), + new Identifier("minecraft", "block/respawn_anchor_top"), + new Identifier("minecraft", "entity/conduit/wind"), + new Identifier("minecraft", "entity/conduit/wind_vertical") + ), + () -> SodiumExtraClientMod.options().animationSettings.sculkSensor, List.of( + new Identifier("minecraft", "block/sculk"), + new Identifier("minecraft", "block/sculk_catalyst_top_bloom"), + new Identifier("minecraft", "block/sculk_catalyst_side_bloom"), + new Identifier("minecraft", "block/sculk_shrieker_inner_top"), + new Identifier("minecraft", "block/sculk_vein"), + new Identifier("minecraft", "block/sculk_shrieker_can_summon_inner_top"), + new Identifier("minecraft", "block/sculk_sensor_tendril_inactive"), + new Identifier("minecraft", "block/sculk_sensor_tendril_active"), + new Identifier("minecraft", "vibration") + ) + ); @Redirect(method = "upload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/Sprite;createAnimation()Lnet/minecraft/client/texture/Sprite$TickableAnimation;")) public Sprite.TickableAnimation sodiumExtra$tickAnimatedSprites(Sprite instance) { @@ -24,26 +83,10 @@ public abstract class MixinSpriteAtlasTexture extends AbstractTexture { @Unique private boolean shouldAnimate(Identifier identifier) { if (identifier != null) { - String path = identifier.getPath(); - if (path.endsWith("water_still") || path.endsWith("water_flow")) { - return SodiumExtraClientMod.options().animationSettings.water; - } else if (path.endsWith("lava_still") || path.endsWith("lava_flow")) { - return SodiumExtraClientMod.options().animationSettings.lava; - } else if (path.endsWith("nether_portal")) { - return SodiumExtraClientMod.options().animationSettings.portal; - } else if (path.endsWith("fire_0") || path.endsWith("fire_1") || path.endsWith("soul_fire_0") || - path.endsWith("soul_fire_1") || path.endsWith("campfire_fire") || path.endsWith("campfire_log_lit") || - path.endsWith("soul_campfire_fire") || path.endsWith("soul_campfire_log_lit")) { - return SodiumExtraClientMod.options().animationSettings.fire; - } else if (path.endsWith("magma") || path.endsWith("lantern") || path.endsWith("sea_lantern") || - path.endsWith("soul_lantern") || path.endsWith("kelp") || path.endsWith("kelp_plant") || - path.endsWith("seagrass") || path.endsWith("warped_stem") || path.endsWith("crimson_stem") || - path.endsWith("blast_furnace_front_on") || path.endsWith("smoker_front_on") || - path.endsWith("stonecutter_saw")) { - return SodiumExtraClientMod.options().animationSettings.blockAnimations; - } else if (path.endsWith("sculk_sensor_tendril_inactive") || path.endsWith("sculk_sensor_tendril_active") || - path.endsWith("particle/vibration")) { - return SodiumExtraClientMod.options().animationSettings.sculkSensor; + for (Map.Entry, List> supplierListEntry : this.animatedSprites.entrySet()) { + if (supplierListEntry.getValue().contains(identifier)) { + return supplierListEntry.getKey().get(); + } } } return true; From 7844d7f56d439005eaf537fb161a00b6eb5f11ed Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Fri, 22 Sep 2023 00:38:24 +0800 Subject: [PATCH 4/5] change: Update to 1.20.2 --- build.gradle | 4 ++-- gradle.properties | 10 +++++----- .../mods/sodiumextra/client/gui/SodiumExtraHud.java | 2 +- .../mods/sodiumextra/client/gui/SuggestRSOScreen.java | 2 +- .../gui/scrollable_page/OptionPageScrollFrame.java | 6 +++--- .../client/gui/scrollable_page/ScrollBarComponent.java | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 77f74ebb..15c49304 100644 --- a/build.gradle +++ b/build.gradle @@ -58,8 +58,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "me.jellysquid.mods:sodium-fabric:0.5.3+git.fcb3ad2" - //modImplementation "maven.modrinth:sodium:${project.sodium_version}" + //modImplementation "me.jellysquid.mods:sodium-fabric:0.5.3+git.fcb3ad2" + modImplementation "maven.modrinth:sodium:${project.sodium_version}" /*modImplementation("me.flashyreese.mods:reeses-sodium-options:${project.reeses_sodium_options}") { exclude group: "net.coderbot.iris_mc1_19", module: "iris" }*/ diff --git a/gradle.properties b/gradle.properties index 14556e99..8a0eedc5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html - minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.9 - loader_version=0.14.21 + minecraft_version=1.20.2 + yarn_mappings=1.20.2+build.1 + loader_version=0.14.22 # Mod Properties version_type=release @@ -15,6 +15,6 @@ org.gradle.jvmargs=-Xmx1G # Dependencies reeses_sodium_options=1.5.1+mc1.20-build.74 - sodium_version=mc1.20.1-0.5.3 - fabric_version=0.85.0+1.20.1 + sodium_version=mc1.20.2-0.5.3 + fabric_version=0.89.0+1.20.2 crowdin_translate=1.4+1.19.3 diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraHud.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraHud.java index a8d1e493..72792e47 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraHud.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SodiumExtraHud.java @@ -48,7 +48,7 @@ public void onStartTick(MinecraftClient client) { } @Override public void onHudRender(DrawContext drawContext, float tickDelta) { - if (!client.options.debugEnabled) { + if (!client.getDebugHud().shouldShowDebugHud()) { SodiumExtraGameOptions.OverlayCorner overlayCorner = SodiumExtraClientMod.options().extraSettings.overlayCorner; // Calculate starting position based on the overlay corner int x; diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java index e37dfa8d..3f7f2286 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/SuggestRSOScreen.java @@ -47,7 +47,7 @@ protected void init() { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { - this.renderBackground(drawContext); + this.renderBackground(drawContext, mouseX, mouseY, delta); drawContext.drawTextWithShadow(this.textRenderer, HEADER, 25, 30, 0XFFFFFF); this.lines.drawWithShadow(drawContext, 25, 70, this.textRenderer.fontHeight * 2, 0xFFFFFF); super.render(drawContext, mouseX, mouseY, delta); diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/OptionPageScrollFrame.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/OptionPageScrollFrame.java index 4f910b4a..01ba2543 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/OptionPageScrollFrame.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/OptionPageScrollFrame.java @@ -175,12 +175,12 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) { } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (super.mouseScrolled(mouseX, mouseY, amount)) { + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + if (super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) { return true; } if (this.canScroll) { - return this.scrollBar.mouseScrolled(mouseX, mouseY, amount); + return this.scrollBar.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } return false; } diff --git a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/ScrollBarComponent.java b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/ScrollBarComponent.java index 78612f7b..f83856c6 100644 --- a/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/ScrollBarComponent.java +++ b/src/main/java/me/flashyreese/mods/sodiumextra/client/gui/scrollable_page/ScrollBarComponent.java @@ -75,10 +75,10 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { if (this.dim.containsCursor(mouseX, mouseY) || this.extendedScrollArea != null && this.extendedScrollArea.containsCursor(mouseX, mouseY)) { if (this.offset <= this.maxScrollBarOffset && this.offset >= 0) { - int value = (int) (this.offset - amount * 6); + int value = (int) (this.offset - verticalAmount * 6); // todo: horizontalAmount this.setOffset(value); return true; } From 1ac5841ebc84d7d062e3e1cb7de6dd59c5bd08c9 Mon Sep 17 00:00:00 2001 From: Yao Chung Hu <30311066+FlashyReese@users.noreply.github.com> Date: Fri, 22 Sep 2023 00:40:21 +0800 Subject: [PATCH 5/5] change: Bump to `0.5.2` for release --- gradle.properties | 2 +- src/main/resources/fabric.mod.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8a0eedc5..ed56bd5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G # Mod Properties version_type=release revision=1 - mod_version=0.5.1 + mod_version=0.5.2 maven_group=me.flashyreese.mods archives_base_name=sodium-extra diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index cb852c05..6db8ff9c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -51,8 +51,8 @@ "depends": { "fabricloader": ">=0.14", "fabric-api": "*", - "sodium": ">=0.5.1", - "minecraft": ">=1.20" + "sodium": ">=0.5.3", + "minecraft": ">=1.20.2" }, "breaks": { "reeses-sodium-options": "<1.4.2"