Skip to content

Commit ae2ea26

Browse files
committed
secure setLightmapTextureCoords
1 parent a59ee41 commit ae2ea26

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.threadedupdates;
25+
26+
import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadedChunkUpdateHelper;
27+
import org.spongepowered.asm.mixin.Mixin;
28+
import org.spongepowered.asm.mixin.injection.At;
29+
import org.spongepowered.asm.mixin.injection.Inject;
30+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
31+
32+
import net.minecraft.client.renderer.OpenGlHelper;
33+
34+
@Mixin(value = OpenGlHelper.class,
35+
priority = 900)
36+
public abstract class OpenGLHelperMixin {
37+
@Inject(method = "setLightmapTextureCoords",
38+
at = @At("HEAD"),
39+
cancellable = true,
40+
require = 1)
41+
private static void onlyIfMainThread(int target, float x, float y, CallbackInfo ci) {
42+
if (!ThreadedChunkUpdateHelper.isMainThread()) {
43+
ci.cancel();
44+
}
45+
}
46+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public enum Mixin implements IMixin {
157157

158158
//region Threaded Chunk Updates
159159
ThreadedUpdates_GameSettings(Side.CLIENT, THREADING, "threadedupdates.GameSettingsMixin"),
160+
ThreadedUpdates_OpenGLHelperMixin(Side.CLIENT, THREADING, "threadedupdates.OpenGLHelperMixin"),
160161
ThreadedUpdates_ChunkProviderClientMixin(Side.CLIENT, THREADING, "threadedupdates.ChunkProviderClientMixin"),
161162
ThreadedUpdates_ForgeHooksClientMixin(Side.CLIENT, THREADING, "threadedupdates.ForgeHooksClientMixin"),
162163
ThreadedUpdates_RenderBlocksMixin(Side.CLIENT, THREADING, "threadedupdates.RenderBlocksMixin"),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ public static boolean canBlockBeRenderedOffThread(Block block, int pass, int ren
264264
}
265265

266266
public static boolean isMainThread() {
267+
val thread = Thread.currentThread();
267268
if (MAIN_THREAD == null)
268-
throw new AssertionError("Main thread not setup, mad.");
269-
return Thread.currentThread() == MAIN_THREAD;
269+
return thread.getName().equals("Client thread");
270+
return thread == MAIN_THREAD;
270271
}
271272

272273
private static String worldRendererToString(WorldRenderer wr) {

0 commit comments

Comments
 (0)