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

@ -4,10 +4,6 @@ import java.util.ArrayList;
import java.util.Iterator;
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.ListTag;
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
public String saveJson(){
String ret = "";
JsonObjectBuilder loreEntry = Json.createObjectBuilder();
JsonArrayBuilder jab = Json.createArrayBuilder();
for (LoreEntry loreEntryx : LoreData) {
jab.add(loreEntryx.saveJson());
String ret = "{";
Iterator<LoreEntry> loreEntries = LoreData.iterator();
ret += "\"extra\": [";
while(loreEntries.hasNext())
{
LoreEntry loreEntryx = loreEntries.next();
ret += loreEntryx.saveJson();
if(loreEntries.hasNext())
{
ret += ",";
}
}
loreEntry.add("extra", jab);
loreEntry.add("text", "");
ret=loreEntry.build().toString();
ret += "],";
ret += "\"text\": \"\"";
ret += "}";
return ret;
}

View file

@ -1,8 +1,5 @@
package dev.zontreck.libzontreck.items.lore;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@ -41,18 +38,25 @@ public class LoreEntry
parentTag.add(tag);
}
private String bool2str(boolean a){
if(a)return "true";
else return "false";
}
// 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
public JsonObjectBuilder saveJson()
public String saveJson()
{
JsonObjectBuilder obj = Json.createObjectBuilder();
obj.add("bold", bold);
obj.add("italic", italic);
obj.add("underlined", underlined);
obj.add("strikethrough", strikethrough);
obj.add("obfuscated", obfuscated);
obj.add("color", color);
obj.add("text", text);
String obj = "{";
obj += "\"bold\": " + bool2str(bold)+",";
obj += "\"italic\": " + bool2str(italic)+",";
obj += "\"underlined\": "+bool2str(underlined)+",";
obj += "\"strikethrough\": "+bool2str(strikethrough)+",";
obj += "\"obfuscated\": "+bool2str(obfuscated)+",";
obj += "\"color\": \""+color+"\",";
obj += "\"text\": \""+text+"\"";
obj += "}";
return obj;