Skip to content

Commit

Permalink
secure setLightmapTextureCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 1, 2024
1 parent a59ee41 commit ae2ea26
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of FalseTweaks.
*
* Copyright (C) 2022-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalseTweaks is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FalseTweaks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
*/

package com.falsepattern.falsetweaks.mixin.mixins.client.threadedupdates;

import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadedChunkUpdateHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.renderer.OpenGlHelper;

@Mixin(value = OpenGlHelper.class,
priority = 900)
public abstract class OpenGLHelperMixin {
@Inject(method = "setLightmapTextureCoords",
at = @At("HEAD"),
cancellable = true,
require = 1)
private static void onlyIfMainThread(int target, float x, float y, CallbackInfo ci) {
if (!ThreadedChunkUpdateHelper.isMainThread()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public enum Mixin implements IMixin {

//region Threaded Chunk Updates
ThreadedUpdates_GameSettings(Side.CLIENT, THREADING, "threadedupdates.GameSettingsMixin"),
ThreadedUpdates_OpenGLHelperMixin(Side.CLIENT, THREADING, "threadedupdates.OpenGLHelperMixin"),
ThreadedUpdates_ChunkProviderClientMixin(Side.CLIENT, THREADING, "threadedupdates.ChunkProviderClientMixin"),
ThreadedUpdates_ForgeHooksClientMixin(Side.CLIENT, THREADING, "threadedupdates.ForgeHooksClientMixin"),
ThreadedUpdates_RenderBlocksMixin(Side.CLIENT, THREADING, "threadedupdates.RenderBlocksMixin"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ public static boolean canBlockBeRenderedOffThread(Block block, int pass, int ren
}

public static boolean isMainThread() {
val thread = Thread.currentThread();
if (MAIN_THREAD == null)
throw new AssertionError("Main thread not setup, mad.");
return Thread.currentThread() == MAIN_THREAD;
return thread.getName().equals("Client thread");
return thread == MAIN_THREAD;
}

private static String worldRendererToString(WorldRenderer wr) {
Expand Down

0 comments on commit ae2ea26

Please sign in to comment.