Updated thing

This commit is contained in:
mcrcortex
2025-05-29 22:57:32 +10:00
parent fe2e6522ed
commit 5841b36469
5 changed files with 36 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package me.cortex.voxy.client.core;
public interface IGetVoxyRenderSystem { public interface IGetVoxyRenderSystem {
VoxyRenderSystem getVoxyRenderSystem(); VoxyRenderSystem getVoxyRenderSystem();
VoxyRenderSystem getVoxyOverworldRenderSystem();
void shutdownRenderer(); void shutdownRenderer();
void createRenderer(); void createRenderer();
} }

View File

@@ -61,12 +61,16 @@ public class VoxyRenderSystem {
public final ChunkBoundRenderer chunkBoundRenderer; public final ChunkBoundRenderer chunkBoundRenderer;
public VoxyRenderSystem(WorldEngine world, ServiceThreadPool threadPool) { public VoxyRenderSystem(WorldEngine world, ServiceThreadPool threadPool) {
this(world, threadPool, 1L<<32);
}
public VoxyRenderSystem(WorldEngine world, ServiceThreadPool threadPool, long maxGeometryCapacity) {
//Trigger the shared index buffer loading //Trigger the shared index buffer loading
SharedIndexBuffer.INSTANCE.id(); SharedIndexBuffer.INSTANCE.id();
Capabilities.init();//Ensure clinit is called Capabilities.init();//Ensure clinit is called
this.worldIn = world; this.worldIn = world;
this.renderer = new RenderService(world, threadPool); this.renderer = new RenderService(world, threadPool, maxGeometryCapacity);
this.postProcessing = new PostProcessing(); this.postProcessing = new PostProcessing();
int minSec = MinecraftClient.getInstance().world.getBottomSectionCoord()>>5; int minSec = MinecraftClient.getInstance().world.getBottomSectionCoord()>>5;
int maxSec = (MinecraftClient.getInstance().world.getTopSectionCoord()-1)>>5; int maxSec = (MinecraftClient.getInstance().world.getTopSectionCoord()-1)>>5;

View File

@@ -62,11 +62,12 @@ public class RenderService<T extends AbstractSectionRenderer<J, Q>, J extends Vi
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public RenderService(WorldEngine world, ServiceThreadPool serviceThreadPool) { public RenderService(WorldEngine world, ServiceThreadPool serviceThreadPool, long maxGeometryCapacity) {
this.world = world; this.world = world;
this.modelService = new ModelBakerySubsystem(world.getMapper()); this.modelService = new ModelBakerySubsystem(world.getMapper());
long geometryCapacity = getGeometryBufferSize(); long geometryCapacity = getGeometryBufferSize();
geometryCapacity = Math.min(maxGeometryCapacity, geometryCapacity);
this.geometryData = (Q) new BasicSectionGeometryData(1<<20, geometryCapacity); this.geometryData = (Q) new BasicSectionGeometryData(1<<20, geometryCapacity);

View File

@@ -11,6 +11,7 @@ import me.cortex.voxy.commonImpl.WorldIdentifier;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.util.ObjectAllocator; import net.minecraft.client.util.ObjectAllocator;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -25,6 +26,8 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
@Shadow private Frustum frustum; @Shadow private Frustum frustum;
@Shadow private @Nullable ClientWorld world; @Shadow private @Nullable ClientWorld world;
@Unique private VoxyRenderSystem renderer; @Unique private VoxyRenderSystem renderer;
@Unique private VoxyRenderSystem overworldRenderer;
@Unique private WorldIdentifier overworldIdentifier;
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupTerrain(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/Frustum;ZZ)V", shift = At.Shift.AFTER)) @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;setupTerrain(Lnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/Frustum;ZZ)V", shift = At.Shift.AFTER))
private void injectSetup(ObjectAllocator allocator, RenderTickCounter tickCounter, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, Matrix4f positionMatrix, Matrix4f projectionMatrix, CallbackInfo ci) { private void injectSetup(ObjectAllocator allocator, RenderTickCounter tickCounter, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, Matrix4f positionMatrix, Matrix4f projectionMatrix, CallbackInfo ci) {
@@ -38,6 +41,11 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
return this.renderer; return this.renderer;
} }
@Override
public VoxyRenderSystem getVoxyOverworldRenderSystem() {
return this.renderer;
}
@Inject(method = "reload()V", at = @At("RETURN"), order = 900)//We want to inject before sodium @Inject(method = "reload()V", at = @At("RETURN"), order = 900)//We want to inject before sodium
private void reloadVoxyRenderer(CallbackInfo ci) { private void reloadVoxyRenderer(CallbackInfo ci) {
this.shutdownRenderer(); this.shutdownRenderer();
@@ -51,6 +59,9 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
if (this.world != world) { if (this.world != world) {
this.shutdownRenderer(); this.shutdownRenderer();
} }
if (world!=null&&world.getRegistryKey()==World.OVERWORLD) {
this.overworldIdentifier = WorldIdentifier.of(world);
}
} }
@Inject(method = "close", at = @At("HEAD")) @Inject(method = "close", at = @At("HEAD"))
@@ -64,6 +75,10 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
this.renderer.shutdown(); this.renderer.shutdown();
this.renderer = null; this.renderer = null;
} }
if (this.overworldRenderer != null) {
this.overworldRenderer.shutdown();
this.overworldRenderer = null;
}
} }
@Override @Override
@@ -88,5 +103,11 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem {
return; return;
} }
this.renderer = new VoxyRenderSystem(world, instance.getThreadPool()); this.renderer = new VoxyRenderSystem(world, instance.getThreadPool());
if (this.world.getRegistryKey()== World.NETHER && this.overworldIdentifier != null) {
var engine = this.overworldIdentifier.getOrCreateEngine();
if (engine != null) {
this.overworldRenderer = new VoxyRenderSystem(engine, instance.getThreadPool(), 1L<<31);
}
}
} }
} }

View File

@@ -26,6 +26,13 @@ public class MixinDefaultChunkRenderer {
if (renderer != null) { if (renderer != null) {
renderer.renderOpaque(matrices, camera.x, camera.y, camera.z); renderer.renderOpaque(matrices, camera.x, camera.y, camera.z);
} }
var overworldRenderer = ((IGetVoxyRenderSystem) MinecraftClient.getInstance().worldRenderer).getVoxyOverworldRenderSystem();
if (overworldRenderer != null) {
overworldRenderer.renderOpaque(new ChunkRenderMatrices(matrices.projection(),
new Matrix4f(matrices.modelView()).scale(1/8f).scale(1,-1,1)),
camera.x*8, (300-camera.y)*8, (camera.z)*8);
}
} }
} }
} }