Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.

safer string reader test

authored by

Lera and committed by cassian.cc 46b11422 7e67b824

+63 -2
+1 -1
common/src/main/java/net/lerariemann/infinity/util/core/CommonIO.java
··· 72 72 try { 73 73 if (file.exists()) { 74 74 content = FileUtils.readFileToString(file, StandardCharsets.UTF_8); 75 - NbtCompound c = StringNbtReader.parse(content); 75 + NbtCompound c = SaferStringReader.parse(content); 76 76 c.remove("infinity_version"); 77 77 return c; 78 78 }
+41
common/src/main/java/net/lerariemann/infinity/util/core/SaferStringReader.java
··· 1 + package net.lerariemann.infinity.util.core; 2 + 3 + import com.mojang.brigadier.StringReader; 4 + import com.mojang.brigadier.exceptions.CommandSyntaxException; 5 + import net.minecraft.nbt.NbtCompound; 6 + import net.minecraft.nbt.StringNbtReader; 7 + 8 + public class SaferStringReader extends StringReader { 9 + public SaferStringReader(String string) { 10 + super(string); 11 + } 12 + 13 + public static NbtCompound parse(String string) throws CommandSyntaxException { 14 + SaferStringReader readerInner = new SaferStringReader(string); 15 + StringNbtReader reader = new StringNbtReader(readerInner); 16 + 17 + NbtCompound nbtCompound = reader.parseCompound(); 18 + readerInner.skipWhitespace(); 19 + if (readerInner.canRead()) { 20 + throw StringNbtReader.TRAILING.createWithContext(readerInner); 21 + } else { 22 + return nbtCompound; 23 + } 24 + } 25 + 26 + @Override 27 + public String readStringUntil(char terminator) throws CommandSyntaxException { 28 + StringBuilder result = new StringBuilder(); 29 + 30 + while(this.canRead()) { 31 + char c = this.read(); 32 + if (c == terminator) { 33 + return result.toString(); 34 + } 35 + 36 + result.append(c); 37 + } 38 + 39 + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedEndOfQuote().createWithContext(this); 40 + } 41 + }
+21 -1
common/src/main/resources/config/easter/classic.json
··· 1 1 { 2 - "infinity_version": 2004002, 2 + "infinity_version": 2004005, 3 3 "aliases": "origin", 4 4 "options": { 5 5 "portal_color": 65535, ··· 51 51 "surface_rule": { 52 52 "type": "minecraft:sequence", 53 53 "sequence": [ 54 + { 55 + "type": "minecraft:condition", 56 + "if_true": { 57 + "type": "minecraft:not", 58 + "invert": { 59 + "type": "y_above", 60 + "anchor": { 61 + "absolute": 1 62 + }, 63 + "surface_depth_multiplier": 0, 64 + "add_stone_depth": false 65 + } 66 + }, 67 + "then_run": { 68 + "type": "minecraft:block", 69 + "result_state": { 70 + "Name": "minecraft:lava" 71 + } 72 + } 73 + }, 54 74 { 55 75 "type": "minecraft:condition", 56 76 "if_true": {