From ce8b874dd17ccafdc69e210318c8654afb1672ba Mon Sep 17 00:00:00 2001 From: crystalneko Date: Wed, 2 Oct 2024 14:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=A8=A1=E5=9E=8B=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/resource/AyameModelResource.java | 11 +++++-- .../resource/ModelResourceWriterUtil.java | 22 +++++--------- .../ayamemc/ayame/model/AyameModelType.java | 1 + .../ayame/model/DefaultAyameModelType.java | 29 +++++++++++++++++++ 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/org/ayamemc/ayame/client/resource/AyameModelResource.java b/common/src/main/java/org/ayamemc/ayame/client/resource/AyameModelResource.java index 493fd69..e98ac45 100644 --- a/common/src/main/java/org/ayamemc/ayame/client/resource/AyameModelResource.java +++ b/common/src/main/java/org/ayamemc/ayame/client/resource/AyameModelResource.java @@ -24,6 +24,8 @@ import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.resources.ResourceLocation; import org.ayamemc.ayame.client.IAyameClientEvents; +import org.ayamemc.ayame.model.AyameModelType; +import org.ayamemc.ayame.model.DefaultAyameModelType; import org.ayamemc.ayame.model.IndexData; import org.ayamemc.ayame.util.JsonInterpreter; import org.ayamemc.ayame.util.ZipFileManager; @@ -94,8 +96,13 @@ public List getPresets() { * @param animation */ public record ModelDataResource(String mainName,String name,JsonInterpreter model, DynamicTexture texture, JsonInterpreter animation){ - public ModelResourceWriterUtil.ModelResourceLocationRecord getOrCreateResource() { - return ModelResourceWriterUtil.addModelResource(this); + /** + * 使用这个metadata 创建一个{@link DefaultAyameModelType} + * @param metaData + * @return + */ + public AyameModelType getOrCreateResource(IndexData.ModelMetaData metaData) { + return ModelResourceWriterUtil.addModelResource(this).setMetaData(metaData).build(); } public ResourceLocation createModelResourceLocation() { diff --git a/common/src/main/java/org/ayamemc/ayame/client/resource/ModelResourceWriterUtil.java b/common/src/main/java/org/ayamemc/ayame/client/resource/ModelResourceWriterUtil.java index c70939f..b3f31ee 100644 --- a/common/src/main/java/org/ayamemc/ayame/client/resource/ModelResourceWriterUtil.java +++ b/common/src/main/java/org/ayamemc/ayame/client/resource/ModelResourceWriterUtil.java @@ -29,6 +29,8 @@ import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; +import org.ayamemc.ayame.model.AyameModelType; +import org.ayamemc.ayame.model.DefaultAyameModelType; import org.jetbrains.annotations.NotNull; import software.bernie.geckolib.cache.GeckoLibCache; import software.bernie.geckolib.cache.object.BakedGeoModel; @@ -53,14 +55,17 @@ public class ModelResourceWriterUtil { /** * @param modelRes 模型资源 - * @return {@link ModelResourceLocationRecord} 模型资源路径和动画路径的记录 + * @return 未完成的模型构建器 */ - public static ModelResourceLocationRecord addModelResource(@NotNull AyameModelResource.ModelDataResource modelRes) { + public static DefaultAyameModelType.Builder addModelResource(@NotNull AyameModelResource.ModelDataResource modelRes) { addBakedModel(modelRes.createModelResourceLocation(), modelRes); addBakedAnimation(modelRes.createAnimationResourceLocation(), modelRes); addTexture(modelRes.createTextureResourceLocation(), modelRes); - return new ModelResourceLocationRecord(modelRes.createModelResourceLocation(),modelRes.createAnimationResourceLocation(), modelRes.createTextureResourceLocation()); + return DefaultAyameModelType.Builder.create() + .setGeoModel(modelRes.createModelResourceLocation()) + .setAnimation(modelRes.createAnimationResourceLocation()) + .setTexture(modelRes.createTextureResourceLocation()); } /** @@ -103,16 +108,5 @@ public static void addBakedAnimation(ResourceLocation resourceLocation, @NotNull public static void addTexture(ResourceLocation resourceLocation, @NotNull AyameModelResource.ModelDataResource modelRes) { Minecraft.getInstance().getTextureManager().register(resourceLocation, modelRes.texture()); } - - /** - * 模型资源路径和动画路径的记录,只是为了方便 - * - * @param modelLocation 模型资源路径 - * @param animationLocation 模型动画路径 - * @param textureLocation 贴图路径 - */ - public record ModelResourceLocationRecord(ResourceLocation modelLocation, ResourceLocation animationLocation, - ResourceLocation textureLocation) { - } } diff --git a/common/src/main/java/org/ayamemc/ayame/model/AyameModelType.java b/common/src/main/java/org/ayamemc/ayame/model/AyameModelType.java index a3c5e4e..8c1ffe7 100644 --- a/common/src/main/java/org/ayamemc/ayame/model/AyameModelType.java +++ b/common/src/main/java/org/ayamemc/ayame/model/AyameModelType.java @@ -39,4 +39,5 @@ public interface AyameModelType { ResourceLocation getAnimation(); IndexData.ModelMetaData metaData(); + } diff --git a/common/src/main/java/org/ayamemc/ayame/model/DefaultAyameModelType.java b/common/src/main/java/org/ayamemc/ayame/model/DefaultAyameModelType.java index 1f4cb87..0bb5d56 100644 --- a/common/src/main/java/org/ayamemc/ayame/model/DefaultAyameModelType.java +++ b/common/src/main/java/org/ayamemc/ayame/model/DefaultAyameModelType.java @@ -40,6 +40,35 @@ public static AyameModelType of(ResourceLocation geoModel, ResourceLocation anim return new DefaultAyameModelType(geoModel, animation, texture, IndexData.ModelMetaData.Builder.create().parseJsonFromResource(metaData).build()); } + public static class Builder { + private ResourceLocation geoModel; + private ResourceLocation animation; + private ResourceLocation texture; + private IndexData.ModelMetaData metaData; + public Builder setGeoModel(ResourceLocation geoModel) { + this.geoModel = geoModel; + return this; + } + public Builder setAnimation(ResourceLocation animation) { + this.animation = animation; + return this; + } + public Builder setTexture(ResourceLocation texture) { + this.texture = texture; + return this; + } + public Builder setMetaData(IndexData.ModelMetaData metaData) { + this.metaData = metaData; + return this; + } + public DefaultAyameModelType build() { + return new DefaultAyameModelType(geoModel, animation, texture, metaData); + } + public static Builder create() { + return new Builder(); + } + } + @Override public ResourceLocation getGeoModel() {