diff --git a/patches/net/minecraft/data/models/BlockModelGenerators.java.patch b/__old__/net/minecraft/data/models/BlockModelGenerators.java.patch similarity index 100% rename from patches/net/minecraft/data/models/BlockModelGenerators.java.patch rename to __old__/net/minecraft/data/models/BlockModelGenerators.java.patch diff --git a/patches/net/minecraft/data/models/EquipmentModelProvider.java.patch b/__old__/net/minecraft/data/models/EquipmentModelProvider.java.patch similarity index 100% rename from patches/net/minecraft/data/models/EquipmentModelProvider.java.patch rename to __old__/net/minecraft/data/models/EquipmentModelProvider.java.patch diff --git a/patches/net/minecraft/data/models/ItemModelGenerators.java.patch b/__old__/net/minecraft/data/models/ItemModelGenerators.java.patch similarity index 100% rename from patches/net/minecraft/data/models/ItemModelGenerators.java.patch rename to __old__/net/minecraft/data/models/ItemModelGenerators.java.patch diff --git a/patches/net/minecraft/world/item/equipment/EquipmentModels.java.patch b/__old__/net/minecraft/world/item/equipment/EquipmentModels.java.patch similarity index 100% rename from patches/net/minecraft/world/item/equipment/EquipmentModels.java.patch rename to __old__/net/minecraft/world/item/equipment/EquipmentModels.java.patch diff --git a/patches/net/minecraft/client/data/models/ModelProvider.java.patch b/patches/net/minecraft/client/data/models/ModelProvider.java.patch new file mode 100644 index 0000000000..1254ff2e12 --- /dev/null +++ b/patches/net/minecraft/client/data/models/ModelProvider.java.patch @@ -0,0 +1,115 @@ +--- a/net/minecraft/client/data/models/ModelProvider.java ++++ b/net/minecraft/client/data/models/ModelProvider.java +@@ -34,20 +_,40 @@ + private final PackOutput.PathProvider blockStatePathProvider; + private final PackOutput.PathProvider itemInfoPathProvider; + private final PackOutput.PathProvider modelPathProvider; +- +- public ModelProvider(PackOutput p_388260_) { ++ public final String modId; ++ ++ // NeoForge: Use the above constructor passing in their mod id ++ @Deprecated ++ public ModelProvider(PackOutput p_252226_) { ++ this(p_252226_, ResourceLocation.DEFAULT_NAMESPACE); ++ } ++ ++ public ModelProvider(PackOutput p_388260_, String modId) { + this.blockStatePathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "blockstates"); + this.itemInfoPathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "items"); + this.modelPathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "models"); ++ this.modId = modId; ++ } ++ ++ protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { ++ blockModels.run(); ++ itemModels.run(); ++ } ++ ++ protected Stream> getKnownBlocks() { ++ return BuiltInRegistries.BLOCK.listElements().filter(holder -> holder.getKey().location().getNamespace().equals(modId)); ++ } ++ ++ protected Stream> getKnownItems() { ++ return BuiltInRegistries.ITEM.listElements().filter(holder -> holder.getKey().location().getNamespace().equals(modId)); + } + + @Override + public CompletableFuture run(CachedOutput p_387857_) { +- ModelProvider.ItemInfoCollector modelprovider$iteminfocollector = new ModelProvider.ItemInfoCollector(); +- ModelProvider.BlockStateGeneratorCollector modelprovider$blockstategeneratorcollector = new ModelProvider.BlockStateGeneratorCollector(); ++ ModelProvider.ItemInfoCollector modelprovider$iteminfocollector = new ModelProvider.ItemInfoCollector(this::getKnownItems); ++ ModelProvider.BlockStateGeneratorCollector modelprovider$blockstategeneratorcollector = new ModelProvider.BlockStateGeneratorCollector(this::getKnownBlocks); + ModelProvider.SimpleModelCollector modelprovider$simplemodelcollector = new ModelProvider.SimpleModelCollector(); +- new BlockModelGenerators(modelprovider$blockstategeneratorcollector, modelprovider$iteminfocollector, modelprovider$simplemodelcollector).run(); +- new ItemModelGenerators(modelprovider$iteminfocollector, modelprovider$simplemodelcollector).run(); ++ registerModels(new BlockModelGenerators(modelprovider$blockstategeneratorcollector, modelprovider$iteminfocollector, modelprovider$simplemodelcollector), new ItemModelGenerators(modelprovider$iteminfocollector, modelprovider$simplemodelcollector)); + modelprovider$blockstategeneratorcollector.validate(); + modelprovider$iteminfocollector.finalizeAndValidate(); + return CompletableFuture.allOf( +@@ -69,6 +_,15 @@ + @OnlyIn(Dist.CLIENT) + static class BlockStateGeneratorCollector implements Consumer { + private final Map generators = new HashMap<>(); ++ private final Supplier>> knownBlocks; ++ ++ public BlockStateGeneratorCollector(Supplier>> knownBlocks) { ++ this.knownBlocks = knownBlocks; ++ } ++ ++ public BlockStateGeneratorCollector() { ++ this(BuiltInRegistries.BLOCK::listElements); ++ } + + public void accept(BlockStateGenerator p_388748_) { + Block block = p_388748_.getBlock(); +@@ -79,9 +_,9 @@ + } + + public void validate() { +- Stream> stream = BuiltInRegistries.BLOCK.listElements().filter(p_388333_ -> true); ++ Stream> stream = knownBlocks.get(); + List list = stream.filter(p_386843_ -> !this.generators.containsKey(p_386843_.value())) +- .map(p_386823_ -> p_386823_.key().location()) ++ .map(p_386823_ -> p_386823_.unwrapKey().orElseThrow().location()) + .toList(); + if (!list.isEmpty()) { + throw new IllegalStateException("Missing blockstate definitions for: " + list); +@@ -97,6 +_,15 @@ + static class ItemInfoCollector implements ItemModelOutput { + private final Map itemInfos = new HashMap<>(); + private final Map copies = new HashMap<>(); ++ private final Supplier>> knownItems; ++ ++ public ItemInfoCollector(Supplier>> knownItems) { ++ this.knownItems = knownItems; ++ } ++ ++ public ItemInfoCollector() { ++ this(BuiltInRegistries.ITEM::listElements); ++ } + + @Override + public void accept(Item p_387063_, ItemModel.Unbaked p_388578_) { +@@ -116,7 +_,7 @@ + } + + public void finalizeAndValidate() { +- BuiltInRegistries.ITEM.forEach(p_388426_ -> { ++ knownItems.get().map(Holder::value).forEach(p_388426_ -> { + if (!this.copies.containsKey(p_388426_)) { + if (p_388426_ instanceof BlockItem blockitem && !this.itemInfos.containsKey(blockitem)) { + ResourceLocation resourcelocation = ModelLocationUtils.getModelLocation(blockitem.getBlock()); +@@ -132,10 +_,9 @@ + this.register(p_386494_, clientitem); + } + }); +- List list = BuiltInRegistries.ITEM +- .listElements() ++ List list = knownItems.get() + .filter(p_388636_ -> !this.itemInfos.containsKey(p_388636_.value())) +- .map(p_388278_ -> p_388278_.key().location()) ++ .map(p_388278_ -> p_388278_.unwrapKey().orElseThrow().location()) + .toList(); + if (!list.isEmpty()) { + throw new IllegalStateException("Missing item model definitions for: " + list); diff --git a/patches/net/minecraft/data/models/model/ModelLocationUtils.java.patch b/patches/net/minecraft/client/data/models/model/ModelLocationUtils.java.patch similarity index 52% rename from patches/net/minecraft/data/models/model/ModelLocationUtils.java.patch rename to patches/net/minecraft/client/data/models/model/ModelLocationUtils.java.patch index ac45b38362..662c5cfca7 100644 --- a/patches/net/minecraft/data/models/model/ModelLocationUtils.java.patch +++ b/patches/net/minecraft/client/data/models/model/ModelLocationUtils.java.patch @@ -1,18 +1,18 @@ ---- a/net/minecraft/data/models/model/ModelLocationUtils.java -+++ b/net/minecraft/data/models/model/ModelLocationUtils.java -@@ -8,11 +_,13 @@ +--- a/net/minecraft/client/data/models/model/ModelLocationUtils.java ++++ b/net/minecraft/client/data/models/model/ModelLocationUtils.java +@@ -11,11 +_,13 @@ public class ModelLocationUtils { @Deprecated - public static ResourceLocation decorateBlockModelLocation(String p_125582_) { -- return ResourceLocation.withDefaultNamespace("block/" + p_125582_); + public static ResourceLocation decorateBlockModelLocation(String p_388520_) { +- return ResourceLocation.withDefaultNamespace("block/" + p_388520_); + // NeoForge: Use ResourceLocation.parse to support modded paths -+ return ResourceLocation.parse(p_125582_).withPrefix("block/"); ++ return ResourceLocation.parse(p_388520_).withPrefix("block/"); } - public static ResourceLocation decorateItemModelLocation(String p_125584_) { -- return ResourceLocation.withDefaultNamespace("item/" + p_125584_); + public static ResourceLocation decorateItemModelLocation(String p_387226_) { +- return ResourceLocation.withDefaultNamespace("item/" + p_387226_); + // NeoForge: Use ResourceLocation.parse to support modded paths -+ return ResourceLocation.parse(p_125584_).withPrefix("item/"); ++ return ResourceLocation.parse(p_387226_).withPrefix("item/"); } - public static ResourceLocation getModelLocation(Block p_125579_, String p_125580_) { + public static ResourceLocation getModelLocation(Block p_387758_, String p_388221_) { diff --git a/patches/net/minecraft/client/data/models/model/ModelTemplate.java.patch b/patches/net/minecraft/client/data/models/model/ModelTemplate.java.patch new file mode 100644 index 0000000000..cd1e24d3e0 --- /dev/null +++ b/patches/net/minecraft/client/data/models/model/ModelTemplate.java.patch @@ -0,0 +1,41 @@ +--- a/net/minecraft/client/data/models/model/ModelTemplate.java ++++ b/net/minecraft/client/data/models/model/ModelTemplate.java +@@ -51,21 +_,27 @@ + + public ResourceLocation create(ResourceLocation p_388380_, TextureMapping p_387099_, BiConsumer p_387748_) { + Map map = this.createMap(p_387099_); +- p_387748_.accept(p_388380_, () -> { +- JsonObject jsonobject = new JsonObject(); +- this.model.ifPresent(p_388657_ -> jsonobject.addProperty("parent", p_388657_.toString())); +- if (!map.isEmpty()) { +- JsonObject jsonobject1 = new JsonObject(); +- map.forEach((p_387287_, p_386479_) -> jsonobject1.addProperty(p_387287_.getId(), p_386479_.toString())); +- jsonobject.add("textures", jsonobject1); +- } +- +- return jsonobject; +- }); ++ p_387748_.accept(p_388380_, () -> createBaseTemplate(p_388380_, map)); + return p_388380_; + } + ++ public JsonObject createBaseTemplate(ResourceLocation p_388380_, Map map) { ++ JsonObject jsonobject = new JsonObject(); ++ this.model.ifPresent(p_388657_ -> jsonobject.addProperty("parent", p_388657_.toString())); ++ if (!map.isEmpty()) { ++ JsonObject jsonobject1 = new JsonObject(); ++ map.forEach((p_387287_, p_386479_) -> jsonobject1.addProperty(p_387287_.getId(), p_386479_.toString())); ++ jsonobject.add("textures", jsonobject1); ++ } ++ ++ return jsonobject; ++ } ++ + private Map createMap(TextureMapping p_387972_) { + return Streams.concat(this.requiredSlots.stream(), p_387972_.getForced()).collect(ImmutableMap.toImmutableMap(Function.identity(), p_387972_::get)); ++ } ++ ++ public net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate.Builder extend() { ++ return net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate.Builder.of(this); + } + } diff --git a/patches/net/minecraft/data/models/model/TextureMapping.java.patch b/patches/net/minecraft/client/data/models/model/TextureMapping.java.patch similarity index 55% rename from patches/net/minecraft/data/models/model/TextureMapping.java.patch rename to patches/net/minecraft/client/data/models/model/TextureMapping.java.patch index 60398417da..cccf517138 100644 --- a/patches/net/minecraft/data/models/model/TextureMapping.java.patch +++ b/patches/net/minecraft/client/data/models/model/TextureMapping.java.patch @@ -1,8 +1,8 @@ ---- a/net/minecraft/data/models/model/TextureMapping.java -+++ b/net/minecraft/data/models/model/TextureMapping.java -@@ -401,4 +_,11 @@ - ResourceLocation resourcelocation = BuiltInRegistries.ITEM.getKey(p_125746_); - return resourcelocation.withPath(p_252192_ -> "item/" + p_252192_ + p_125747_); +--- a/net/minecraft/client/data/models/model/TextureMapping.java ++++ b/net/minecraft/client/data/models/model/TextureMapping.java +@@ -412,4 +_,11 @@ + ResourceLocation resourcelocation = BuiltInRegistries.ITEM.getKey(p_386842_); + return resourcelocation.withPath(p_387396_ -> "item/" + p_387396_ + p_386898_); } + + public TextureMapping copy() { diff --git a/patches/net/minecraft/data/models/model/TexturedModel.java.patch b/patches/net/minecraft/client/data/models/model/TexturedModel.java.patch similarity index 62% rename from patches/net/minecraft/data/models/model/TexturedModel.java.patch rename to patches/net/minecraft/client/data/models/model/TexturedModel.java.patch index f0c87c71e9..99fc5c7494 100644 --- a/patches/net/minecraft/data/models/model/TexturedModel.java.patch +++ b/patches/net/minecraft/client/data/models/model/TexturedModel.java.patch @@ -1,20 +1,20 @@ ---- a/net/minecraft/data/models/model/TexturedModel.java -+++ b/net/minecraft/data/models/model/TexturedModel.java -@@ -8,7 +_,7 @@ - import net.minecraft.resources.ResourceLocation; - import net.minecraft.world.level.block.Block; +--- a/net/minecraft/client/data/models/model/TexturedModel.java ++++ b/net/minecraft/client/data/models/model/TexturedModel.java +@@ -9,7 +_,7 @@ + import net.neoforged.api.distmarker.OnlyIn; + @OnlyIn(Dist.CLIENT) -public class TexturedModel { +public class TexturedModel implements net.neoforged.neoforge.common.extensions.ITexturedModelExtension { public static final TexturedModel.Provider CUBE = createDefault(TextureMapping::cube, ModelTemplates.CUBE_ALL); public static final TexturedModel.Provider CUBE_INNER_FACES = createDefault(TextureMapping::cube, ModelTemplates.CUBE_ALL_INNER_FACES); public static final TexturedModel.Provider CUBE_MIRRORED = createDefault(TextureMapping::cube, ModelTemplates.CUBE_MIRRORED_ALL); -@@ -74,7 +_,7 @@ - } +@@ -75,7 +_,7 @@ @FunctionalInterface + @OnlyIn(Dist.CLIENT) - public interface Provider { + public interface Provider extends net.neoforged.neoforge.common.extensions.ITexturedModelExtension.Provider { - TexturedModel get(Block p_125965_); + TexturedModel get(Block p_386689_); - default ResourceLocation create(Block p_125957_, BiConsumer> p_125958_) { + default ResourceLocation create(Block p_388828_, BiConsumer p_386557_) { diff --git a/patches/net/minecraft/data/models/ModelProvider.java.patch b/patches/net/minecraft/data/models/ModelProvider.java.patch deleted file mode 100644 index edb7645dda..0000000000 --- a/patches/net/minecraft/data/models/ModelProvider.java.patch +++ /dev/null @@ -1,66 +0,0 @@ ---- a/net/minecraft/data/models/ModelProvider.java -+++ b/net/minecraft/data/models/ModelProvider.java -@@ -24,13 +_,26 @@ - import net.minecraft.world.item.Item; - import net.minecraft.world.level.block.Block; - --public class ModelProvider implements DataProvider { -+public class ModelProvider implements DataProvider, net.neoforged.neoforge.common.extensions.IModelProviderExtension { - private final PackOutput.PathProvider blockStatePathProvider; - private final PackOutput.PathProvider modelPathProvider; -+ public final String modId; - -+ // NeoForge: Use the above constructor passing in their mod id -+ @Deprecated - public ModelProvider(PackOutput p_252226_) { -+ this(p_252226_, ResourceLocation.DEFAULT_NAMESPACE); -+ } -+ -+ public ModelProvider(PackOutput p_252226_, String modId) { - this.blockStatePathProvider = p_252226_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "blockstates"); - this.modelPathProvider = p_252226_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "models"); -+ this.modId = modId; -+ } -+ -+ protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { -+ blockModels.run(); -+ itemModels.run(); - } - - @Override -@@ -52,19 +_,14 @@ - } - }; - Consumer consumer1 = set::add; -- new BlockModelGenerators(consumer, biconsumer, consumer1).run(); -- new ItemModelGenerators(biconsumer).run(); -- List list = BuiltInRegistries.BLOCK -- .entrySet() -- .stream() -- .filter(p_300706_ -> true) -- .map(Entry::getValue) -+ registerModels(new BlockModelGenerators(consumer, biconsumer, consumer1, this.modId), new ItemModelGenerators(biconsumer, this.modId)); -+ List list = getKnownBlocks() - .filter(p_125117_ -> !map.containsKey(p_125117_)) - .toList(); - if (!list.isEmpty()) { - throw new IllegalStateException("Missing blockstate definitions for: " + list); - } else { -- BuiltInRegistries.BLOCK.forEach(p_125128_ -> { -+ getKnownBlocks().forEach(p_125128_ -> { - Item item = Item.BY_BLOCK.get(p_125128_); - if (item != null) { - if (set.contains(item)) { -@@ -95,5 +_,12 @@ - @Override - public String getName() { - return "Model Definitions"; -+ } -+ -+ protected java.util.stream.Stream getKnownBlocks() { -+ return BuiltInRegistries.BLOCK.entrySet() -+ .stream() -+ .filter(block -> block.getKey().location().getNamespace().equals(modId)) -+ .map(Entry::getValue); - } - } diff --git a/patches/net/minecraft/data/models/model/ModelTemplate.java.patch b/patches/net/minecraft/data/models/model/ModelTemplate.java.patch deleted file mode 100644 index dca77baf2c..0000000000 --- a/patches/net/minecraft/data/models/model/ModelTemplate.java.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/data/models/model/ModelTemplate.java -+++ b/net/minecraft/data/models/model/ModelTemplate.java -@@ -79,4 +_,8 @@ - public interface JsonFactory { - JsonObject create(ResourceLocation p_266987_, Map p_266933_); - } -+ -+ public net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate.Builder extend() { -+ return net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate.Builder.of(this); -+ } - } diff --git a/patches/net/minecraft/data/models/model/ModelTemplates.java.patch b/patches/net/minecraft/data/models/model/ModelTemplates.java.patch deleted file mode 100644 index beb8cf1e52..0000000000 --- a/patches/net/minecraft/data/models/model/ModelTemplates.java.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- a/net/minecraft/data/models/model/ModelTemplates.java -+++ b/net/minecraft/data/models/model/ModelTemplates.java -@@ -195,14 +_,17 @@ - } - - public static ModelTemplate create(String p_125724_, TextureSlot... p_125725_) { -- return new ModelTemplate(Optional.of(ResourceLocation.withDefaultNamespace("block/" + p_125724_)), Optional.empty(), p_125725_); -+ // NeoForge: Support modded paths -+ return new ModelTemplate(Optional.of(ModelLocationUtils.decorateBlockModelLocation(p_125724_)), Optional.empty(), p_125725_); - } - - public static ModelTemplate createItem(String p_125731_, TextureSlot... p_125732_) { -- return new ModelTemplate(Optional.of(ResourceLocation.withDefaultNamespace("item/" + p_125731_)), Optional.empty(), p_125732_); -+ // NeoForge: Use ResourceLocation.parse to support modded paths -+ return new ModelTemplate(Optional.of(ModelLocationUtils.decorateItemModelLocation(p_125731_)), Optional.empty(), p_125732_); - } - - public static ModelTemplate create(String p_125720_, String p_125721_, TextureSlot... p_125722_) { -- return new ModelTemplate(Optional.of(ResourceLocation.withDefaultNamespace("block/" + p_125720_)), Optional.of(p_125721_), p_125722_); -+ // NeoForge: Use ResourceLocation.parse to support modded paths -+ return new ModelTemplate(Optional.of(ModelLocationUtils.decorateBlockModelLocation(p_125720_)), Optional.of(p_125721_), p_125722_); - } - } diff --git a/src/main/java/net/neoforged/neoforge/client/model/generators/CustomLoaderBuilder.java b/src/main/java/net/neoforged/neoforge/client/model/generators/CustomLoaderBuilder.java index 8570879130..865ab5f712 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/generators/CustomLoaderBuilder.java +++ b/src/main/java/net/neoforged/neoforge/client/model/generators/CustomLoaderBuilder.java @@ -11,10 +11,10 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; -import net.minecraft.data.models.model.ModelTemplate; -import net.minecraft.data.models.model.TextureMapping; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.resources.ResourceLocation; -import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; +import net.neoforged.neoforge.client.model.UnbakedModelLoader; public abstract class CustomLoaderBuilder { private static final ResourceLocation DUMMY = ResourceLocation.fromNamespaceAndPath("dummy", "dummy"); @@ -26,7 +26,7 @@ public abstract class CustomLoaderBuilder { private boolean optional = false; /** - * @param loaderId The ID of the associated {@link IGeometryLoader} + * @param loaderId The ID of the associated {@link UnbakedModelLoader} * @param parent The parent {@link ExtendedModelTemplate.Builder} * @param allowInlineElements Whether the loader supports inline vanilla elements and as such can fall back to vanilla loading * with some degradation if the loader does not exist and is marked as optional in the model @@ -90,6 +90,6 @@ public JsonObject toJson(JsonObject json) { } protected static void serializeNestedTemplate(ModelTemplate template, TextureMapping textures, Consumer consumer) { - template.create(DUMMY, textures, (id, jsonSup) -> consumer.accept(jsonSup.get()), template::createBaseTemplate); + template.create(DUMMY, textures, (id, jsonSup) -> consumer.accept(jsonSup.get())); } } diff --git a/src/main/java/net/neoforged/neoforge/client/model/generators/ExtendedModelTemplate.java b/src/main/java/net/neoforged/neoforge/client/model/generators/ExtendedModelTemplate.java index ccb83c21c8..7bace6402a 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/generators/ExtendedModelTemplate.java +++ b/src/main/java/net/neoforged/neoforge/client/model/generators/ExtendedModelTemplate.java @@ -22,6 +22,8 @@ import java.util.function.BiConsumer; import java.util.function.Function; import java.util.stream.Collectors; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TextureSlot; import net.minecraft.client.renderer.block.model.BlockElement; import net.minecraft.client.renderer.block.model.BlockElementFace; import net.minecraft.client.renderer.block.model.BlockElementRotation; @@ -29,8 +31,6 @@ import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.ItemTransform; import net.minecraft.core.Direction; -import net.minecraft.data.models.model.ModelTemplate; -import net.minecraft.data.models.model.TextureSlot; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemDisplayContext; diff --git a/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/CompositeModelBuilder.java b/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/CompositeModelBuilder.java index c9053fd4b8..b3ee1a5d69 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/CompositeModelBuilder.java +++ b/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/CompositeModelBuilder.java @@ -13,8 +13,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import net.minecraft.data.models.model.ModelTemplate; -import net.minecraft.data.models.model.TextureMapping; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.client.model.generators.CustomLoaderBuilder; import net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate; diff --git a/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/SeparateTransformsModelBuilder.java b/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/SeparateTransformsModelBuilder.java index 1f64f0d9e1..7a54ade2f1 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/SeparateTransformsModelBuilder.java +++ b/src/main/java/net/neoforged/neoforge/client/model/generators/loaders/SeparateTransformsModelBuilder.java @@ -9,8 +9,8 @@ import com.google.gson.JsonObject; import java.util.LinkedHashMap; import java.util.Map; -import net.minecraft.data.models.model.ModelTemplate; -import net.minecraft.data.models.model.TextureMapping; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TextureMapping; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemDisplayContext; import net.neoforged.neoforge.client.model.generators.CustomLoaderBuilder; diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IModelProviderExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IModelProviderExtension.java index 11152527b3..f8cd3015a7 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IModelProviderExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IModelProviderExtension.java @@ -5,7 +5,7 @@ package net.neoforged.neoforge.common.extensions; -import net.minecraft.data.models.ModelProvider; +import net.minecraft.client.data.models.ModelProvider; import net.minecraft.resources.ResourceLocation; public interface IModelProviderExtension { diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/ITexturedModelExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/ITexturedModelExtension.java index d174cb400d..dced7de18c 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/ITexturedModelExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/ITexturedModelExtension.java @@ -6,8 +6,8 @@ package net.neoforged.neoforge.common.extensions; import java.util.function.UnaryOperator; -import net.minecraft.data.models.model.ModelTemplate; -import net.minecraft.data.models.model.TexturedModel; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TexturedModel; public interface ITexturedModelExtension { default TexturedModel updateTemplate(UnaryOperator modifier) { diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 5734c2fa21..4d80e5a26f 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -496,24 +496,29 @@ public net.minecraft.world.item.enchantment.Enchantment applyEffects(Ljava/util/ public net.minecraft.client.gui.components.LogoRenderer LOGO_TEXTURE_WIDTH public net.minecraft.client.gui.components.LogoRenderer LOGO_TEXTURE_HEIGHT # Vanilla Data Generators -public net.minecraft.world.item.equipment.EquipmentModels onlyHumanoid(Ljava/lang/String;)Lnet/minecraft/world/item/equipment/EquipmentModel; -public net.minecraft.world.item.equipment.EquipmentModels humanoidAndHorse(Ljava/lang/String;)Lnet/minecraft/world/item/equipment/EquipmentModel; -public net.minecraft.data.models.BlockModelGenerators *() -public net.minecraft.data.models.BlockModelGenerators * -public net.minecraft.data.models.BlockModelGenerators$BlockEntityModelGenerator -public net.minecraft.data.models.BlockModelGenerators$BlockFamilyProvider -public net.minecraft.data.models.BlockModelGenerators$BlockFamilyProvider *() -public net.minecraft.data.models.BlockModelGenerators$BlockStateGeneratorSupplier -public net.minecraft.data.models.BlockModelGenerators$BookSlotModelCacheKey -public net.minecraft.data.models.BlockModelGenerators$BookSlotModelCacheKey (Lnet/minecraft/data/models/model/ModelTemplate;Ljava/lang/String;)V -public net.minecraft.data.models.BlockModelGenerators$TintState -public net.minecraft.data.models.BlockModelGenerators$WoodProvider -public net.minecraft.data.models.ItemModelGenerators *() -public net.minecraft.data.models.ItemModelGenerators * -public net.minecraft.data.models.model.ModelTemplates *() -public net.minecraft.data.models.model.ModelTemplate * -public net.minecraft.data.models.model.TexturedModel (Lnet/minecraft/data/models/model/TextureMapping;Lnet/minecraft/data/models/model/ModelTemplate;)V -public net.minecraft.data.models.model.TexturedModel createDefault(Ljava/util/function/Function;Lnet/minecraft/data/models/model/ModelTemplate;)Lnet/minecraft/data/models/model/TexturedModel$Provider; -public net.minecraft.data.models.model.TextureSlot create(Ljava/lang/String;)Lnet/minecraft/data/models/model/TextureSlot; -public net.minecraft.data.models.model.TextureSlot create(Ljava/lang/String;Lnet/minecraft/data/models/model/TextureSlot;)Lnet/minecraft/data/models/model/TextureSlot; -public-f net.minecraft.data.models.ModelProvider getName()Ljava/lang/String; +public net.minecraft.client.data.models.model.ModelTemplates create([Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/ModelTemplate; +public net.minecraft.client.data.models.model.ModelTemplates create(Ljava/lang/String;[Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/ModelTemplate; +public net.minecraft.client.data.models.model.ModelTemplates create(Ljava/lang/String;Ljava/lang/String;[Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/ModelTemplate; +public net.minecraft.client.data.models.model.ModelTemplates createItem(Ljava/lang/String;[Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/ModelTemplate; +public net.minecraft.client.data.models.model.ModelTemplates createItem(Ljava/lang/String;Ljava/lang/String;[Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/ModelTemplate; +public net.minecraft.client.data.models.model.ModelTemplate * +public net.minecraft.client.data.models.model.TexturedModel createDefault(Ljava/util/function/Function;Lnet/minecraft/client/data/models/model/ModelTemplate;)Lnet/minecraft/client/data/models/model/TexturedModel$Provider; +public net.minecraft.client.data.models.model.TexturedModel (Lnet/minecraft/client/data/models/model/TextureMapping;Lnet/minecraft/client/data/models/model/ModelTemplate;)V +public net.minecraft.client.data.models.model.TextureSlot create(Ljava/lang/String;)Lnet/minecraft/client/data/models/model/TextureSlot; +public net.minecraft.client.data.models.model.TextureSlot create(Ljava/lang/String;Lnet/minecraft/client/data/models/model/TextureSlot;)Lnet/minecraft/client/data/models/model/TextureSlot; +public net.minecraft.client.data.models.EquipmentAssetProvider onlyHumanoid(Ljava/lang/String;)Lnet/minecraft/client/resources/model/EquipmentClientInfo; +public net.minecraft.client.data.models.EquipmentAssetProvider humanoidAndHorse(Ljava/lang/String;)Lnet/minecraft/client/resources/model/EquipmentClientInfo; +public net.minecraft.client.data.models.BlockModelGenerators * +public net.minecraft.client.data.models.BlockModelGenerators *() +public net.minecraft.client.data.models.BlockModelGenerators$BlockFamilyProvider +public net.minecraft.client.data.models.BlockModelGenerators$BlockFamilyProvider *() +public net.minecraft.client.data.models.BlockModelGenerators$BlockStateGeneratorSupplier +public net.minecraft.client.data.models.BlockModelGenerators$BookSlotModelCacheKey +public net.minecraft.client.data.models.BlockModelGenerators$BookSlotModelCacheKey (Lnet/minecraft/client/data/models/model/ModelTemplate;Ljava/lang/String;)V +public net.minecraft.client.data.models.BlockModelGenerators$PlantType +public net.minecraft.client.data.models.BlockModelGenerators$WoodProvider +public net.minecraft.client.data.models.ItemModelGenerators * +public net.minecraft.client.data.models.ItemModelGenerators *() +public net.minecraft.client.data.models.ItemModelGenerators$TrimMaterialData +public net.minecraft.client.data.models.ItemModelGenerators$TrimMaterialData (Ljava/lang/String;Lnet/minecraft/resources/ResourceKey;Ljava/util/Map;)V +public-f net.minecraft.client.data.models.ModelProvider getName()Ljava/lang/String; diff --git a/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java b/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java index d357f6dcd6..1382949cf2 100644 --- a/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java +++ b/testframework/src/main/java/net/neoforged/testframework/impl/reg/RegistrationHelperImpl.java @@ -27,7 +27,6 @@ import net.minecraft.data.PackOutput; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackLocationInfo; import net.minecraft.server.packs.PackSelectionConfig; import net.minecraft.server.packs.PackType; @@ -40,9 +39,6 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.neoforge.attachment.AttachmentType; -import net.neoforged.neoforge.client.model.generators.BlockStateProvider; -import net.neoforged.neoforge.client.model.generators.ItemModelProvider; -import net.neoforged.neoforge.client.model.generators.ModelProvider; import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.common.data.GlobalLootModifierProvider; import net.neoforged.neoforge.common.data.LanguageProvider; @@ -84,19 +80,6 @@ protected void addTranslations() { consumers.forEach(c -> c.accept(this)); } }); - reg.register(BlockStateProvider.class, (output, registries, generator, existingFileHelper, modId, consumers) -> new BlockStateProvider(output, modId, existingFileHelper) { - @Override - protected void registerStatesAndModels() { - existingFileHelper.trackGenerated(ResourceLocation.fromNamespaceAndPath("testframework", "block/white"), ModelProvider.TEXTURE); - consumers.forEach(c -> c.accept(this)); - } - }); - reg.register(ItemModelProvider.class, (output, registries, generator, existingFileHelper, modId, consumers) -> new ItemModelProvider(output, modId, existingFileHelper) { - @Override - protected void registerModels() { - consumers.forEach(c -> c.accept(this)); - } - }); reg.register(GlobalLootModifierProvider.class, (output, registries, generator, existingFileHelper, modId, consumers) -> new GlobalLootModifierProvider(output, registries, modId) { @Override protected void start() { diff --git a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java index 9595db892b..4e21dd35ca 100644 --- a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java +++ b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredBlockBuilder.java @@ -7,9 +7,21 @@ import com.mojang.serialization.MapCodec; import java.util.Objects; +import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.stream.Stream; import net.minecraft.client.color.item.ItemTintSource; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.ModelTemplates; +import net.minecraft.client.data.models.model.TextureMapping; +import net.minecraft.client.data.models.model.TextureSlot; +import net.minecraft.client.data.models.model.TexturedModel; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.LivingEntity; @@ -19,8 +31,7 @@ import net.minecraft.world.level.block.Block; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; -import net.neoforged.neoforge.client.model.generators.BlockModelBuilder; -import net.neoforged.neoforge.client.model.generators.BlockStateProvider; +import net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate; import net.neoforged.neoforge.common.data.LanguageProvider; import net.neoforged.neoforge.registries.DeferredBlock; import org.jetbrains.annotations.Nullable; @@ -55,28 +66,65 @@ public DeferredBlockBuilder withLang(String name) { private boolean hasItem = false; private boolean hasColor = false; + public DeferredBlockBuilder withModel(BiConsumer consumer) { + helper.addClientProvider(client -> new ModelProvider(client.getGenerator().getPackOutput(), helper.modId()) { + @Override + protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { + consumer.accept(value(), blockModels); + } + + @Override + protected Stream> getKnownItems() { + return hasItem ? Stream.of(helper.items().createHolder(Registries.ITEM, key.location())) : Stream.empty(); + } + + @Override + protected Stream> getKnownBlocks() { + return Stream.of(DeferredBlockBuilder.this); + } + + @Override + public String getName() { + return key.location().getPath() + "-model-generator"; + } + }); + return this; + } + + public DeferredBlockBuilder withModel(TexturedModel.Provider model) { + return withModel((block, blockModels) -> blockModels.createTrivialBlock(block, model)); + } + + public DeferredBlockBuilder withModel(TextureMapping textures, Consumer modelConsumer) { + return withModel((block, blockModels) -> { + var builder = ExtendedModelTemplate.builder(); + modelConsumer.accept(builder); + ; + var modelPath = builder.build().create(block, textures, blockModels.modelOutput); + blockModels.blockStateOutput.accept(BlockModelGenerators.createSimpleBlock(block, modelPath)); + }); + } + public DeferredBlockBuilder withDefaultWhiteModel() { - helper.clientProvider(BlockStateProvider.class, prov -> { - final BlockModelBuilder model; + return withModel((block, blockModels) -> { + ModelTemplate template; + if (hasColor) { - model = prov.models().getBuilder(key.location().getPath()) + template = ExtendedModelTemplate.builder() .element() .from(0, 0, 0) .to(16, 16, 16) - .allFaces((direction, faceBuilder) -> faceBuilder.uvs(0, 0, 16, 16).texture("#all").tintindex(0).cullface(direction)) + .allFaces((direction, faceBuilder) -> faceBuilder.uvs(0, 0, 16, 16).texture(TextureSlot.ALL).tintindex(0).cullface(direction)) .end() - .texture("all", ResourceLocation.fromNamespaceAndPath("testframework", "block/white")) - .texture("particle", ResourceLocation.fromNamespaceAndPath("testframework", "block/white")); + .requiredTextureSlot(TextureSlot.ALL) + .build(); } else { - model = prov.models().cubeAll(key.location().getPath(), ResourceLocation.fromNamespaceAndPath("testframework", "block/white")); - } - if (hasItem) { - prov.simpleBlockWithItem(value(), model); - } else { - prov.simpleBlock(value(), model); + template = ModelTemplates.CUBE_ALL; } + + var modelPath = template.create(block, TextureMapping.cube(ResourceLocation.fromNamespaceAndPath("testframework", "block/white")), blockModels.modelOutput); + blockModels.blockStateOutput.accept(BlockModelGenerators.createSimpleBlock(block, modelPath)); }); - return this; } public DeferredBlockBuilder withColor(int color) { diff --git a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java index 4065c74bb7..761d4799ed 100644 --- a/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java +++ b/testframework/src/main/java/net/neoforged/testframework/registration/DeferredItemBuilder.java @@ -5,12 +5,22 @@ package net.neoforged.testframework.registration; +import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.stream.Stream; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; +import net.minecraft.client.data.models.model.ItemModelUtils; +import net.minecraft.client.data.models.model.ModelLocationUtils; +import net.minecraft.client.data.models.model.ModelTemplate; +import net.minecraft.client.data.models.model.TextureMapping; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; -import net.neoforged.neoforge.client.model.generators.ItemModelBuilder; -import net.neoforged.neoforge.client.model.generators.ItemModelProvider; +import net.minecraft.world.level.block.Block; +import net.neoforged.neoforge.client.model.generators.ExtendedModelTemplate; import net.neoforged.neoforge.common.data.LanguageProvider; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import net.neoforged.neoforge.registries.DeferredItem; @@ -37,8 +47,42 @@ public DeferredItemBuilder tab(ResourceKey tab) { return this; } - public DeferredItemBuilder withModel(Consumer modelConsumer) { - registrationHelper.clientProvider(ItemModelProvider.class, prov -> modelConsumer.accept(prov.getBuilder(key.location().toString()))); + public DeferredItemBuilder withModel(BiConsumer consumer) { + registrationHelper.addClientProvider(client -> new ModelProvider(client.getGenerator().getPackOutput(), registrationHelper.modId()) { + @Override + protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { + consumer.accept(value(), itemModels); + } + + @Override + protected Stream> getKnownItems() { + return Stream.of(DeferredItemBuilder.this); + } + + @Override + protected Stream> getKnownBlocks() { + return Stream.empty(); + } + + @Override + public String getName() { + return key.location().getPath() + "-model-generator"; + } + }); return this; } + + public DeferredItemBuilder withModel(ModelTemplate template) { + return withModel((item, itemModels) -> itemModels.generateFlatItem(item, template)); + } + + public DeferredItemBuilder withModel(TextureMapping textures, Consumer modelConsumer) { + return withModel((item, itemModels) -> { + var modelPath = ModelLocationUtils.getModelLocation(item); + var builder = ExtendedModelTemplate.builder(); + modelConsumer.accept(builder); + itemModels.itemModelOutput.accept(item, ItemModelUtils.plainModel(modelPath)); + builder.build().create(item, textures, itemModels.modelOutput); + }); + } } diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java b/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java index 0436124abd..490dd8ae4d 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/VanillaDataGenTest.java @@ -6,16 +6,16 @@ package net.neoforged.neoforge.debug; import java.util.function.BiConsumer; +import net.minecraft.client.data.models.BlockModelGenerators; +import net.minecraft.client.data.models.EquipmentModelProvider; +import net.minecraft.client.data.models.ItemModelGenerators; +import net.minecraft.client.data.models.ModelProvider; +import net.minecraft.client.data.models.model.ModelTemplates; +import net.minecraft.client.data.models.model.TextureMapping; +import net.minecraft.client.data.models.model.TexturedModel; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.ItemTransform; import net.minecraft.core.component.DataComponents; -import net.minecraft.data.models.BlockModelGenerators; -import net.minecraft.data.models.EquipmentModelProvider; -import net.minecraft.data.models.ItemModelGenerators; -import net.minecraft.data.models.ModelProvider; -import net.minecraft.data.models.model.ModelTemplates; -import net.minecraft.data.models.model.TextureMapping; -import net.minecraft.data.models.model.TexturedModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.item.Item; diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java index 08d076e486..11a6d96aa8 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/item/ItemTests.java @@ -17,7 +17,6 @@ import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; import net.minecraft.gametest.framework.GameTest; import net.minecraft.network.chat.Style; -import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; @@ -52,7 +51,6 @@ import net.minecraft.world.level.block.entity.DispenserBlockEntity; import net.minecraft.world.level.material.Fluids; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.neoforge.client.model.generators.ModelFile; import net.neoforged.neoforge.common.Tags; import net.neoforged.testframework.DynamicTest; import net.neoforged.testframework.annotation.ForEachTest; @@ -141,7 +139,8 @@ public InteractionResult use(Level level, Player player, InteractionHand hand) { return sup; } }) - .tab(CreativeModeTabs.SPAWN_EGGS).withModel(builder -> builder.parent(new ModelFile.UncheckedModelFile(ResourceLocation.fromNamespaceAndPath("minecraft", "item/template_spawn_egg")))); + .tab(CreativeModeTabs.SPAWN_EGGS) + .withModel((item, itemModels) -> itemModels.generateSpawnEgg(item, 0xFFFFFF, 0xFFFFFF)); test.onGameTest(helper -> helper.startSequence() .thenExecute(() -> helper.setBlock(1, 1, 1, Blocks.IRON_BLOCK))