-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests model generation still requires updating
- Loading branch information
1 parent
923a4a7
commit 41e1c12
Showing
24 changed files
with
340 additions
and
205 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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); |
20 changes: 10 additions & 10 deletions
20
...odels/model/ModelLocationUtils.java.patch → ...odels/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 |
---|---|---|
@@ -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_) { |
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); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...ta/models/model/TextureMapping.java.patch → ...ta/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
18 changes: 9 additions & 9 deletions
18
...ata/models/model/TexturedModel.java.patch → ...ata/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 |
---|---|---|
@@ -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<ResourceLocation, Supplier<JsonElement>> p_125958_) { | ||
default ResourceLocation create(Block p_388828_, BiConsumer<ResourceLocation, ModelInstance> p_386557_) { |
66 changes: 0 additions & 66 deletions
66
patches/net/minecraft/data/models/ModelProvider.java.patch
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
patches/net/minecraft/data/models/model/ModelTemplate.java.patch
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
patches/net/minecraft/data/models/model/ModelTemplates.java.patch
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.