Skip to content

Commit 1a25984

Browse files
committed
Merge remote-tracking branch 'origin/1.16' into 1.18
2 parents 9c380e5 + c1277a2 commit 1a25984

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ private boolean trustedResourcePack(PackResources pack) {
237237
pack instanceof FilePackResources;
238238
}
239239

240+
/**
241+
* Make a copy of the top-level model list and stream that to avoid CMEs if the getMaterials call triggers a model
242+
* load.
243+
*/
244+
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Collection;stream()Ljava/util/stream/Stream;", ordinal = 0))
245+
private Stream<?> getModelStream(Collection<?> modelCollection) {
246+
return new ArrayList<>(modelCollection).stream();
247+
}
248+
240249
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;", ordinal = 0))
241250
private Object collectExtraTextures(Stream<Material> instance, Collector<?, ?, ?> arCollector) {
242251
Set<Material> materialsSet = new ObjectOpenHashSet<>(instance.collect(Collectors.toSet()));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.concurrent.TimeUnit;
5555
import java.util.function.BiConsumer;
5656
import java.util.function.Function;
57+
import java.util.stream.Stream;
5758

5859
/* high priority so that our injectors are added before other mods' */
5960
@Mixin(value = ModelBakery.class, priority = 600)
@@ -162,6 +163,15 @@ private void addTopLevelFile(ModelResourceLocation location, CallbackInfo ci) {
162163
}
163164
}
164165

166+
/**
167+
* Make a copy of the top-level model list and stream that to avoid CMEs if the getMaterials call triggers a model
168+
* load.
169+
*/
170+
@Redirect(method = "processLoading", at = @At(value = "INVOKE", target = "Ljava/util/Collection;stream()Ljava/util/stream/Stream;", ordinal = 0), remap = false)
171+
private Stream<?> getModelStream(Collection<?> modelCollection) {
172+
return new ArrayList<>(modelCollection).stream();
173+
}
174+
165175
@Redirect(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;gatherFluidTextures(Ljava/util/Set;)V", remap = false), remap = false)
166176
private void gatherModelTextures(Set<Material> materialSet) {
167177
ForgeHooksClient.gatherFluidTextures(materialSet);

0 commit comments

Comments
 (0)