Skip to content

Commit

Permalink
Add 1.20.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Dec 8, 2023
1 parent dd6e9e8 commit aed5af1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public static Object getNMSEntity(Entity entity) {
*/
public static Object readNBT(InputStream stream) {
try {
return ReflectionMethod.NBTFILE_READ.run(null, stream);
if(MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R3)) {
return ReflectionMethod.NBTFILE_READV2.run(null, stream, ReflectionMethod.NBTACCOUNTER_CREATE_UNLIMITED.run(null));
} else {
return ReflectionMethod.NBTFILE_READ.run(null, stream);
}
} catch (Exception e) {
try {
stream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum MinecraftVersion {
MC1_7_R4(174), MC1_8_R3(183), MC1_9_R1(191), MC1_9_R2(192), MC1_10_R1(1101), MC1_11_R1(1111), MC1_12_R1(1121),
MC1_13_R1(1131), MC1_13_R2(1132), MC1_14_R1(1141), MC1_15_R1(1151), MC1_16_R1(1161), MC1_16_R2(1162),
MC1_16_R3(1163), MC1_17_R1(1171), MC1_18_R1(1181, true), MC1_18_R2(1182, true), MC1_19_R1(1191, true),
MC1_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true), MC1_20_R2(1202, true);
MC1_19_R2(1192, true), MC1_19_R3(1193, true), MC1_20_R1(1201, true), MC1_20_R2(1202, true), MC1_20_R3(1203, true);

private static MinecraftVersion version;
private static Boolean hasGsonSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum ClassWrapper {
"net.minecraft.nbt.NbtUtils"),
NMS_IBLOCKDATA(PackageWrapper.NMS, "IBlockData", MinecraftVersion.MC1_8_R3, null,
"net.minecraft.world.level.block.state", "net.minecraft.world.level.block.state.BlockState"),
NMS_NBTACCOUNTER(PackageWrapper.NMS, "NBTReadLimiter", MinecraftVersion.MC1_20_R3, null, "net.minecraft.nbt", "net.minecraft.nbt.NbtAccounter"),
GAMEPROFILE(PackageWrapper.NONE, "com.mojang.authlib.GameProfile", MinecraftVersion.MC1_8_R3, null);

private Class<?> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,27 @@ public class MojangToMapping {
}

};

@SuppressWarnings("serial")
private static Map<String, String> MC1_20R3 = new HashMap<String, String>() {

{
putAll(MC1_20R2);

put("net.minecraft.nbt.NbtIo#readCompressed(java.io.InputStream,net.minecraft.nbt.NbtAccounter)", "a");
put("net.minecraft.nbt.NbtAccounter#unlimitedHeap()", "a");
put("net.minecraft.world.entity.Entity#getEncodeId()", "bw");
put("net.minecraft.world.level.block.entity.BlockEntity#saveWithId()", "p");
put("net.minecraft.world.level.block.entity.BlockEntity#getBlockState()", "r");
}

};


public static Map<String, String> getMapping() {
switch (MinecraftVersion.getVersion()) {
case MC1_20_R3:
return MC1_20R3;
case MC1_20_R2:
return MC1_20R2;
case MC1_20_R1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,19 @@ MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "e"),
new Since(MinecraftVersion.MC1_14_R1, "getSaveID"), new Since(MinecraftVersion.MC1_18_R1, "getEncodeId()")),

NBTFILE_READ(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS, new Class[] { InputStream.class },
MinecraftVersion.MC1_7_R4, new Since(MinecraftVersion.MC1_7_R4, "a"),
MinecraftVersion.MC1_7_R4, MinecraftVersion.MC1_20_R2, new Since(MinecraftVersion.MC1_7_R4, "a"),
new Since(MinecraftVersion.MC1_18_R1, "readCompressed(java.io.InputStream)")),

NBTFILE_READV2(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS,
new Class[] { InputStream.class, ClassWrapper.NMS_NBTACCOUNTER.getClazz() }, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_20_R3,
"readCompressed(java.io.InputStream,net.minecraft.nbt.NbtAccounter)")),

NBTACCOUNTER_CREATE_UNLIMITED(ClassWrapper.NMS_NBTACCOUNTER,
new Class[] {}, MinecraftVersion.MC1_20_R3,
new Since(MinecraftVersion.MC1_20_R3,
"unlimitedHeap()")),

NBTFILE_WRITE(ClassWrapper.NMS_NBTCOMPRESSEDSTREAMTOOLS,
new Class[] { ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz(), OutputStream.class }, MinecraftVersion.MC1_7_R4,
new Since(MinecraftVersion.MC1_7_R4, "a"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MappingsParser {
public static StringBuilder builder = new StringBuilder();

public static void main(String[] args) throws IOException {
File input = new File("minecraft_server.1.20.2.txt");
File input = new File("minecraft_server.1.20.4.txt");
List<String> lines = Files.readAllLines(input.toPath());

Map<String, ClassWrapper> classes = new HashMap<>();
Expand Down

0 comments on commit aed5af1

Please sign in to comment.