Serialize Json manually because... javax is apparently inaccessible in minecraft's classpath
This commit is contained in:
parent
41c98e8c3d
commit
65b3fc3e6d
4 changed files with 33 additions and 26 deletions
|
@ -5,5 +5,5 @@ org.gradle.daemon=false
|
|||
|
||||
mc_version=1.19.2
|
||||
forge_version=43.2.3
|
||||
myversion=1.0.3.6
|
||||
myversion=1.0.3.7
|
||||
parchment_version=2022.11.27
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
# ${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
|
||||
version="1.0.3.6" #mandatory
|
||||
version="1.0.3.7" #mandatory
|
||||
# A display name for the mod
|
||||
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/
|
||||
|
|
Reference in a new issue