Skip to content

Commit 978ac04

Browse files
committed
optifine fixes
1 parent 18d4bee commit 978ac04

File tree

8 files changed

+257
-23
lines changed

8 files changed

+257
-23
lines changed

src/main/java/com/falsepattern/falsetweaks/asm/modules/occlusion/optifine/LazyOptiFineCheck.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,12 @@ public static boolean hasOptiFine() {
3636
if (detected == null) {
3737
if (FMLLaunchHandler.side().isClient()) {
3838
try {
39-
//We might be too early but let's try the standard way
40-
detected = FMLClientHandler.instance().hasOptifine();
41-
} catch (Throwable ignored) {
42-
//Ok, we'll do it manually then
43-
try {
44-
ClassLoader cl;
45-
cl = Loader.instance().getModClassLoader();
46-
if (cl == null) {
47-
cl = Launch.classLoader;
48-
}
49-
Class.forName("Config", false, cl);
50-
detected = true;
51-
} catch (Throwable ignored1) {
52-
//99.9% sure that optifine is not present
53-
detected = false;
54-
}
39+
ClassLoader cl = Launch.classLoader;
40+
Class.forName("Config", false, cl);
41+
detected = true;
42+
} catch (Throwable ignored1) {
43+
//99.9% sure that optifine is not present
44+
detected = false;
5545
}
5646
} else {
5747
//server shouldn't have OF

src/main/java/com/falsepattern/falsetweaks/asm/modules/occlusion/optifine/RenderGlobalDeOptimizer.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@
3838
*/
3939
public class RenderGlobalDeOptimizer implements TurboClassTransformer {
4040
private static final String OWNER_INTERNAL_NAME = "net/minecraft/client/renderer/RenderGlobal";
41-
private static final String BAD_FIELD_NAME = "t";
4241
private static final String BAD_FIELD_DESC = "LCompactArrayList;";
4342
private static final String BAD_METHOD_OWNER = "CompactArrayList";
44-
private static final String TARGET_FIELD_NAME = "field_72767_j";
4543
private static final String TARGET_FIELD_DESC = "Ljava/util/List;";
4644
private static final String TARGET_METHOD_OWNER = "java/util/List";
4745

@@ -79,8 +77,7 @@ public boolean transformClass(@NotNull String className, @NotNull ClassNodeHandl
7977
val insn = insnList.next();
8078
if (insn instanceof FieldInsnNode) {
8179
val field = (FieldInsnNode) insn;
82-
if (OWNER_INTERNAL_NAME.equals(field.owner) && BAD_FIELD_NAME.equals(field.name) && BAD_FIELD_DESC.equals(field.desc)) {
83-
field.name = TARGET_FIELD_NAME;
80+
if (OWNER_INTERNAL_NAME.equals(field.owner) && BAD_FIELD_DESC.equals(field.desc)) {
8481
field.desc = TARGET_FIELD_DESC;
8582
modified = true;
8683
}

src/main/java/com/falsepattern/falsetweaks/asm/modules/threadedupdates/compat/Threading_AngelicaRemapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public byte[] transform(String name, String transformedName, byte[] bytes) {
3636
return null;
3737

3838
val reader = new ClassReader(bytes);
39-
val writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
39+
val writer = new ClassWriter(0);
4040
val remapAdapter = new AngelicaRemappingAdapter(writer);
4141
reader.accept(remapAdapter, ClassReader.EXPAND_FRAMES);
4242
return writer.toByteArray();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2024 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* FalseTweaks is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
package com.falsepattern.falsetweaks.mixin.bridge.occlison;
25+
26+
import java.util.List;
27+
28+
public interface IRenderGlobalOptiFastcraft {
29+
List ft$worldRenderersToUpdate();
30+
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/occlusion/optifastcraft/RenderGlobalMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package com.falsepattern.falsetweaks.mixin.mixins.client.occlusion.optifastcraft;
2525

2626
import com.falsepattern.falsetweaks.config.ModuleConfig;
27+
import com.falsepattern.falsetweaks.mixin.bridge.occlison.IRenderGlobalOptiFastcraft;
2728
import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadSafeSettings;
2829
import lombok.val;
2930
import lombok.var;
@@ -47,7 +48,7 @@
4748

4849
@Mixin(value = RenderGlobal.class,
4950
priority = -3)
50-
public abstract class RenderGlobalMixin {
51+
public abstract class RenderGlobalMixin implements IRenderGlobalOptiFastcraft {
5152
@Shadow
5253
public WorldClient theWorld;
5354

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2024 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* FalseTweaks is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
package com.falsepattern.falsetweaks.mixin.mixins.client.occlusion.optifastcraft;
25+
26+
import com.falsepattern.falsetweaks.config.ModuleConfig;
27+
import com.falsepattern.falsetweaks.mixin.bridge.occlison.IRenderGlobalOptiFastcraft;
28+
import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadSafeSettings;
29+
import lombok.val;
30+
import lombok.var;
31+
import org.spongepowered.asm.mixin.Mixin;
32+
import org.spongepowered.asm.mixin.Overwrite;
33+
import org.spongepowered.asm.mixin.Shadow;
34+
import org.spongepowered.asm.mixin.Unique;
35+
36+
import net.minecraft.client.Minecraft;
37+
import net.minecraft.client.multiplayer.WorldClient;
38+
import net.minecraft.client.renderer.EntitySorter;
39+
import net.minecraft.client.renderer.RenderGlobal;
40+
import net.minecraft.client.renderer.WorldRenderer;
41+
import net.minecraft.entity.EntityLivingBase;
42+
import net.minecraft.init.Blocks;
43+
import net.minecraft.util.MathHelper;
44+
45+
import java.nio.IntBuffer;
46+
import java.util.Arrays;
47+
import java.util.List;
48+
49+
@Mixin(value = RenderGlobal.class,
50+
priority = -3)
51+
public abstract class RenderGlobal_DevMixin implements IRenderGlobalOptiFastcraft {
52+
@Shadow
53+
public WorldClient theWorld;
54+
55+
@Shadow
56+
public int renderDistanceChunks;
57+
58+
@Shadow
59+
public Minecraft mc;
60+
61+
@Shadow
62+
public WorldRenderer[] worldRenderers;
63+
64+
@Shadow
65+
public int renderChunksWide;
66+
67+
@Shadow
68+
public int renderChunksTall;
69+
70+
@Shadow
71+
public int renderChunksDeep;
72+
73+
@Shadow
74+
public WorldRenderer[] sortedWorldRenderers;
75+
76+
@Shadow
77+
public int minBlockX;
78+
79+
@Shadow
80+
public int minBlockY;
81+
82+
@Shadow
83+
public int minBlockZ;
84+
85+
@Shadow
86+
public int maxBlockX;
87+
88+
@Shadow
89+
public int maxBlockY;
90+
91+
@Shadow
92+
public int maxBlockZ;
93+
94+
@Shadow
95+
public List tileEntities;
96+
@SuppressWarnings("MissingUnique")
97+
public List worldRenderersToUpdate;
98+
99+
@Shadow
100+
private boolean occlusionEnabled;
101+
102+
@Shadow
103+
private int renderEntitiesStartupCounter;
104+
105+
@Shadow
106+
private IntBuffer glOcclusionQueryBase;
107+
108+
@Shadow
109+
private int glRenderListBase;
110+
111+
@Shadow
112+
public abstract void onStaticEntitiesChanged();
113+
114+
@Shadow
115+
public abstract void markRenderersForNewPosition(int p_72722_1_, int p_72722_2_, int p_72722_3_);
116+
117+
/**
118+
* @author FalsePattern
119+
* @reason Optifine Unpatch
120+
*/
121+
@Overwrite
122+
public void loadRenderers() {
123+
if (this.theWorld != null) {
124+
ft$updateLeafFancyGraphics();
125+
126+
this.renderDistanceChunks = this.mc.gameSettings.renderDistanceChunks;
127+
int i;
128+
129+
if (this.worldRenderers != null) {
130+
for (i = 0; i < this.worldRenderers.length; ++i) {
131+
this.worldRenderers[i].stopRendering();
132+
}
133+
}
134+
135+
i = this.renderDistanceChunks * 2 + 1;
136+
this.renderChunksWide = i;
137+
this.renderChunksTall = 16;
138+
this.renderChunksDeep = i;
139+
this.worldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall * this.renderChunksDeep];
140+
this.sortedWorldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall * this.renderChunksDeep];
141+
int j = 0;
142+
int k = 0;
143+
this.minBlockX = 0;
144+
this.minBlockY = 0;
145+
this.minBlockZ = 0;
146+
this.maxBlockX = this.renderChunksWide;
147+
this.maxBlockY = this.renderChunksTall;
148+
this.maxBlockZ = this.renderChunksDeep;
149+
int l;
150+
151+
for (l = 0; l < this.worldRenderersToUpdate.size(); ++l) {
152+
((WorldRenderer) this.worldRenderersToUpdate.get(l)).needsUpdate = false;
153+
}
154+
155+
this.worldRenderersToUpdate.clear();
156+
this.tileEntities.clear();
157+
this.onStaticEntitiesChanged();
158+
159+
for (l = 0; l < this.renderChunksWide; ++l) {
160+
for (int i1 = 0; i1 < this.renderChunksTall; ++i1) {
161+
for (int j1 = 0; j1 < this.renderChunksDeep; ++j1) {
162+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l] =
163+
new WorldRenderer(this.theWorld, this.tileEntities, l * 16, i1 * 16, j1 * 16, this.glRenderListBase + j);
164+
165+
if (this.occlusionEnabled) {
166+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].glOcclusionQuery = this.glOcclusionQueryBase.get(k);
167+
}
168+
169+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isWaitingOnOcclusionQuery = false;
170+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isVisible = true;
171+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isInFrustum = true;
172+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].chunkIndex = k++;
173+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].markDirty();
174+
this.sortedWorldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l] =
175+
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l];
176+
this.worldRenderersToUpdate.add(this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l]);
177+
j += 3;
178+
}
179+
}
180+
}
181+
182+
if (this.theWorld != null) {
183+
EntityLivingBase entitylivingbase = this.mc.renderViewEntity;
184+
185+
if (entitylivingbase != null) {
186+
this.markRenderersForNewPosition(MathHelper.floor_double(entitylivingbase.posX), MathHelper.floor_double(entitylivingbase.posY),
187+
MathHelper.floor_double(entitylivingbase.posZ));
188+
Arrays.sort(this.sortedWorldRenderers, new EntitySorter(entitylivingbase));
189+
}
190+
}
191+
192+
this.renderEntitiesStartupCounter = 2;
193+
}
194+
}
195+
196+
@Unique
197+
private void ft$updateLeafFancyGraphics() {
198+
val gameSettings = mc.gameSettings;
199+
var fancyGraphics = false;
200+
if (ModuleConfig.THREADED_CHUNK_UPDATES()) {
201+
fancyGraphics = ((ThreadSafeSettings) gameSettings).ft$fancyGraphics();
202+
} else {
203+
// This field does not exist if threaded chunk updates are used.
204+
fancyGraphics = mc.gameSettings.fancyGraphics;
205+
}
206+
Blocks.leaves.setGraphicsLevel(fancyGraphics);
207+
Blocks.leaves2.setGraphicsLevel(fancyGraphics);
208+
}
209+
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/triangulator/TessellatorMixin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ private int extendAddVertexStep(int constant) {
259259
@ModifyConstant(method = "draw",
260260
constant = @Constant(intValue = 32),
261261
require = 5,
262+
expect = 5,
262263
// OptiFine
263264
allow = 6) // Vanilla
264265
private int extendDrawStride(int constant) {
@@ -268,6 +269,7 @@ private int extendDrawStride(int constant) {
268269
@ModifyConstant(method = "draw",
269270
constant = @Constant(intValue = 8),
270271
require = 0,
272+
expect = 0,
271273
// OptiFine
272274
allow = 2) // Vanilla
273275
private int extendDrawOffset(int constant) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import lombok.Getter;
3232
import lombok.RequiredArgsConstructor;
3333

34+
import net.minecraft.launchwrapper.Launch;
35+
3436
import java.util.List;
3537
import java.util.function.Predicate;
3638

@@ -153,8 +155,11 @@ public enum Mixin implements IMixin {
153155

154156
//Both of them
155157
Occlusion_OptiFastCraft_RenderGlobalMixin(Side.CLIENT,
156-
THREADING.and(require(TargetedMod.FASTCRAFT).or(REQUIRE_ANY_OPTIFINE)),
158+
THREADING.and(require(TargetedMod.FASTCRAFT).or(REQUIRE_ANY_OPTIFINE)).and(condition(() -> !(Boolean)Launch.blackboard.get("fml.deobfuscatedEnvironment"))),
157159
"occlusion.optifastcraft.RenderGlobalMixin"),
160+
Occlusion_OptiFastCraft_RenderGlobal_DevMixin(Side.CLIENT,
161+
THREADING.and(require(TargetedMod.FASTCRAFT).or(REQUIRE_ANY_OPTIFINE)).and(condition(() -> (Boolean)Launch.blackboard.get("fml.deobfuscatedEnvironment"))),
162+
"occlusion.optifastcraft.RenderGlobal_DevMixin"),
158163

159164
//endregion Occlusion Tweaks Module
160165

0 commit comments

Comments
 (0)