Skip to content

Commit 9396ff1

Browse files
authored
change: Eliminate the assumption that only one client world exists (CaffeineMC#734)
1 parent afe3f6c commit 9396ff1

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

src/main/java/me/jellysquid/mods/sodium/client/render/SodiumWorldRenderer.java

+4-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import me.jellysquid.mods.sodium.client.util.math.FrustumExtended;
1818
import me.jellysquid.mods.sodium.client.world.ChunkStatusListener;
1919
import me.jellysquid.mods.sodium.client.world.ClientChunkManagerExtended;
20+
import me.jellysquid.mods.sodium.client.world.WorldRendererExtended;
2021
import me.jellysquid.mods.sodium.common.util.ListUtil;
2122
import net.minecraft.block.entity.BlockEntity;
2223
import net.minecraft.client.MinecraftClient;
@@ -39,8 +40,6 @@
3940
* Provides an extension to vanilla's {@link WorldRenderer}.
4041
*/
4142
public class SodiumWorldRenderer implements ChunkStatusListener {
42-
private static SodiumWorldRenderer instance;
43-
4443
private final MinecraftClient client;
4544

4645
private ClientWorld world;
@@ -59,29 +58,13 @@ public class SodiumWorldRenderer implements ChunkStatusListener {
5958
private ChunkRenderer chunkRenderer;
6059

6160
/**
62-
* Instantiates Sodium's world renderer. This should be called at the time of the world renderer initialization.
63-
*/
64-
public static SodiumWorldRenderer create() {
65-
if (instance == null) {
66-
instance = new SodiumWorldRenderer(MinecraftClient.getInstance());
67-
}
68-
69-
return instance;
70-
}
71-
72-
/**
73-
* @throws IllegalStateException If the renderer has not yet been created
74-
* @return The current instance of this type
61+
* @return The SodiumWorldRenderer based on the current dimension
7562
*/
7663
public static SodiumWorldRenderer getInstance() {
77-
if (instance == null) {
78-
throw new IllegalStateException("Renderer not initialized");
79-
}
80-
81-
return instance;
64+
return ((WorldRendererExtended) MinecraftClient.getInstance().worldRenderer).getSodiumWorldRenderer();
8265
}
8366

84-
private SodiumWorldRenderer(MinecraftClient client) {
67+
public SodiumWorldRenderer(MinecraftClient client) {
8568
this.client = client;
8669
}
8770

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package me.jellysquid.mods.sodium.client.world;
2+
3+
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
4+
5+
public interface WorldRendererExtended {
6+
SodiumWorldRenderer getSodiumWorldRenderer();
7+
}

src/main/java/me/jellysquid/mods/sodium/mixin/features/chunk_rendering/MixinWorldRenderer.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
44
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;
55
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer;
6+
import me.jellysquid.mods.sodium.client.world.WorldRendererExtended;
67
import net.minecraft.client.MinecraftClient;
78
import net.minecraft.client.option.GameOptions;
89
import net.minecraft.client.render.*;
@@ -22,7 +23,7 @@
2223
import java.util.SortedSet;
2324

2425
@Mixin(WorldRenderer.class)
25-
public abstract class MixinWorldRenderer {
26+
public abstract class MixinWorldRenderer implements WorldRendererExtended {
2627
@Shadow
2728
@Final
2829
private BufferBuilderStorage bufferBuilders;
@@ -33,6 +34,11 @@ public abstract class MixinWorldRenderer {
3334

3435
private SodiumWorldRenderer renderer;
3536

37+
@Override
38+
public SodiumWorldRenderer getSodiumWorldRenderer() {
39+
return renderer;
40+
}
41+
3642
@Redirect(method = "reload()V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;viewDistance:I", ordinal = 1))
3743
private int nullifyBuiltChunkStorage(GameOptions options) {
3844
// Do not allow any resources to be allocated
@@ -41,7 +47,7 @@ private int nullifyBuiltChunkStorage(GameOptions options) {
4147

4248
@Inject(method = "<init>", at = @At("RETURN"))
4349
private void init(MinecraftClient client, BufferBuilderStorage bufferBuilders, CallbackInfo ci) {
44-
this.renderer = SodiumWorldRenderer.create();
50+
this.renderer = new SodiumWorldRenderer(client);
4551
}
4652

4753
@Inject(method = "setWorld", at = @At("RETURN"))

0 commit comments

Comments
 (0)