Skip to content

Commit 8a3b7f7

Browse files
committed
Merge remote-tracking branch 'origin/1.20' into 1.21.1
2 parents 3194d30 + 588b565 commit 8a3b7f7

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.model_optimizations;
2+
3+
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
4+
import net.minecraft.client.renderer.block.model.MultiVariant;
5+
import net.minecraft.client.renderer.block.model.Variant;
6+
import net.minecraft.client.resources.model.UnbakedModel;
7+
import net.minecraft.resources.ResourceLocation;
8+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Overwrite;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
13+
import java.util.List;
14+
import java.util.function.Function;
15+
16+
@Mixin(value = MultiVariant.class, priority = 700)
17+
@ClientOnlyMixin
18+
public abstract class MultiVariantMixin {
19+
@Shadow public abstract List<Variant> getVariants();
20+
21+
/**
22+
* @author embeddedt
23+
* @reason avoid streams, try to optimize for common case
24+
*/
25+
@Overwrite
26+
public void resolveParents(Function<ResourceLocation, UnbakedModel> modelGetter) {
27+
var variants = this.getVariants();
28+
// There is usually only a single variant
29+
if (variants.size() == 1) {
30+
modelGetter.apply(variants.get(0).getModelLocation()).resolveParents(modelGetter);
31+
} else if(variants.size() > 1) {
32+
ObjectOpenHashSet<ResourceLocation> seenLocations = new ObjectOpenHashSet<>(variants.size());
33+
for (var variant : variants) {
34+
var location = variant.getModelLocation();
35+
if (seenLocations.add(location)) {
36+
modelGetter.apply(location).resolveParents(modelGetter);
37+
}
38+
}
39+
}
40+
}
41+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public Map<ModelResourceLocation, BakedModel> wrapRegistry(String modId) {
165165
modIdsToInclude.remove("minecraft");
166166
Set<ModelResourceLocation> ourModelLocations;
167167
if (config == UniverseVisibility.SELF_AND_DEPS) {
168+
ModernFix.LOGGER.debug("Mod {} is restricted to seeing models from mods: [{}]", modId, String.join(", ", modIdsToInclude));
168169
ourModelLocations = Sets.filter(this.topLevelModelLocations, loc -> modIdsToInclude.contains(loc.id().getNamespace()));
169170
} else {
170171
ourModelLocations = this.topLevelModelLocations;

0 commit comments

Comments
 (0)