|
| 1 | +--- a/net/minecraft/client/data/models/ModelProvider.java |
| 2 | ++++ b/net/minecraft/client/data/models/ModelProvider.java |
| 3 | +@@ -34,20 +_,58 @@ |
| 4 | + private final PackOutput.PathProvider blockStatePathProvider; |
| 5 | + private final PackOutput.PathProvider itemInfoPathProvider; |
| 6 | + private final PackOutput.PathProvider modelPathProvider; |
| 7 | ++ public final String modId; |
| 8 | + |
| 9 | ++ // Neo: Use the constructor which accepts a mod ID. |
| 10 | ++ @Deprecated |
| 11 | + public ModelProvider(PackOutput p_388260_) { |
| 12 | ++ this(p_388260_, ResourceLocation.DEFAULT_NAMESPACE); |
| 13 | ++ } |
| 14 | ++ |
| 15 | ++ public ModelProvider(PackOutput p_388260_, String modId) { |
| 16 | + this.blockStatePathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "blockstates"); |
| 17 | + this.itemInfoPathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "items"); |
| 18 | + this.modelPathProvider = p_388260_.createPathProvider(PackOutput.Target.RESOURCE_PACK, "models"); |
| 19 | ++ this.modId = modId; |
| 20 | ++ } |
| 21 | ++ |
| 22 | ++ protected void registerModels(BlockModelGenerators blockModels, ItemModelGenerators itemModels) { |
| 23 | ++ blockModels.run(); |
| 24 | ++ itemModels.run(); |
| 25 | ++ } |
| 26 | ++ |
| 27 | ++ /** |
| 28 | ++ * Returns a {@link Stream stream} containing all {@link Block blocks} which must have their models/block states generated or {@link Stream#empty() empty} if none are desired. |
| 29 | ++ * <p> |
| 30 | ++ * When using providers for specific {@link Block block} usages, it is best to override this method returning the exact {@link Block blocks} which must be generated, |
| 31 | ++ * or {@link Stream#empty() empty} if generating only {@link Item item} models. |
| 32 | ++ * <p> |
| 33 | ++ * Default implementation generates models for {@link Block blocks} matching the given {@code modId}. |
| 34 | ++ * @see #getKnownItems() |
| 35 | ++ */ |
| 36 | ++ protected Stream<? extends Holder<Block>> getKnownBlocks() { |
| 37 | ++ return BuiltInRegistries.BLOCK.listElements().filter(holder -> holder.getKey().location().getNamespace().equals(modId)); |
| 38 | ++ } |
| 39 | ++ |
| 40 | ++ /** |
| 41 | ++ * Returns a {@link Stream stream} containing all {@link Item items} which must have their models/client items generated or {@link Stream#empty() empty} if none are desired. |
| 42 | ++ * <p> |
| 43 | ++ * When using providers for specific {@link Item item} usages, it is best to override this method returning the exact {@link Item items} which must be generated, |
| 44 | ++ * or {@link Stream#empty() empty} if generating only {@link Block block} models (which have no respective {@link Item item}). |
| 45 | ++ * <p> |
| 46 | ++ * Default implementation generates models for {@link Item items} matching the given {@code modId}. |
| 47 | ++ * @see #getKnownBlocks() |
| 48 | ++ */ |
| 49 | ++ protected Stream<? extends Holder<Item>> getKnownItems() { |
| 50 | ++ return BuiltInRegistries.ITEM.listElements().filter(holder -> holder.getKey().location().getNamespace().equals(modId)); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public CompletableFuture<?> run(CachedOutput p_387857_) { |
| 55 | +- ModelProvider.ItemInfoCollector modelprovider$iteminfocollector = new ModelProvider.ItemInfoCollector(); |
| 56 | +- ModelProvider.BlockStateGeneratorCollector modelprovider$blockstategeneratorcollector = new ModelProvider.BlockStateGeneratorCollector(); |
| 57 | ++ ModelProvider.ItemInfoCollector modelprovider$iteminfocollector = new ModelProvider.ItemInfoCollector(this::getKnownItems); |
| 58 | ++ ModelProvider.BlockStateGeneratorCollector modelprovider$blockstategeneratorcollector = new ModelProvider.BlockStateGeneratorCollector(this::getKnownBlocks); |
| 59 | + ModelProvider.SimpleModelCollector modelprovider$simplemodelcollector = new ModelProvider.SimpleModelCollector(); |
| 60 | +- new BlockModelGenerators(modelprovider$blockstategeneratorcollector, modelprovider$iteminfocollector, modelprovider$simplemodelcollector).run(); |
| 61 | +- new ItemModelGenerators(modelprovider$iteminfocollector, modelprovider$simplemodelcollector).run(); |
| 62 | ++ registerModels(new BlockModelGenerators(modelprovider$blockstategeneratorcollector, modelprovider$iteminfocollector, modelprovider$simplemodelcollector), new ItemModelGenerators(modelprovider$iteminfocollector, modelprovider$simplemodelcollector)); |
| 63 | + modelprovider$blockstategeneratorcollector.validate(); |
| 64 | + modelprovider$iteminfocollector.finalizeAndValidate(); |
| 65 | + return CompletableFuture.allOf( |
| 66 | +@@ -63,12 +_,22 @@ |
| 67 | + |
| 68 | + @Override |
| 69 | + public String getName() { |
| 70 | +- return "Model Definitions"; |
| 71 | ++ return "Model Definitions - " + modId; |
| 72 | + } |
| 73 | + |
| 74 | + @OnlyIn(Dist.CLIENT) |
| 75 | + static class BlockStateGeneratorCollector implements Consumer<BlockStateGenerator> { |
| 76 | + private final Map<Block, BlockStateGenerator> generators = new HashMap<>(); |
| 77 | ++ private final Supplier<Stream<? extends Holder<Block>>> knownBlocks; |
| 78 | ++ |
| 79 | ++ public BlockStateGeneratorCollector(Supplier<Stream<? extends Holder<Block>>> knownBlocks) { |
| 80 | ++ this.knownBlocks = knownBlocks; |
| 81 | ++ } |
| 82 | ++ |
| 83 | ++ @Deprecated // Neo: Provided for vanilla/multi-loader compatibility. Use constructor with Supplier parameter. |
| 84 | ++ public BlockStateGeneratorCollector() { |
| 85 | ++ this(BuiltInRegistries.BLOCK::listElements); |
| 86 | ++ } |
| 87 | + |
| 88 | + public void accept(BlockStateGenerator p_388748_) { |
| 89 | + Block block = p_388748_.getBlock(); |
| 90 | +@@ -79,9 +_,9 @@ |
| 91 | + } |
| 92 | + |
| 93 | + public void validate() { |
| 94 | +- Stream<Holder.Reference<Block>> stream = BuiltInRegistries.BLOCK.listElements().filter(p_388333_ -> true); |
| 95 | ++ Stream<? extends Holder<Block>> stream = knownBlocks.get(); |
| 96 | + List<ResourceLocation> list = stream.filter(p_386843_ -> !this.generators.containsKey(p_386843_.value())) |
| 97 | +- .map(p_386823_ -> p_386823_.key().location()) |
| 98 | ++ .map(p_386823_ -> p_386823_.unwrapKey().orElseThrow().location()) |
| 99 | + .toList(); |
| 100 | + if (!list.isEmpty()) { |
| 101 | + throw new IllegalStateException("Missing blockstate definitions for: " + list); |
| 102 | +@@ -97,6 +_,16 @@ |
| 103 | + static class ItemInfoCollector implements ItemModelOutput { |
| 104 | + private final Map<Item, ClientItem> itemInfos = new HashMap<>(); |
| 105 | + private final Map<Item, Item> copies = new HashMap<>(); |
| 106 | ++ private final Supplier<Stream<? extends Holder<Item>>> knownItems; |
| 107 | ++ |
| 108 | ++ public ItemInfoCollector(Supplier<Stream<? extends Holder<Item>>> knownItems) { |
| 109 | ++ this.knownItems = knownItems; |
| 110 | ++ } |
| 111 | ++ |
| 112 | ++ @Deprecated // Neo: Provided for vanilla/multi-loader compatibility. Use constructor with Supplier parameter. |
| 113 | ++ public ItemInfoCollector() { |
| 114 | ++ this(BuiltInRegistries.ITEM::listElements); |
| 115 | ++ } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void accept(Item p_387063_, ItemModel.Unbaked p_388578_) { |
| 119 | +@@ -116,7 +_,7 @@ |
| 120 | + } |
| 121 | + |
| 122 | + public void finalizeAndValidate() { |
| 123 | +- BuiltInRegistries.ITEM.forEach(p_388426_ -> { |
| 124 | ++ knownItems.get().map(Holder::value).forEach(p_388426_ -> { |
| 125 | + if (!this.copies.containsKey(p_388426_)) { |
| 126 | + if (p_388426_ instanceof BlockItem blockitem && !this.itemInfos.containsKey(blockitem)) { |
| 127 | + ResourceLocation resourcelocation = ModelLocationUtils.getModelLocation(blockitem.getBlock()); |
| 128 | +@@ -132,10 +_,9 @@ |
| 129 | + this.register(p_386494_, clientitem); |
| 130 | + } |
| 131 | + }); |
| 132 | +- List<ResourceLocation> list = BuiltInRegistries.ITEM |
| 133 | +- .listElements() |
| 134 | ++ List<ResourceLocation> list = knownItems.get() |
| 135 | + .filter(p_388636_ -> !this.itemInfos.containsKey(p_388636_.value())) |
| 136 | +- .map(p_388278_ -> p_388278_.key().location()) |
| 137 | ++ .map(p_388278_ -> p_388278_.unwrapKey().orElseThrow().location()) |
| 138 | + .toList(); |
| 139 | + if (!list.isEmpty()) { |
| 140 | + throw new IllegalStateException("Missing item model definitions for: " + list); |
0 commit comments