Skip to content

Commit

Permalink
修添加SimpleModelResourcep
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Nov 10, 2024
1 parent d6c2502 commit cc5bc48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
public record DefaultAyameModelType(ResourceLocation geoModel, ResourceLocation animation, ResourceLocation texture,
IndexData.ModelMetaData metaData) implements AyameModelType {

public static AyameModelType of(ResourceLocation geoModel, ResourceLocation animation, ResourceLocation texture, ResourceLocation metaData) {
return new DefaultAyameModelType(geoModel, animation, texture, IndexData.ModelMetaData.Builder.create().parseJsonFromResource(metaData).build());
}

@Override
public ResourceLocation getGeoModel() {
Expand Down
23 changes: 15 additions & 8 deletions common/src/main/java/org/ayamemc/ayame/model/DefaultModels.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,26 @@
import org.ayamemc.ayame.util.FileUtil;

import java.nio.file.Path;
import java.util.List;

import static org.ayamemc.ayame.util.ResourceLocationHelper.withAyameNamespace;

public class DefaultModels {
public static final String MODEL_PATH = "config/ayame/models/";
public static final AyameModelType DEFAULT_MODEL = DefaultAyameModelType.of(
withAyameNamespace("geo/ayame/default"),
withAyameNamespace("animations/ayame/default"),
withAyameNamespace("textures/ayame/default"),
withAyameNamespace("metadata/ayame/default")
);

public static final IModelResource AQUARTER_NEKO_RESOURCE = create("aquarter_neko");
public static final AyameModelType DEFAULT_MODEL = DefaultAyameModelType.Builder.create()
.setGeoModel(withAyameNamespace("geo/ayame/default"))
.setAnimation(withAyameNamespace("animations/ayame/default"))
.setTexture(withAyameNamespace("textures/ayame/default"))
.setMetaData(IndexData.ModelMetaData.Builder.create()
.setName("default")
.setAuthors(new String[]{"CrystalNeko"})
.setDescription("Default model for Ayame")
.setVersion("0.0.1")
.build()
)
.build();

public static final IModelResource AQUARTER_NEKO_RESOURCE = create("AQuarter_neko");

// 静态初始化
public static void init(){}
Expand Down
11 changes: 2 additions & 9 deletions common/src/main/java/org/ayamemc/ayame/model/IndexData.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ModelData build() {
*/
public record ModelMetaData(@NotNull String format,@NotNull String[] authors, @NotNull String name, @Nullable String description,
@Nullable String license, @Nullable String[] links, @Nullable String[] tags,
@NotNull String type, @NotNull String version, @Nullable String[] animations) {
@NotNull String version, @Nullable String[] animations) {


public JsonInterpreter conversion() {
Expand All @@ -177,7 +177,6 @@ public JsonInterpreter conversion() {
json.set("license", license);
json.set("links", links);
json.set("tags", tags);
json.set("type", type);
json.set("version", version);
json.set("animations", animations);
return json;
Expand All @@ -191,7 +190,6 @@ public static class Builder {
private String license = "Unknown";
private String[] links = new String[]{};
private String[] tags = new String[]{};
private String type = "ayame";
private String version = "1.0.0";
private String[] animations = new String[]{};

Expand Down Expand Up @@ -233,10 +231,6 @@ public Builder setTags(String[] tags) {
return this;
}

public Builder setType(String type) {
this.type = type;
return this;
}

public Builder setVersion(String version) {
this.version = version;
Expand All @@ -251,7 +245,6 @@ public Builder setAnimations(String[] animations) {
public Builder parseJson(JsonInterpreter json) {
return this.setName(json.getString("name"))
.setFormat(json.getString("format"))
.setType(type)
.setAuthors(json.getStringList("authors").toArray(new String[0]))
.setDescription(json.getString("description"))
.setLinks(json.getStringList("links").toArray(new String[0]))
Expand All @@ -265,7 +258,7 @@ public Builder parseJsonFromResource(ResourceLocation resourceLocation) {
}

public ModelMetaData build() {
return new ModelMetaData(format,authors, name, description, license, links, tags, type, version, animations);
return new ModelMetaData(format,authors, name, description, license, links, tags, version, animations);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public ModelContent(DirectoryValidator validator) {
@Nullable
@Override
public ModelResourceRegistry.ModelFile createZipPack(Path path) {
try (ZipFile zipFile = new ZipFile(path.toFile())) {
ZipEntry entry = zipFile.getEntry("index.json");
if (entry != null) {
return new ModelResourceRegistry.ModelFile(zipFile);
}
ZipFile zipFile = null;
try {
zipFile = new ZipFile(path.toFile());
} catch (IOException e) {
Ayame.LOGGER.error("Failed to read ZIP pack at path: {}", path, e);
throw new RuntimeException(e);
}
ZipEntry entry = zipFile.getEntry("index.json");
if (entry != null) {
return new ModelResourceRegistry.ModelFile(zipFile);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"ayame-fabric.mixins.json"
],
"depends": {
"fabricloader": ">=0.16.9",
"fabricloader": "*",
"minecraft": ">=1.21 <=1.21.1",
"java": ">=21",
"fabric-api": "*",
Expand Down

0 comments on commit cc5bc48

Please sign in to comment.