Skip to content

Commit 664c299

Browse files
committed
pull out the ChunkCache into a separate module
1 parent f8a0bdd commit 664c299

7 files changed

Lines changed: 82 additions & 40 deletions

File tree

src/main/java/com/falsepattern/falsetweaks/config/ModuleConfig.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,24 @@ public class ModuleConfig {
122122
@Config.RequiresMcRestart
123123
public static boolean THREADED_CHUNK_UPDATES;
124124

125-
@Config.Comment("Enables dynamic lights code injections.\n" +
126-
"See the dynamiclights config entry for more configurability.")
125+
@Config.Comment({
126+
"OptiFine-style dynamic lights, but works without OptiFine",
127+
"Force-enables CHUNK_CACHE.",
128+
"Implicitly enabled when OptiFine is installed for compatibility.",
129+
"See the dynamiclights config entry for more configs.",
130+
})
127131
@Config.DefaultBoolean(true)
128132
@Config.RequiresMcRestart
129133
public static boolean DYNAMIC_LIGHTS;
130134

135+
@Config.Comment({
136+
"Replaces the renderer chunk cache with a more efficient version.",
137+
"FPS impact: Faster chunk rendering"
138+
})
139+
@Config.DefaultBoolean(true)
140+
@Config.RequiresMcRestart
141+
public static boolean FASTER_CHUNK_CACHE;
142+
131143
@Config.Comment("Wraps block renderer code and tile entity renderer code in extra opengl state guards.")
132144
@Config.DefaultBoolean(true)
133145
@Config.RequiresMcRestart
@@ -136,6 +148,7 @@ public class ModuleConfig {
136148
@Config.Comment("Gets rid of that obnoxious burst of minecart sounds when joining a world.")
137149
@Config.DefaultBoolean(true)
138150
public static boolean MINECART_EAR_BLAST_FIX;
151+
139152
@Config.Comment("Improves the performance of the minecraft sky mesh.\n" +
140153
"Also fixes the weird white lines that some OptiFine shaderpacks get with huge render distances.\n" +
141154
"FPS impact: Negligible gain")

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/dynlights/WorldRendererMixin.java renamed to src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/cc/WorldRendererMixin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package com.falsepattern.falsetweaks.mixin.mixins.client.dynlights;
1+
package com.falsepattern.falsetweaks.mixin.mixins.client.cc;
22

3-
import com.falsepattern.falsetweaks.modules.dynlights.ChunkCacheFT;
3+
import com.falsepattern.falsetweaks.modules.cc.ChunkCacheFT;
44
import com.llamalad7.mixinextras.sugar.Share;
55
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
66
import lombok.val;
77
import org.spongepowered.asm.mixin.Mixin;
8-
import org.spongepowered.asm.mixin.Unique;
98
import org.spongepowered.asm.mixin.injection.At;
109
import org.spongepowered.asm.mixin.injection.Inject;
1110
import org.spongepowered.asm.mixin.injection.Redirect;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.falsepattern.falsetweaks.mixin.mixins.client.cc.of;
2+
3+
import com.falsepattern.falsetweaks.modules.dynlights.DynamicLightsDrivers;
4+
import org.spongepowered.asm.mixin.Dynamic;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
8+
9+
import net.minecraft.block.Block;
10+
import net.minecraft.world.ChunkCache;
11+
import net.minecraft.world.IBlockAccess;
12+
import net.minecraft.world.World;
13+
14+
@Mixin(targets = "ChunkCacheOF",
15+
remap = false)
16+
public abstract class ChunkCacheOFMixin extends ChunkCache {
17+
public ChunkCacheOFMixin(World p_i1964_1_, int p_i1964_2_, int p_i1964_3_, int p_i1964_4_, int p_i1964_5_, int p_i1964_6_, int p_i1964_7_, int p_i1964_8_) {
18+
super(p_i1964_1_, p_i1964_2_, p_i1964_3_, p_i1964_4_, p_i1964_5_, p_i1964_6_, p_i1964_7_, p_i1964_8_);
19+
}
20+
21+
@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
22+
at = @At(value = "INVOKE",
23+
target = "LConfig;isDynamicLights()Z"),
24+
require = 1)
25+
private boolean ftDynamicLights() {
26+
return DynamicLightsDrivers.frontend.enabled();
27+
}
28+
29+
@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
30+
at = @At(value = "INVOKE",
31+
target = "LDynamicLights;getCombinedLight(IIII)I"),
32+
require = 1)
33+
private int ftCombinedLights(int x, int y, int z, int combinedLight) {
34+
return DynamicLightsDrivers.frontend.forWorldMesh().getCombinedLight(x, y, z, combinedLight);
35+
}
36+
37+
@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
38+
at = @At(value = "INVOKE",
39+
target = "Lnet/minecraft/world/IBlockAccess;getLightBrightnessForSkyBlocks(IIII)I",
40+
remap = true),
41+
require = 1)
42+
private int brightnessFromSuper(IBlockAccess instance, int x, int y, int z, int lightValue) {
43+
return super.getLightBrightnessForSkyBlocks(x, y, z, lightValue);
44+
}
45+
46+
@Dynamic
47+
@Redirect(method = "func_147439_a",
48+
at = @At(value = "INVOKE",
49+
target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;",
50+
remap = true),
51+
remap = true,
52+
require = 3)
53+
private Block blockFromSuper(IBlockAccess instance, int x, int y, int z) {
54+
return super.getBlock(x, y, z);
55+
}
56+
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/dynlights/of/ChunkCacheOFMixin.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/com/falsepattern/falsetweaks/mixin/plugin/standard/Mixin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,16 @@ public enum Mixin implements IMixin {
302302
DynLights_ItemRendererMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.ItemRendererMixin"),
303303
DynLights_RenderGlobalMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.RenderGlobalMixin"),
304304
DynLights_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.WorldClientMixin"),
305-
DynLights_WorldRendererMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.WorldRendererMixin"),
306305
DynLights_NonThread_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF.and(THREADING.negate()), "dynlights.nonthread.WorldClientMixin"),
307306
DynLights_Thread_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF.and(THREADING), "dynlights.thread.WorldClientMixin"),
308-
DynLights_OF_ChunkCacheOFMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "dynlights.of.ChunkCacheOFMixin"),
309307
DynLights_OF_DynamicLightsMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "dynlights.of.DynamicLightsMixin"),
310-
311308
//endregion Dynamic Lights Module
312309

310+
//region Chunk Cache Module
311+
CC_WorldRendererMixin(Side.CLIENT, condition(() -> ModuleConfig.DYNAMIC_LIGHTS || ModuleConfig.FASTER_CHUNK_CACHE).and(AVOID_OPTIFINE_WITH_DYNAMIC_LIGHTS), "cc.WorldRendererMixin"),
312+
CC_OF_ChunkCacheOFMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "cc.of.ChunkCacheOFMixin"),
313+
//endregion Chunk Cache Module
314+
313315
//region Misc Modules
314316
ItemRenderList_ItemRendererMixin(Side.CLIENT, condition(() -> ModuleConfig.ITEM_RENDER_LISTS), "misc.ItemRenderList_ItemRendererMixin"),
315317

src/main/java/com/falsepattern/falsetweaks/modules/dynlights/ChunkCacheFT.java renamed to src/main/java/com/falsepattern/falsetweaks/modules/cc/ChunkCacheFT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package com.falsepattern.falsetweaks.modules.dynlights;
1+
package com.falsepattern.falsetweaks.modules.cc;
22

3-
import com.falsepattern.falsetweaks.api.dynlights.DynamicLightsDriver;
43
import com.falsepattern.falsetweaks.api.dynlights.FTDynamicLights;
4+
import com.falsepattern.falsetweaks.modules.dynlights.ArrayCache;
55
import lombok.val;
66

77
import java.util.Arrays;
88
import net.minecraft.block.Block;
99
import net.minecraft.world.ChunkCache;
10-
import net.minecraft.world.IBlockAccess;
1110
import net.minecraft.world.World;
1211

1312
public class ChunkCacheFT extends ChunkCache {

src/main/java/com/falsepattern/falsetweaks/modules/threadedupdates/OptiFineCompat.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
import com.falsepattern.falsetweaks.Compat;
2727
import com.falsepattern.falsetweaks.config.ModuleConfig;
28-
import com.falsepattern.falsetweaks.modules.dynlights.ChunkCacheFT;
29-
import com.falsepattern.falsetweaks.modules.dynlights.DynamicLightsDrivers;
28+
import com.falsepattern.falsetweaks.modules.cc.ChunkCacheFT;
3029
import shadersmod.client.Shaders;
3130
import stubpackage.ChunkCacheOF;
3231
import stubpackage.Config;
@@ -70,7 +69,7 @@ public static ChunkCache createChunkCache(World world, int xMin, int yMin, int z
7069
}
7170
if (HAS_CHUNKCACHE) {
7271
return WrappedOF.createOFChunkCache(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);
73-
} else if (ModuleConfig.DYNAMIC_LIGHTS) {
72+
} else if (ModuleConfig.DYNAMIC_LIGHTS || ModuleConfig.FASTER_CHUNK_CACHE) {
7473
return new ChunkCacheFT(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);
7574
} else {
7675
return new ChunkCache(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);

0 commit comments

Comments
 (0)