Merge pull request #628 from altrisi/formatted-add
Add FormattedText addition
This commit is contained in:
2 files changed
+38
No files matched your search
@@ -3,6 +3,7 @@ package carpet.script.value;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class FormattedTextValue extends StringValue
|
||||
@@ -14,6 +15,33 @@ public class FormattedTextValue extends StringValue
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static Value combine(Value left, Value right) {
|
||||
BaseText text;
|
||||
if (left instanceof FormattedTextValue)
|
||||
{
|
||||
text = (BaseText) ((FormattedTextValue) left).getText().shallowCopy();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (left instanceof NullValue)
|
||||
return right;
|
||||
text = new LiteralText(left.getString());
|
||||
}
|
||||
|
||||
if (right instanceof FormattedTextValue)
|
||||
{
|
||||
text.append(((FormattedTextValue) right).getText().shallowCopy());
|
||||
return new FormattedTextValue(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (right instanceof NullValue)
|
||||
return left;
|
||||
text.append(right.getString());
|
||||
return new FormattedTextValue(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString() {
|
||||
return text.getString();
|
||||
@@ -48,10 +76,16 @@ public class FormattedTextValue extends StringValue
|
||||
return StringTag.of(Text.Serializer.toJson(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value add(Value o) {
|
||||
return combine(this, o);
|
||||
}
|
||||
|
||||
public String serialize()
|
||||
{
|
||||
return Text.Serializer.toJson(text);
|
||||
}
|
||||
|
||||
public static FormattedTextValue deserialize(String serialized)
|
||||
{
|
||||
return new FormattedTextValue(Text.Serializer.fromJson(serialized));
|
||||
|
||||
@@ -79,6 +79,10 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
|
||||
public Value add(Value o) {
|
||||
String lstr = this.getString();
|
||||
if (o instanceof FormattedTextValue)
|
||||
{
|
||||
return FormattedTextValue.combine(this, o);
|
||||
}
|
||||
if (lstr == null) // null
|
||||
return new StringValue(o.getString());
|
||||
String rstr = o.getString();
|
||||
|
||||
Reference in new issue
Block a user