Skip to content

Commit

Permalink
重构模型资源
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Oct 2, 2024
1 parent 17d4e7d commit ce8b874
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,8 +96,13 @@ public List<ModelDataResource> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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) {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public interface AyameModelType {
ResourceLocation getAnimation();

IndexData.ModelMetaData metaData();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ce8b874

Please sign in to comment.