Skip to content

Commit fa5b896

Browse files
committed
feat(threading): Improved tracking for threadsafe blocks
1 parent ebbc31d commit fa5b896

9 files changed

Lines changed: 138 additions & 77 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 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, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.mixin.mixins.client.threadedupdates;
24+
25+
import com.falsepattern.falsetweaks.modules.threadedupdates.saftey.IBlockExt;
26+
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.Unique;
28+
29+
import net.minecraft.block.Block;
30+
31+
@Mixin(Block.class)
32+
public abstract class BlockMixin implements IBlockExt {
33+
@Unique
34+
private boolean ft$isThreadSafe = false;
35+
36+
@Override
37+
public void ft$isThreadSafe(boolean value) {
38+
ft$isThreadSafe = value;
39+
}
40+
41+
@Override
42+
public boolean ft$isThreadSafe() {
43+
return ft$isThreadSafe;
44+
}
45+
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/threadedupdates/RenderingRegistryMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public abstract class RenderingRegistryMixin implements IRenderingRegistryExt {
3939
private Map<Integer, ISimpleBlockRenderingHandler> blockRenderers;
4040

4141
@Override
42-
public ISimpleBlockRenderingHandler getISBRH(Block block) {
42+
public ISimpleBlockRenderingHandler ft$getRenderer(Block block) {
4343
return blockRenderers.get(block.getRenderType());
4444
}
4545
}

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
@@ -192,6 +192,7 @@ public enum Mixin implements IMixins {
192192
"threadedupdates.RenderingRegistryMixin",
193193
"threadedupdates.TessellatorMixin",
194194
"threadedupdates.ChunkCacheMixin",
195+
"threadedupdates.BlockMixin",
195196
"threadedupdates.blockbounds.BlockMixin_Root",
196197
"threadedupdates.blockbounds.BlockMixin_Impl")),
197198
ThreadedUpdates_blockBounds(Phase.EARLY,

src/main/java/com/falsepattern/falsetweaks/modules/beddium/FTChunkBuilderMeshingTask.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.falsepattern.falsetweaks.config.ModuleConfig;
2727
import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadTessellator;
2828
import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadedUpdateHooks;
29-
import com.falsepattern.falsetweaks.modules.threadedupdates.saftey.ThreadedBlockSafetyRegistry;
29+
import com.falsepattern.falsetweaks.modules.threadedupdates.saftey.IBlockExt;
3030
import com.ventooth.beddium.api.task.SimpleChunkBuilderMeshingTask;
3131
import com.ventooth.beddium.api.task.WorldRenderRegion;
3232
import it.unimi.dsi.fastutil.ints.IntList;
@@ -99,12 +99,8 @@ protected boolean isThreaded() {
9999

100100
@Override
101101
protected boolean canRenderOffThread(int pass, Block block, int x, int y, int z) {
102-
val rt = block.getRenderType();
103-
// Vanilla render types end at 42
104-
if (rt < 42) {
105-
return true;
106-
}
107-
return ThreadedBlockSafetyRegistry.canBlockRenderOffThread(block);
102+
return IBlockExt.of(block)
103+
.ft$isThreadSafe();
108104
}
109105

110106
@Override
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 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, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.modules.threadedupdates.saftey;
24+
25+
import net.minecraft.block.Block;
26+
27+
public interface IBlockExt {
28+
@SuppressWarnings("CastToIncompatibleInterface")
29+
static IBlockExt of(Block thiz) {
30+
return (IBlockExt) thiz;
31+
}
32+
33+
void ft$isThreadSafe(boolean value);
34+
35+
boolean ft$isThreadSafe();
36+
}

src/main/java/com/falsepattern/falsetweaks/modules/threadedupdates/saftey/IRenderingRegistryExt.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424

2525
import net.minecraft.block.Block;
2626
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
27+
import cpw.mods.fml.client.registry.RenderingRegistry;
2728

2829
// Ported from Angelica
2930
public interface IRenderingRegistryExt {
30-
ISimpleBlockRenderingHandler getISBRH(Block block);
31+
@SuppressWarnings("CastToIncompatibleInterface")
32+
static IRenderingRegistryExt of(RenderingRegistry thiz) {
33+
return (IRenderingRegistryExt) thiz;
34+
}
35+
36+
ISimpleBlockRenderingHandler ft$getRenderer(Block block);
3137
}

src/main/java/com/falsepattern/falsetweaks/modules/threadedupdates/saftey/ThreadSafeBlockRendererMap.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626
import lombok.Data;
2727
import lombok.SneakyThrows;
2828
import lombok.val;
29+
import lombok.var;
2930
import org.apache.logging.log4j.LogManager;
3031

32+
import net.minecraft.block.Block;
3133
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
3234
import cpw.mods.fml.client.registry.RenderingRegistry;
3335
import cpw.mods.fml.common.Loader;
36+
import cpw.mods.fml.common.registry.GameData;
37+
import cpw.mods.fml.common.registry.GameRegistry;
3438

3539
import java.util.AbstractMap;
3640
import java.util.ArrayList;
@@ -117,6 +121,46 @@ public static void logBrokenISBRHs() {
117121
logger.error(Strings.repeat("+=", 25));
118122
}
119123

124+
public static void markThreadsafeBlocks() {
125+
val logger = LOG_ISBRH_ERRORS ? LogManager.getLogger("FT|THREAD SAFETY") : null;
126+
127+
//noinspection deprecation
128+
val renderingRegistry = IRenderingRegistryExt.of(RenderingRegistry.instance());
129+
//noinspection unchecked
130+
val blockRegistry = (Iterable<Block>) GameData.getBlockRegistry();
131+
for (val block : blockRegistry) {
132+
val isThreadsafe = isBlockThreadsafe(renderingRegistry, block);
133+
IBlockExt.of(block)
134+
.ft$isThreadSafe(isThreadsafe);
135+
if (logger != null) {
136+
val blockId = GameRegistry.findUniqueIdentifierFor(block);
137+
final String blockName;
138+
if (blockId == null) {
139+
//noinspection ObjectToString
140+
blockName = "UNKNOWN(" + block + ")";
141+
} else {
142+
blockName = "(" + blockId + ")";
143+
}
144+
145+
if (isThreadsafe) {
146+
logger.debug("Block Threadsafe: {}", blockName);
147+
} else {
148+
logger.warn("Block NOT Threadsafe: {}", blockName);
149+
}
150+
}
151+
}
152+
}
153+
154+
private static boolean isBlockThreadsafe(IRenderingRegistryExt renderingRegistry, Block block) {
155+
val renderType = block.getRenderType();
156+
// Vanilla render types end at 42
157+
if (renderType < 42) {
158+
return true;
159+
}
160+
val renderer = renderingRegistry.ft$getRenderer(block);
161+
return renderer instanceof ThreadSafeBlockRenderer;
162+
}
163+
120164
@Override
121165
public ISimpleBlockRenderingHandler put(Integer key, ISimpleBlockRenderingHandler value) {
122166
log:

src/main/java/com/falsepattern/falsetweaks/modules/threadedupdates/saftey/ThreadedBlockSafetyRegistry.java

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

src/main/java/com/falsepattern/falsetweaks/proxy/ClientProxy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public void postInit(FMLPostInitializationEvent e) {
174174
public void loadComplete(FMLLoadCompleteEvent e) {
175175
super.loadComplete(e);
176176
ThreadSafeBlockRendererMap.logBrokenISBRHs();
177+
ThreadSafeBlockRendererMap.markThreadsafeBlocks();
177178
}
178179

179180
@SubscribeEvent

0 commit comments

Comments
 (0)