Can has json version of a scarpet value
This commit is contained in:
1 parent
b48c52cce4
commit
e759a368b9
5 files changed
+57
-3
No files matched your search
@@ -2,6 +2,8 @@ package carpet.script.value;
|
||||
|
||||
import carpet.script.LazyValue;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.AbstractNumberTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@@ -525,4 +527,13 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson()
|
||||
{
|
||||
JsonArray array = new JsonArray();
|
||||
for (Value el: items)
|
||||
array.add(el.toJson());
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
@@ -256,4 +258,12 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
});
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson()
|
||||
{
|
||||
JsonObject jsonMap = new JsonObject();
|
||||
map.forEach((k, v) -> jsonMap.add(k.getString(), v.toJson()));
|
||||
return jsonMap;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
@@ -60,4 +62,10 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of("null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson()
|
||||
{
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.LongTag;
|
||||
@@ -235,11 +237,11 @@ public class NumericValue extends Value
|
||||
{
|
||||
if (longValue != null)
|
||||
return LongTag.of(longValue);
|
||||
long longValue = getLong();
|
||||
if (value == (double)longValue)
|
||||
long lv = getLong();
|
||||
if (value == (double)lv)
|
||||
{
|
||||
if (abs(value) < Integer.MAX_VALUE-2)
|
||||
return IntTag.of((int)longValue);
|
||||
return IntTag.of((int)lv);
|
||||
return LongTag.of(getLong());
|
||||
}
|
||||
else
|
||||
@@ -247,4 +249,20 @@ public class NumericValue extends Value
|
||||
return DoubleTag.of(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson()
|
||||
{
|
||||
if (longValue != null)
|
||||
return new JsonPrimitive(longValue);
|
||||
long lv = getLong();
|
||||
if (value == (double)lv)
|
||||
{
|
||||
return new JsonPrimitive(getLong());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new JsonPrimitive(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
@@ -206,4 +208,9 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
}
|
||||
|
||||
public abstract Tag toTag(boolean force);
|
||||
|
||||
public JsonElement toJson()
|
||||
{
|
||||
return new JsonPrimitive(getString());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user