Skip to content

Commit

Permalink
pull out the ChunkCache into a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Nov 14, 2024
1 parent f8a0bdd commit 664c299
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,24 @@ public class ModuleConfig {
@Config.RequiresMcRestart
public static boolean THREADED_CHUNK_UPDATES;

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

@Config.Comment({
"Replaces the renderer chunk cache with a more efficient version.",
"FPS impact: Faster chunk rendering"
})
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean FASTER_CHUNK_CACHE;

@Config.Comment("Wraps block renderer code and tile entity renderer code in extra opengl state guards.")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
Expand All @@ -136,6 +148,7 @@ public class ModuleConfig {
@Config.Comment("Gets rid of that obnoxious burst of minecart sounds when joining a world.")
@Config.DefaultBoolean(true)
public static boolean MINECART_EAR_BLAST_FIX;

@Config.Comment("Improves the performance of the minecraft sky mesh.\n" +
"Also fixes the weird white lines that some OptiFine shaderpacks get with huge render distances.\n" +
"FPS impact: Negligible gain")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.falsepattern.falsetweaks.mixin.mixins.client.dynlights;
package com.falsepattern.falsetweaks.mixin.mixins.client.cc;

import com.falsepattern.falsetweaks.modules.dynlights.ChunkCacheFT;
import com.falsepattern.falsetweaks.modules.cc.ChunkCacheFT;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import lombok.val;
import org.spongepowered.asm.mixin.Mixin;
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.Redirect;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.falsepattern.falsetweaks.mixin.mixins.client.cc.of;

import com.falsepattern.falsetweaks.modules.dynlights.DynamicLightsDrivers;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import net.minecraft.block.Block;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

@Mixin(targets = "ChunkCacheOF",
remap = false)
public abstract class ChunkCacheOFMixin extends ChunkCache {
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_) {
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_);
}

@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
at = @At(value = "INVOKE",
target = "LConfig;isDynamicLights()Z"),
require = 1)
private boolean ftDynamicLights() {
return DynamicLightsDrivers.frontend.enabled();
}

@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
at = @At(value = "INVOKE",
target = "LDynamicLights;getCombinedLight(IIII)I"),
require = 1)
private int ftCombinedLights(int x, int y, int z, int combinedLight) {
return DynamicLightsDrivers.frontend.forWorldMesh().getCombinedLight(x, y, z, combinedLight);
}

@Redirect(method = "getLightBrightnessForSkyBlocksRaw",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/IBlockAccess;getLightBrightnessForSkyBlocks(IIII)I",
remap = true),
require = 1)
private int brightnessFromSuper(IBlockAccess instance, int x, int y, int z, int lightValue) {
return super.getLightBrightnessForSkyBlocks(x, y, z, lightValue);
}

@Dynamic
@Redirect(method = "func_147439_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;",
remap = true),
remap = true,
require = 3)
private Block blockFromSuper(IBlockAccess instance, int x, int y, int z) {
return super.getBlock(x, y, z);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,16 @@ public enum Mixin implements IMixin {
DynLights_ItemRendererMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.ItemRendererMixin"),
DynLights_RenderGlobalMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.RenderGlobalMixin"),
DynLights_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.WorldClientMixin"),
DynLights_WorldRendererMixin(Side.CLIENT, DYNLIGHTS_NONOF, "dynlights.WorldRendererMixin"),
DynLights_NonThread_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF.and(THREADING.negate()), "dynlights.nonthread.WorldClientMixin"),
DynLights_Thread_WorldClientMixin(Side.CLIENT, DYNLIGHTS_NONOF.and(THREADING), "dynlights.thread.WorldClientMixin"),
DynLights_OF_ChunkCacheOFMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "dynlights.of.ChunkCacheOFMixin"),
DynLights_OF_DynamicLightsMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "dynlights.of.DynamicLightsMixin"),

//endregion Dynamic Lights Module

//region Chunk Cache Module
CC_WorldRendererMixin(Side.CLIENT, condition(() -> ModuleConfig.DYNAMIC_LIGHTS || ModuleConfig.FASTER_CHUNK_CACHE).and(AVOID_OPTIFINE_WITH_DYNAMIC_LIGHTS), "cc.WorldRendererMixin"),
CC_OF_ChunkCacheOFMixin(Side.CLIENT, REQUIRE_OPTIFINE_WITH_DYNAMIC_LIGHTS, "cc.of.ChunkCacheOFMixin"),
//endregion Chunk Cache Module

//region Misc Modules
ItemRenderList_ItemRendererMixin(Side.CLIENT, condition(() -> ModuleConfig.ITEM_RENDER_LISTS), "misc.ItemRenderList_ItemRendererMixin"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.falsepattern.falsetweaks.modules.dynlights;
package com.falsepattern.falsetweaks.modules.cc;

import com.falsepattern.falsetweaks.api.dynlights.DynamicLightsDriver;
import com.falsepattern.falsetweaks.api.dynlights.FTDynamicLights;
import com.falsepattern.falsetweaks.modules.dynlights.ArrayCache;
import lombok.val;

import java.util.Arrays;
import net.minecraft.block.Block;
import net.minecraft.world.ChunkCache;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ChunkCacheFT extends ChunkCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

import com.falsepattern.falsetweaks.Compat;
import com.falsepattern.falsetweaks.config.ModuleConfig;
import com.falsepattern.falsetweaks.modules.dynlights.ChunkCacheFT;
import com.falsepattern.falsetweaks.modules.dynlights.DynamicLightsDrivers;
import com.falsepattern.falsetweaks.modules.cc.ChunkCacheFT;
import shadersmod.client.Shaders;
import stubpackage.ChunkCacheOF;
import stubpackage.Config;
Expand Down Expand Up @@ -70,7 +69,7 @@ public static ChunkCache createChunkCache(World world, int xMin, int yMin, int z
}
if (HAS_CHUNKCACHE) {
return WrappedOF.createOFChunkCache(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);
} else if (ModuleConfig.DYNAMIC_LIGHTS) {
} else if (ModuleConfig.DYNAMIC_LIGHTS || ModuleConfig.FASTER_CHUNK_CACHE) {
return new ChunkCacheFT(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);
} else {
return new ChunkCache(world, xMin, yMin, zMin, xMax, yMax, zMax, subIn);
Expand Down

0 comments on commit 664c299

Please sign in to comment.