Add FormattedText functionality to the right of the operand

This commit is contained in:
altrisi committed 2020-12-14 19:20:21 +01:00
1 parent 7b77fb0853
commit 6dfd64027d
2 files changed
+11 -1

No files matched your search

@@ -27,7 +27,7 @@ public class FormattedTextValue extends StringValue
@Override
public Value clone()
{
return new FormattedTextValue(text);
return new FormattedTextValue(text.shallowCopy());
}
@Override
@@ -4,6 +4,8 @@ import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.nbt.Tag;
import net.minecraft.text.BaseText;
import net.minecraft.text.LiteralText;
import java.util.ArrayList;
import java.util.List;
@@ -79,6 +81,14 @@ public abstract class Value implements Comparable<Value>, Cloneable
public Value add(Value o) {
String lstr = this.getString();
if (o instanceof FormattedTextValue)
{
if (lstr == null)
return ((FormattedTextValue) o).clone();
BaseText newText = new LiteralText(lstr);
newText.append(((FormattedTextValue) o).getText().shallowCopy());
return new FormattedTextValue(newText);
}
if (lstr == null) // null
return new StringValue(o.getString());
String rstr = o.getString();