Serialize Json manually because... javax is apparently inaccessible in minecraft's classpath

This commit is contained in:
Tara 2023-01-22 13:17:05 -07:00
parent 41c98e8c3d
commit 65b3fc3e6d
4 changed files with 33 additions and 26 deletions

View file

@ -5,5 +5,5 @@ org.gradle.daemon=false
mc_version=1.19.2 mc_version=1.19.2
forge_version=43.2.3 forge_version=43.2.3
myversion=1.0.3.6 myversion=1.0.3.7
parchment_version=2022.11.27 parchment_version=2022.11.27

View file

@ -4,10 +4,6 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObjectBuilder;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
@ -37,15 +33,22 @@ public class ExtraLore {
// This json object is what goes inside the actual item lore. This is not the entry used to save the state // This json object is what goes inside the actual item lore. This is not the entry used to save the state
public String saveJson(){ public String saveJson(){
String ret = ""; String ret = "{";
JsonObjectBuilder loreEntry = Json.createObjectBuilder(); Iterator<LoreEntry> loreEntries = LoreData.iterator();
JsonArrayBuilder jab = Json.createArrayBuilder(); ret += "\"extra\": [";
for (LoreEntry loreEntryx : LoreData) { while(loreEntries.hasNext())
jab.add(loreEntryx.saveJson()); {
LoreEntry loreEntryx = loreEntries.next();
ret += loreEntryx.saveJson();
if(loreEntries.hasNext())
{
ret += ",";
}
} }
loreEntry.add("extra", jab); ret += "],";
loreEntry.add("text", ""); ret += "\"text\": \"\"";
ret=loreEntry.build().toString(); ret += "}";
return ret; return ret;
} }

View file

@ -1,8 +1,5 @@
package dev.zontreck.libzontreck.items.lore; package dev.zontreck.libzontreck.items.lore;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
@ -41,18 +38,25 @@ public class LoreEntry
parentTag.add(tag); parentTag.add(tag);
} }
private String bool2str(boolean a){
if(a)return "true";
else return "false";
}
// Only json saving is available. // Only json saving is available.
// The NBT Variant should be saved to the mod's custom tag container due to the way lore must be formatted // The NBT Variant should be saved to the mod's custom tag container due to the way lore must be formatted
public JsonObjectBuilder saveJson() public String saveJson()
{ {
JsonObjectBuilder obj = Json.createObjectBuilder();
obj.add("bold", bold); String obj = "{";
obj.add("italic", italic); obj += "\"bold\": " + bool2str(bold)+",";
obj.add("underlined", underlined); obj += "\"italic\": " + bool2str(italic)+",";
obj.add("strikethrough", strikethrough); obj += "\"underlined\": "+bool2str(underlined)+",";
obj.add("obfuscated", obfuscated); obj += "\"strikethrough\": "+bool2str(strikethrough)+",";
obj.add("color", color); obj += "\"obfuscated\": "+bool2str(obfuscated)+",";
obj.add("text", text); obj += "\"color\": \""+color+"\",";
obj += "\"text\": \""+text+"\"";
obj += "}";
return obj; return obj;

View file

@ -19,7 +19,7 @@ modId="libzontreck" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build # see the associated build.gradle script for how to populate this completely automatically during a build
version="1.0.3.6" #mandatory version="1.0.3.7" #mandatory
# A display name for the mod # A display name for the mod
displayName="LibZontreck" #mandatory displayName="LibZontreck" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/