Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 9cb2d00

Browse files
committed
fix: crash on startup due to Vault (#87)
1 parent 7dcae07 commit 9cb2d00

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

common/src/main/java/com/github/franckyi/ibeeditor/client/Vault.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.github.franckyi.ibeeditor.client;
22

33
import com.github.franckyi.ibeeditor.PlatformUtil;
4+
import io.netty.buffer.ByteBufInputStream;
45
import io.netty.buffer.Unpooled;
5-
import net.minecraft.nbt.CompoundTag;
6+
import net.minecraft.nbt.*;
67
import net.minecraft.network.FriendlyByteBuf;
78
import org.apache.logging.log4j.LogManager;
89
import org.apache.logging.log4j.Logger;
@@ -88,14 +89,36 @@ private static void loadFromFile(Path path) {
8889
try (var is = Files.newInputStream(path)) {
8990
buffer.writeBytes(is, is.available());
9091
INSTANCE.version = buffer.readInt();
91-
IntStream.range(0, buffer.readInt()).forEach(i -> INSTANCE.items.add(buffer.readNbt()));
92-
IntStream.range(0, buffer.readInt()).forEach(i -> INSTANCE.entities.add(buffer.readNbt()));
92+
IntStream.range(0, buffer.readInt()).forEach(i -> INSTANCE.items.add(safeReadNbt()));
93+
IntStream.range(0, buffer.readInt()).forEach(i -> INSTANCE.entities.add(safeReadNbt()));
9394
LOGGER.info("Vault loaded");
9495
} catch (IOException e) {
9596
LOGGER.error("Error while loading vault", e);
9697
}
9798
}
9899

100+
private static CompoundTag safeReadNbt() {
101+
var i = buffer.readerIndex();
102+
try {
103+
var result = buffer.readNbt();
104+
if (result == null || result.isEmpty()) throw new RuntimeException("Tag is empty, this must be an error");
105+
return result;
106+
} catch (Exception e) {
107+
buffer.readerIndex(i);
108+
byte b0 = buffer.readByte();
109+
if (b0 != Tag.TAG_COMPOUND) {
110+
throw e;
111+
} else {
112+
buffer.readerIndex(i);
113+
try {
114+
return NbtIo.read(new ByteBufInputStream(buffer));
115+
} catch (IOException e0) {
116+
throw new RuntimeException(e0);
117+
}
118+
}
119+
}
120+
}
121+
99122
public static void save() {
100123
try (var os = Files.newOutputStream(VAULT_FILE)) {
101124
buffer.writeInt(INSTANCE.version);

forge_update.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"1.20-recommended": "2.2.3",
66
"1.20.1-latest": "2.2.3",
77
"1.20.1-recommended": "2.2.3",
8-
"1.20.2-latest": "2.2.4",
9-
"1.20.2-recommended": "2.2.4"
8+
"1.20.2-latest": "2.2.5",
9+
"1.20.2-recommended": "2.2.5"
1010
}
1111
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ org.gradle.daemon=false
44
# IBE Editor
55
minecraft_version=1.20.2
66
archives_base_name=IBEEditor
7-
mod_version=2.2.4
7+
mod_version=2.2.5
88
maven_group=com.github.franckyi.ibeeditor
99
# Fabric https://fabricmc.net/develop/
1010
fabric_loader_version=0.14.24

versions.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2+
"2.2.5": {
3+
"type": "release",
4+
"changelog": "* fix: crash on startup due to Vault (#87)"
5+
},
26
"2.2.4": {
37
"type": "release",
4-
"changelog": "* feat: 1.20.2 update (#86)\n* fix(forge): make mod optional for client (#84)"
8+
"changelog": "* feat: 1.20.2 update (#86)\n* fix(forge): make mod optional for client (#84)\n* fix: allow the block editor to be opened when the mod isn't installed on the server (#85)"
59
},
610
"2.2.3": {
711
"type": "release",

0 commit comments

Comments
 (0)