Skip to content

Commit

Permalink
Get compiling on 21.4
Browse files Browse the repository at this point in the history
Tests model generation still requires updating
  • Loading branch information
ApexModder committed Dec 3, 2024
1 parent 923a4a7 commit 41e1c12
Show file tree
Hide file tree
Showing 24 changed files with 340 additions and 205 deletions.
115 changes: 115 additions & 0 deletions patches/net/minecraft/client/data/models/ModelProvider.java.patch
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);
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_) {
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);
}
}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
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 patches/net/minecraft/data/models/ModelProvider.java.patch

This file was deleted.

11 changes: 0 additions & 11 deletions patches/net/minecraft/data/models/model/ModelTemplate.java.patch

This file was deleted.

23 changes: 0 additions & 23 deletions patches/net/minecraft/data/models/model/ModelTemplates.java.patch

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -90,6 +90,6 @@ public JsonObject toJson(JsonObject json) {
}

protected static void serializeNestedTemplate(ModelTemplate template, TextureMapping textures, Consumer<JsonElement> consumer) {
template.create(DUMMY, textures, (id, jsonSup) -> consumer.accept(jsonSup.get()), template::createBaseTemplate);
template.create(DUMMY, textures, (id, jsonSup) -> consumer.accept(jsonSup.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
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;
import net.minecraft.client.renderer.block.model.BlockFaceUV;
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;
Expand Down
Loading

0 comments on commit 41e1c12

Please sign in to comment.