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
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user