From 301d587535d6a96d53b77eb17d20b49319ef6c58 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Mon, 22 Sep 2025 11:29:36 +1000 Subject: [PATCH] ingest chunk section on block change on board --- .../client/core/gl/shader/ShaderLoader.java | 2 +- .../mixin/minecraft/MixinClientWorld.java | 78 +++++++++++++++++++ src/main/resources/client.voxy.mixins.json | 1 + 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientWorld.java diff --git a/src/main/java/me/cortex/voxy/client/core/gl/shader/ShaderLoader.java b/src/main/java/me/cortex/voxy/client/core/gl/shader/ShaderLoader.java index 5e7279ee..97d1c247 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/shader/ShaderLoader.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/shader/ShaderLoader.java @@ -6,7 +6,7 @@ import net.caffeinemc.mods.sodium.client.gl.shader.ShaderParser; public class ShaderLoader { public static String parse(String id) { - return "#version 460 core\n"+ShaderParser.parseShader("#import <" + id + ">\n//beans", ShaderConstants.builder().build()).replaceFirst("\n#version .+\n", "\n"); + return "#version 460 core\n"+ShaderParser.parseShader("\n#import <" + id + ">\n//beans", ShaderConstants.builder().build()).replaceAll("\r\n", "\n").replaceFirst("\n#version .+\n", "\n"); //return me.jellysquid.mods.sodium.client.gl.shader.ShaderLoader.getShaderSource(new Identifier(id)); } } diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientWorld.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientWorld.java new file mode 100644 index 00000000..fb75d8ac --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientWorld.java @@ -0,0 +1,78 @@ +package me.cortex.voxy.client.mixin.minecraft; + +import me.cortex.voxy.client.core.IGetVoxyRenderSystem; +import me.cortex.voxy.common.world.service.VoxelIngestService; +import me.cortex.voxy.commonImpl.VoxyCommon; +import net.minecraft.block.BlockState; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.world.ClientChunkManager; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkSectionPos; +import net.minecraft.world.LightType; +import net.minecraft.world.World; +import net.minecraft.world.dimension.DimensionType; +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; + +@Mixin(ClientWorld.class) +public abstract class MixinClientWorld { + + @Unique + private int bottomSectionY; + + @Shadow @Final public WorldRenderer worldRenderer; + + @Shadow public abstract ClientChunkManager getChunkManager(); + + @Inject(method = "", at = @At("TAIL")) + private void voxy$getBottom( + ClientPlayNetworkHandler networkHandler, + ClientWorld.Properties properties, + RegistryKey registryRef, + RegistryEntry dimensionType, + int loadDistance, + int simulationDistance, + WorldRenderer worldRenderer, + boolean debugWorld, + long seed, + int seaLevel, + CallbackInfo cir) { + this.bottomSectionY = ((World)(Object)this).getBottomY()>>4; + } + + @Inject(method = "scheduleBlockRerenderIfNeeded", at = @At("TAIL")) + private void voxy$injectIngestOnStateChange(BlockPos pos, BlockState old, BlockState updated, CallbackInfo cir) { + if (old == updated) return; + + var system = ((IGetVoxyRenderSystem)(this.worldRenderer)).getVoxyRenderSystem(); + if (system == null) { + return; + } + + int x = pos.getX()&15; + int y = pos.getY()&15; + int z = pos.getZ()&15; + if (x == 0 || x==15 || y==0 || y==15 || z==0||z==15) {//Update if there is a statechange on the boarder + var world = (World)(Object)this; + + var csp = ChunkSectionPos.from(pos); + + var section = world.getChunk(pos).getSection(csp.getSectionY()-this.bottomSectionY); + var lp = world.getLightingProvider(); + + var blp = lp.get(LightType.BLOCK).getLightSection(csp); + var slp = lp.get(LightType.SKY).getLightSection(csp); + + VoxelIngestService.rawIngest(system.getEngine(), section, csp.getSectionX(), csp.getSectionY(), csp.getSectionZ(), blp==null?null:blp.copy(), slp==null?null:slp.copy()); + } + } +} diff --git a/src/main/resources/client.voxy.mixins.json b/src/main/resources/client.voxy.mixins.json index 842323cc..c354077b 100644 --- a/src/main/resources/client.voxy.mixins.json +++ b/src/main/resources/client.voxy.mixins.json @@ -16,6 +16,7 @@ "iris.MixinProgramSet", "iris.MixinShaderPackSourceNames", "iris.MixinStandardMacros", + "minecraft.MixinClientWorld", "minecraft.MixinClientChunkManager", "minecraft.MixinClientCommonNetworkHandler", "minecraft.MixinClientLoginNetworkHandler",