Skip to content

Commit 6f0d6e4

Browse files
committed
Merge remote-tracking branch 'origin/1.16' into 1.18
2 parents a79ea97 + 675c58a commit 6f0d6e4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

forge/src/main/java/org/embeddedt/modernfix/forge/dynresources/ModelBakeEventHelper.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@
2121
import org.jetbrains.annotations.Nullable;
2222

2323
import java.util.*;
24+
import java.util.function.BiFunction;
2425

2526
/**
2627
* Stores a list of all known default block/item models in the game, and provides a namespaced version
2728
* of the model registry that emulates vanilla keySet behavior.
2829
*/
2930
public class ModelBakeEventHelper {
3031
// TODO: make into config option
31-
private static final Set<String> INCOMPATIBLE_MODS = ImmutableSet.of("industrialforegoing", "vampirism", "elevatorid");
32+
private static final Set<String> INCOMPATIBLE_MODS = ImmutableSet.of(
33+
"industrialforegoing",
34+
"mekanism",
35+
"vampirism",
36+
"elevatorid");
3237
private final Map<ResourceLocation, BakedModel> modelRegistry;
3338
private final Set<ResourceLocation> topLevelModelLocations;
3439
private final MutableGraph<String> dependencyGraph;
@@ -79,7 +84,7 @@ protected Map<ResourceLocation, BakedModel> delegate() {
7984
private void logWarning() {
8085
if(!WARNED_MOD_IDS.add(modId))
8186
return;
82-
ModernFix.LOGGER.warn("Mod '{}' is accessing Map#keySet/entrySet/values on the model registry map inside its event handler." +
87+
ModernFix.LOGGER.warn("Mod '{}' is accessing Map#keySet/entrySet/values/replaceAll on the model registry map inside its event handler." +
8388
" This probably won't work as expected with dynamic resources on. Prefer using Map#get/put and constructing ModelResourceLocations another way.", modId);
8489
}
8590

@@ -100,6 +105,12 @@ public Collection<BakedModel> values() {
100105
logWarning();
101106
return super.values();
102107
}
108+
109+
@Override
110+
public void replaceAll(BiFunction<? super ResourceLocation, ? super BakedModel, ? extends BakedModel> function) {
111+
logWarning();
112+
super.replaceAll(function);
113+
}
103114
};
104115
}
105116

@@ -139,6 +150,19 @@ public Set<ResourceLocation> keySet() {
139150
public boolean containsKey(@Nullable Object key) {
140151
return ourModelLocations.contains(key) || super.containsKey(key);
141152
}
153+
154+
@Override
155+
public void replaceAll(BiFunction<? super ResourceLocation, ? super BakedModel, ? extends BakedModel> function) {
156+
ModernFix.LOGGER.warn("Mod '{}' is calling replaceAll on the model registry. This requires temporarily loading every model for that mod, which is slow.", modId);
157+
List<ResourceLocation> locations = new ArrayList<>(keySet());
158+
for(ResourceLocation location : locations) {
159+
BakedModel existing = get(location);
160+
BakedModel replacement = function.apply(location, existing);
161+
if(replacement != existing) {
162+
put(location, replacement);
163+
}
164+
}
165+
}
142166
};
143167
}
144168
}

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ForgeHooksClientMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources;
22

3+
import com.google.common.base.Stopwatch;
34
import net.minecraft.client.resources.model.BakedModel;
45
import net.minecraft.resources.ResourceLocation;
56
import net.minecraftforge.client.ForgeHooksClient;
@@ -9,13 +10,15 @@
910
import net.minecraftforge.fml.ModList;
1011
import net.minecraftforge.fml.ModLoader;
1112
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
13+
import org.embeddedt.modernfix.ModernFix;
1214
import org.embeddedt.modernfix.forge.dynresources.ModelBakeEventHelper;
1315
import org.spongepowered.asm.mixin.Mixin;
1416
import org.spongepowered.asm.mixin.injection.At;
1517
import org.spongepowered.asm.mixin.injection.Redirect;
1618

1719
import java.lang.reflect.Method;
1820
import java.util.Map;
21+
import java.util.concurrent.TimeUnit;
1922

2023
@Mixin(ForgeHooksClient.class)
2124
public class ForgeHooksClientMixin {
@@ -32,11 +35,16 @@ private static void postNamespacedKeySetEvent(ModLoader loader, Event event) {
3235
ModList.get().forEachModContainer((id, mc) -> {
3336
Map<ResourceLocation, BakedModel> newRegistry = helper.wrapRegistry(id);
3437
ModelBakeEvent postedEvent = new ModelBakeEvent(bakeEvent.getModelManager(), newRegistry, bakeEvent.getModelLoader());
38+
Stopwatch timer = Stopwatch.createStarted();
3539
try {
3640
acceptEv.invoke(mc, postedEvent);
3741
} catch(ReflectiveOperationException e) {
3842
e.printStackTrace();
3943
}
44+
timer.stop();
45+
if(timer.elapsed(TimeUnit.SECONDS) >= 1) {
46+
ModernFix.LOGGER.warn("Mod '{}' took {} in the model bake event", id, timer);
47+
}
4048
});
4149
}
4250
}

0 commit comments

Comments
 (0)