-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow modders to generate custom EquipentModels using EquipmentModelProvider Expose helpers EquipmentModels Allow modders to use ModelProvider Expose everything from ItemModelGenerators and BlockModelGenerators Support modded paths in ModelLocationUtils Expose more helpers Support modded paths in ModelTemplate.create Fix model provider not filtering for mod specific blocks/items Added test mod to validate ModelProvider and EquipmentModelProvider output Add note to ModelProvider Add missing AT for record constructor Validate model and texture information using ExistingFileHelper Fix typo in parameter name Allow using vanilla texture slots in neos model builders Add custom VariantProperty allowing modders to specify block model builders rather then ResLoc Allow generating custom model files using vanilla model providers Allow setting custom properties onto model templates Allow setting render types for model templates Fix typo with block state model builder generation Allow looking up existing model files Always construct new model template when assigning custom data Merge overloaded methods into vanilla code Add more custom data to model templates Allow setting custom data from TexturedModel Prepend model folders and append namespaces when missing Allow specifying render typed by strings (defaulting to "minecraft" namespace) Add mod and minecraft model path helpers Fix block models generating empty content Support setting item transforms on model templates Fix model being generated into incorrect location Rename serialization methods Reorder constructors and parameters Making them more consistent and the patches easier to read Remove `VariantProperties.MODEL_BUILDER` Cleanup `ModelTemplate.createBaseTemplate` patch Assert existence of existing model files Allow custom render type names when using String overload Make `IModelTemplateExtension.withCustomData` publicly visible Tear out existing file helper Fix incorrect space indentations Fix incorrect space indentations *again* Break all the things Move texture assignment to TextureSlots Formatting Let ModelProvider subclass decide which blocks are relevant Get compiling on 21.4 Tests model generation still requires updating
- Loading branch information
1 parent
2c7c3f2
commit 3d04267
Showing
41 changed files
with
1,337 additions
and
3,029 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
patches/net/minecraft/client/data/models/ModelProvider.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<? extends Holder<Block>> getKnownBlocks() { | ||
+ return BuiltInRegistries.BLOCK.listElements().filter(holder -> holder.getKey().location().getNamespace().equals(modId)); | ||
+ } | ||
+ | ||
+ protected Stream<? extends Holder<Item>> 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<BlockStateGenerator> { | ||
private final Map<Block, BlockStateGenerator> generators = new HashMap<>(); | ||
+ private final Supplier<Stream<? extends Holder<Block>>> knownBlocks; | ||
+ | ||
+ public BlockStateGeneratorCollector(Supplier<Stream<? extends Holder<Block>>> 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<Holder.Reference<Block>> stream = BuiltInRegistries.BLOCK.listElements().filter(p_388333_ -> true); | ||
+ Stream<? extends Holder<Block>> stream = knownBlocks.get(); | ||
List<ResourceLocation> 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<Item, ClientItem> itemInfos = new HashMap<>(); | ||
private final Map<Item, Item> copies = new HashMap<>(); | ||
+ private final Supplier<Stream<? extends Holder<Item>>> knownItems; | ||
+ | ||
+ public ItemInfoCollector(Supplier<Stream<? extends Holder<Item>>> 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<ResourceLocation> list = BuiltInRegistries.ITEM | ||
- .listElements() | ||
+ List<ResourceLocation> 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); |
18 changes: 18 additions & 0 deletions
18
patches/net/minecraft/client/data/models/model/ModelLocationUtils.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- 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_388520_) { | ||
- return ResourceLocation.withDefaultNamespace("block/" + p_388520_); | ||
+ // NeoForge: Use ResourceLocation.parse to support modded paths | ||
+ return ResourceLocation.parse(p_388520_).withPrefix("block/"); | ||
} | ||
|
||
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_387226_).withPrefix("item/"); | ||
} | ||
|
||
public static ResourceLocation getModelLocation(Block p_387758_, String p_388221_) { |
41 changes: 41 additions & 0 deletions
41
patches/net/minecraft/client/data/models/model/ModelTemplate.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ResourceLocation, ModelInstance> p_387748_) { | ||
Map<TextureSlot, ResourceLocation> 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<TextureSlot, ResourceLocation> 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<TextureSlot, ResourceLocation> 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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
patches/net/minecraft/client/data/models/model/TextureMapping.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- 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() { | ||
+ TextureMapping texturemapping = new TextureMapping(); | ||
+ texturemapping.slots.putAll(this.slots); | ||
+ texturemapping.forcedSlots.addAll(this.forcedSlots); | ||
+ return texturemapping; | ||
+ } | ||
} |
20 changes: 20 additions & 0 deletions
20
patches/net/minecraft/client/data/models/model/TexturedModel.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- 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); | ||
@@ -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_386689_); | ||
|
||
default ResourceLocation create(Block p_388828_, BiConsumer<ResourceLocation, ModelInstance> p_386557_) { |
29 changes: 0 additions & 29 deletions
29
src/main/java/net/neoforged/neoforge/client/model/generators/BlockModelBuilder.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/main/java/net/neoforged/neoforge/client/model/generators/BlockModelProvider.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.