Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype of dispatched UnbakedModel serializers #1557

Draft
wants to merge 2 commits into
base: 1.21.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/client/renderer/block/model/BlockElementFace.java
+++ b/net/minecraft/client/renderer/block/model/BlockElementFace.java
@@ -13,9 +_,23 @@
@@ -13,9 +_,29 @@
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
Expand All @@ -12,6 +12,12 @@
+ this(p_111359_, p_111360_, p_111361_, p_111362_, null, new org.apache.commons.lang3.mutable.MutableObject<>());
+ }
+
+ @org.jetbrains.annotations.ApiStatus.Internal
+ @Nullable
+ public net.neoforged.neoforge.client.model.ExtraFaceData getFaceData() {
+ return this.faceData;
+ }
+
+ @Override
+ public net.neoforged.neoforge.client.model.ExtraFaceData faceData() {
+ if(this.faceData != null) {
Expand Down
174 changes: 150 additions & 24 deletions patches/net/minecraft/client/renderer/block/model/BlockModel.java.patch
Original file line number Diff line number Diff line change
@@ -1,33 +1,117 @@
--- a/net/minecraft/client/renderer/block/model/BlockModel.java
+++ b/net/minecraft/client/renderer/block/model/BlockModel.java
@@ -77,9 +_,10 @@
public BlockModel parent;
@@ -47,7 +_,8 @@
import org.slf4j.Logger;

@OnlyIn(Dist.CLIENT)
-public class BlockModel implements UnbakedModel {
+public class BlockModel implements UnbakedModel, net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel
+{
private static final Logger LOGGER = LogUtils.getLogger();
private static final FaceBakery FACE_BAKERY = new FaceBakery();
@VisibleForTesting
@@ -74,12 +_,12 @@
@VisibleForTesting
public final Map<String, Either<Material, String>> textureMap;
@Nullable
- public BlockModel parent;
+ public net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel parent;
@Nullable
protected ResourceLocation parentLocation;
+ public final net.neoforged.neoforge.client.model.geometry.BlockGeometryBakingContext customData = new net.neoforged.neoforge.client.model.geometry.BlockGeometryBakingContext(this);

public static BlockModel fromStream(Reader p_111462_) {
- return GsonHelper.fromJson(GSON, p_111462_, BlockModel.class);
+ return GsonHelper.fromJson(net.neoforged.neoforge.client.model.ExtendedBlockModelDeserializer.INSTANCE, p_111462_, BlockModel.class);
}

public static BlockModel fromString(String p_111464_) {
@@ -104,10 +_,15 @@
@@ -104,15 +_,69 @@
this.overrides = p_273099_;
}

+ @Override
+ public com.mojang.serialization.MapCodec<? extends net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel> codec() {
+ return net.neoforged.neoforge.client.resource.model.ModelCodecs.BLOCK_MODEL;
+ }
+
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public Map<String, Either<Material, String>> getOwnTextureMap() {
+ return this.textureMap;
+ }
+
+ @Override
+ public Boolean getOwnAmbientOcclusion() {
+ return this.hasAmbientOcclusion;
+ }
+
+ @Override
+ public BlockModel.GuiLight getOwnGuiLight() {
+ return this.guiLight;
+ }
+
+ @Override
+ public ItemTransforms getOwnTransforms() {
+ return this.transforms;
+ }
+
+ @Override
+ public List<ItemOverride> getOwnOverrides() {
+ return this.overrides;
+ }
+
+ @Deprecated
public List<BlockElement> getElements() {
+ if (customData.hasCustomGeometry()) return java.util.Collections.emptyList();
return this.elements.isEmpty() && this.parent != null ? this.parent.getElements() : this.elements;
}
- return this.elements.isEmpty() && this.parent != null ? this.parent.getElements() : this.elements;
+ return this.elements.isEmpty() && this.parent instanceof BlockModel blockModel ? blockModel.getElements() : this.elements;
+ }
+
+ @Nullable
+ public ResourceLocation getParentLocation() { return parentLocation; }
+
+ @Override
+ public void setParentLocation(@Nullable ResourceLocation parentLocation) {
+ this.parentLocation = parentLocation;
}

public boolean hasAmbientOcclusion() {
if (this.hasAmbientOcclusion != null) {
return this.hasAmbientOcclusion;
} else {
- return this.parent != null ? this.parent.hasAmbientOcclusion() : true;
+ return this.parent instanceof BlockModel blockModel ? blockModel.hasAmbientOcclusion() : true;
}
}

@@ -120,12 +_,12 @@
if (this.guiLight != null) {
return this.guiLight;
} else {
- return this.parent != null ? this.parent.getGuiLight() : BlockModel.GuiLight.SIDE;
+ return this.parent instanceof BlockModel blockModel ? blockModel.getGuiLight() : BlockModel.GuiLight.SIDE;
}
}

public boolean isResolved() {
- return this.parentLocation == null || this.parent != null && this.parent.isResolved();
+ return net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel.super.isResolved();
}

public List<ItemOverride> getOverrides() {
@@ -136,6 +_,10 @@
return this.overrides.isEmpty() ? ItemOverrides.EMPTY : new ItemOverrides(p_250138_, p_251800_, this.overrides);
}
Expand All @@ -39,31 +123,68 @@
@Override
public Collection<ResourceLocation> getDependencies() {
Set<ResourceLocation> set = Sets.newHashSet();
@@ -184,6 +_,10 @@
blockmodel.parent = (BlockModel)unbakedmodel;
@@ -155,9 +_,9 @@
public void resolveParents(Function<ResourceLocation, UnbakedModel> p_249059_) {
Set<UnbakedModel> set = Sets.newLinkedHashSet();

- for (BlockModel blockmodel = this; blockmodel.parentLocation != null && blockmodel.parent == null; blockmodel = blockmodel.parent) {
+ for (net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel blockmodel = this; blockmodel.getParentLocation() != null && blockmodel.getParent() == null; blockmodel = blockmodel.getParent()) {
set.add(blockmodel);
- UnbakedModel unbakedmodel = p_249059_.apply(blockmodel.parentLocation);
+ UnbakedModel unbakedmodel = p_249059_.apply(blockmodel.getParentLocation());
if (unbakedmodel == null) {
LOGGER.warn("No parent '{}' while loading model '{}'", this.parentLocation, blockmodel);
}
@@ -173,15 +_,15 @@
}

if (unbakedmodel == null) {
- blockmodel.parentLocation = ModelBakery.MISSING_MODEL_LOCATION;
- unbakedmodel = p_249059_.apply(blockmodel.parentLocation);
+ blockmodel.setParentLocation(ModelBakery.MISSING_MODEL_LOCATION);
+ unbakedmodel = p_249059_.apply(blockmodel.getParentLocation());
}

- if (!(unbakedmodel instanceof BlockModel)) {
+ if (!(unbakedmodel instanceof net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel)) {
throw new IllegalStateException("BlockModel parent has to be a block model.");
}

- blockmodel.parent = (BlockModel)unbakedmodel;
+ blockmodel.setParent((net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel)unbakedmodel);
}

+ if (customData.hasCustomGeometry()) {
+ customData.getCustomGeometry().resolveParents(p_249059_, customData);
+ }
+
this.overrides.forEach(p_247932_ -> {
UnbakedModel unbakedmodel1 = p_249059_.apply(p_247932_.getModel());
if (!Objects.equals(unbakedmodel1, this)) {
@@ -198,6 +_,12 @@
@@ -198,7 +_,7 @@
}

public BakedModel bake(
- ModelBaker p_249720_, BlockModel p_111451_, Function<Material, TextureAtlasSprite> p_111452_, ModelState p_111453_, boolean p_111455_
+ ModelBaker p_249720_, BlockModel p_111451_, Function<Material, TextureAtlasSprite> p_111452_, ModelState p_111453_, boolean p_111455_
+ ) {
+ return net.neoforged.neoforge.client.model.geometry.UnbakedGeometryHelper.bake(this, p_249720_, p_111451_, p_111452_, p_111453_, p_111455_);
+ }
+
+ public BakedModel bakeVanilla(
ModelBaker p_249720_, BlockModel p_111451_, Function<Material, TextureAtlasSprite> p_111452_, ModelState p_111453_, boolean p_111455_
) {
TextureAtlasSprite textureatlassprite = p_111452_.apply(this.getMaterial("particle"));
@@ -288,7 +_,18 @@
if (this.getRootModel() == ModelBakery.BLOCK_ENTITY_MARKER) {
@@ -261,8 +_,8 @@
}

private Either<Material, String> findTextureEntry(String p_111486_) {
- for (BlockModel blockmodel = this; blockmodel != null; blockmodel = blockmodel.parent) {
- Either<Material, String> either = blockmodel.textureMap.get(p_111486_);
+ for (net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel blockmodel = this; blockmodel != null; blockmodel = blockmodel.getParent()) {
+ Either<Material, String> either = blockmodel.getOwnTextureMap().get(p_111486_);
if (either != null) {
return either;
}
@@ -276,7 +_,7 @@
}

public BlockModel getRootModel() {
- return this.parent == null ? this : this.parent.getRootModel();
+ return this.parent instanceof BlockModel blockModel ? blockModel.getRootModel() : this;
}

public ItemTransforms getTransforms() {
@@ -288,11 +_,22 @@
ItemTransform itemtransform5 = this.getTransform(ItemDisplayContext.GUI);
ItemTransform itemtransform6 = this.getTransform(ItemDisplayContext.GROUND);
ItemTransform itemtransform7 = this.getTransform(ItemDisplayContext.FIXED);
Expand All @@ -83,6 +204,11 @@
}

private ItemTransform getTransform(ItemDisplayContext p_270662_) {
- return this.parent != null && !this.transforms.hasTransform(p_270662_) ? this.parent.getTransform(p_270662_) : this.transforms.getTransform(p_270662_);
+ return this.parent instanceof BlockModel blockModel && !this.transforms.hasTransform(p_270662_) ? blockModel.getTransform(p_270662_) : this.transforms.getTransform(p_270662_);
}

@Override
@@ -407,6 +_,8 @@
public boolean lightLikeBlock() {
return this == SIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
map.put("particle", p_111672_.hasTexture("particle") ? Either.left(p_111672_.getMaterial("particle")) : map.get("layer0"));
BlockModel blockmodel = new BlockModel(null, list, map, false, p_111672_.getGuiLight(), p_111672_.getTransforms(), p_111672_.getOverrides());
blockmodel.name = p_111672_.name;
+ blockmodel.customData.copyFrom(p_111672_.customData);
+ blockmodel.customData.setGui3d(false);
+ //blockmodel.customData.copyFrom(p_111672_.customData);
+ //blockmodel.customData.setGui3d(false);
return blockmodel;
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
--- a/net/minecraft/client/resources/model/ModelBakery.java
+++ b/net/minecraft/client/resources/model/ModelBakery.java
@@ -77,7 +_,7 @@
BlockModel.fromString("{\"gui_light\": \"side\"}"), p_119297_ -> p_119297_.name = "block entity marker"
);
static final ItemModelGenerator ITEM_MODEL_GENERATOR = new ItemModelGenerator();
- private final Map<ResourceLocation, BlockModel> modelResources;
+ private final Map<ResourceLocation, net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel> modelResources;
private final Set<ResourceLocation> loadingStack = new HashSet<>();
private final Map<ResourceLocation, UnbakedModel> unbakedCache = new HashMap<>();
final Map<ModelBakery.BakedCacheKey, BakedModel> bakedCache = new HashMap<>();
@@ -89,14 +_,14 @@
public ModelBakery(
BlockColors p_249183_,
ProfilerFiller p_252014_,
- Map<ResourceLocation, BlockModel> p_251087_,
+ Map<ResourceLocation, net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel> p_251087_,
Map<ResourceLocation, List<BlockStateModelLoader.LoadedJson>> p_250416_
) {
this.modelResources = p_251087_;
p_252014_.push("missing_model");

try {
- this.missingModel = this.loadBlockModel(MISSING_MODEL_LOCATION);
+ this.missingModel = this.loadUnbakedModel(MISSING_MODEL_LOCATION);
this.registerModel(MISSING_MODEL_VARIANT, this.missingModel);
} catch (IOException ioexception) {
LOGGER.error("Error loading missing model, should never happen :(", (Throwable)ioexception);
@@ -117,6 +_,12 @@
p_252014_.popPush("special");
this.loadSpecialItemModelAndDependencies(ItemRenderer.TRIDENT_IN_HAND_MODEL);
Expand All @@ -13,6 +39,48 @@
this.topLevelModels.values().forEach(p_247954_ -> p_247954_.resolveParents(this::getModel));
p_252014_.pop();
}
@@ -150,7 +_,7 @@

try {
if (!this.unbakedCache.containsKey(resourcelocation)) {
- UnbakedModel unbakedmodel = this.loadBlockModel(resourcelocation);
+ UnbakedModel unbakedmodel = this.loadUnbakedModel(resourcelocation);
this.unbakedCache.put(resourcelocation, unbakedmodel);
this.loadingStack.addAll(unbakedmodel.getDependencies());
}
@@ -192,6 +_,10 @@
}

private BlockModel loadBlockModel(ResourceLocation p_119365_) throws IOException {
+ return (BlockModel)loadUnbakedModel(p_119365_);
+ }
+
+ private UnbakedModel loadUnbakedModel(ResourceLocation p_119365_) throws IOException {
String s = p_119365_.getPath();
if ("builtin/generated".equals(s)) {
return GENERATION_MARKER;
@@ -204,17 +_,17 @@
throw new FileNotFoundException(p_119365_.toString());
} else {
Reader reader = new StringReader(s2);
- BlockModel blockmodel1 = BlockModel.fromStream(reader);
- blockmodel1.name = p_119365_.toString();
+ net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel blockmodel1 = net.neoforged.neoforge.client.resource.model.ModelManagerHooks.loadUnbakedModel(com.mojang.serialization.JsonOps.INSTANCE, reader);
+ blockmodel1.setName(p_119365_.toString());
return blockmodel1;
}
} else {
ResourceLocation resourcelocation = MODEL_LISTER.idToFile(p_119365_);
- BlockModel blockmodel = this.modelResources.get(resourcelocation);
+ net.neoforged.neoforge.client.resource.model.TopLevelUnbakedModel blockmodel = this.modelResources.get(resourcelocation);
if (blockmodel == null) {
throw new FileNotFoundException(resourcelocation.toString());
} else {
- blockmodel.name = p_119365_.toString();
+ blockmodel.setName(p_119365_.toString());
return blockmodel;
}
}
@@ -246,14 +_,30 @@
}

Expand Down
Loading
Loading