Fix ModelDiscovery using Item components early (#10418)

This commit is contained in:
Jonathing 2025-02-12 20:02:52 -05:00 committed by GitHub
parent 0749f49b6c
commit ef224bd2b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,12 @@
--- a/net/minecraft/client/resources/model/ModelDiscovery.java
+++ b/net/minecraft/client/resources/model/ModelDiscovery.java
@@ -37,7 +_,8 @@
private static Set<ModelResourceLocation> listMandatoryModels() {
Set<ModelResourceLocation> set = new HashSet<>();
BuiltInRegistries.ITEM.listElements().forEach(p_368638_ -> {
- ResourceLocation resourcelocation = p_368638_.value().components().get(DataComponents.ITEM_MODEL);
+ // Forge: Force use vanilla components without gathering mod components in the event
+ ResourceLocation resourcelocation = p_368638_.value().vanillaComponents().get(DataComponents.ITEM_MODEL);
if (resourcelocation != null) {
set.add(ModelResourceLocation.inventory(resourcelocation));
}

View file

@ -28,7 +28,7 @@
}
@Deprecated
@@ -123,17 +_,25 @@
@@ -123,17 +_,35 @@
return this.builtInRegistryHolder;
}
@ -42,6 +42,16 @@
+ }
+
+ return builtComponents;
+ }
+
+ /**
+ * Forge: Hack fix used in
+ * {@link net.minecraft.client.resources.model.ModelDiscovery#listMandatoryModels ModelBakery.listMandatoryModels},
+ * during mod loading, before the Forge event bus is ready.
+ */
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public DataComponentMap vanillaComponents() {
+ return components;
}
public int getDefaultMaxStackSize() {