Skip to content

Commit

Permalink
今日的胜负:Neko的败北
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Oct 23, 2024
1 parent 557f01a commit 9a77405
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.ayamemc.ayame.model.DefaultAyameModelType;
import org.ayamemc.ayame.util.FileUtil;
import org.ayamemc.ayame.util.TaskManager;
import org.ayamemc.ayame.util.ZipFileManager;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -55,13 +56,13 @@ public class DefaultAyameModels {
);

public static IModelResource GRMMY_NEKO_MODEL_RESOURCE;
public static AyameModelType TEST_MODEL;
public static AyameModelType GRMMY_NEKO_MODEL;

public static void init() {
TaskManager.TaskManagerImpls.CLIENT_IN_WORLD_TASKS.addTask(() -> {
//TaskManager.TaskManagerImpls.CLIENT_IN_WORLD_TASKS.addTask(() -> {
GRMMY_NEKO_MODEL_RESOURCE = createModelResource("grmmy_neko");
TEST_MODEL = createModel(GRMMY_NEKO_MODEL_RESOURCE);
});
GRMMY_NEKO_MODEL = createModel(GRMMY_NEKO_MODEL_RESOURCE);
//});
}

// TODO: JSON爆null问题在于此处,res.getDefault传入的content内的index.json为null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class AyameModelResource implements IModelResource {
* @param content 模型内容
*/
public AyameModelResource(ZipFileManager content) throws IOException {
if (content == null){
throw new RuntimeException("Model File Content is null");
}
this.content = content;
this.index = createIndexData();
IAyameClientEvents.Instance.INSTANCE.ModelResource_onResourceCreate(this);
Expand All @@ -69,6 +72,9 @@ public String getType() {

public ModelDataResource getDefault() {
try {
if (FileUtil.inputStreamToString(content.readFileContent("index.json")).equalsIgnoreCase("")){
throw new RuntimeException("Model File index is null");
}
return ModelDataResource.Builder.create().getDefaultFromZip(content).build();
} catch (IOException e) {
LOGGER.error("Error when loading default model:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public JsonInterpreter(String jsonString) {
Gson gson = new Gson();
// 将 JSON 字符串转换为 JsonObject
this.jsonObject = gson.fromJson(jsonString, JsonObject.class);
if (jsonObject == null){
throw new RuntimeException("JsonObject is null,the content of it:"+original);
}
}

/**
Expand Down
21 changes: 10 additions & 11 deletions common/src/main/java/org/ayamemc/ayame/util/ZipFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ private void loadZipFile(Path path) {
ZipEntry entry = entries.nextElement();

if (!entry.isDirectory()) { // 忽略目录
try (InputStream is = zipFile.getInputStream(entry)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
InputStream is = zipFile.getInputStream(entry);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;

while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}

// 将内容转换为字节数组输入流并存储在 Map 中
InputStream contentStream = new ByteArrayInputStream(baos.toByteArray());
fileContents.put(entry.getName(), contentStream);
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}

// 将内容转换为字节数组输入流并存储在 Map 中
InputStream contentStream = new ByteArrayInputStream(baos.toByteArray());
fileContents.put(entry.getName(), contentStream);
}
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
*/
@Environment(EnvType.CLIENT)
public final class AyameFabricClient implements ClientModInitializer {
private static KeyMapping keyMapping;

@Override
public void onInitializeClient() {
Expand Down

0 comments on commit 9a77405

Please sign in to comment.