its a doozie
This commit is contained in:
1 parent
365892b9ca
commit
ab553187c5
43 files changed
+356
-351
No files matched your search
@@ -5,14 +5,14 @@ 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;
|
||||
import net.minecraft.nbt.DoubleTag;
|
||||
import net.minecraft.nbt.IntTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.LongTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.AbstractNbtNumber;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtDouble;
|
||||
import net.minecraft.nbt.NbtInt;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.NbtLong;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -481,31 +481,31 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
LIST,
|
||||
MAP,
|
||||
STRING;
|
||||
private static TagTypeCompat getType(Tag tag)
|
||||
private static TagTypeCompat getType(NbtElement tag)
|
||||
{
|
||||
if (tag instanceof IntTag) return INT;
|
||||
if (tag instanceof LongTag) return LONG;
|
||||
if (tag instanceof DoubleTag) return DBL;
|
||||
if (tag instanceof ListTag) return LIST;
|
||||
if (tag instanceof CompoundTag) return MAP;
|
||||
if (tag instanceof NbtInt) return INT;
|
||||
if (tag instanceof NbtLong) return LONG;
|
||||
if (tag instanceof NbtDouble) return DBL;
|
||||
if (tag instanceof NbtList) return LIST;
|
||||
if (tag instanceof NbtCompound) return MAP;
|
||||
return STRING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
int argSize = items.size();
|
||||
if (argSize == 0) return new ListTag();
|
||||
ListTag tag = new ListTag();
|
||||
if (argSize == 0) return new NbtList();
|
||||
NbtList tag = new NbtList();
|
||||
if (argSize ==1)
|
||||
{
|
||||
tag.add(items.get(0).toTag(force));
|
||||
return tag;
|
||||
}
|
||||
// figuring out the types
|
||||
List<Tag> tags= new ArrayList<>();
|
||||
List<NbtElement> tags= new ArrayList<>();
|
||||
items.forEach(v -> tags.add(v.toTag(force)));
|
||||
Set<TagTypeCompat> cases = EnumSet.noneOf(TagTypeCompat.class);
|
||||
tags.forEach(t -> cases.add(TagTypeCompat.getType(t)));
|
||||
@@ -519,17 +519,17 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
|| cases.contains(TagTypeCompat.STRING)) // incompatible types
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
tags.forEach(t -> tag.add(StringTag.of(t.asString())));
|
||||
tags.forEach(t -> tag.add(NbtString.of(t.asString())));
|
||||
return tag;
|
||||
}
|
||||
// only numbers / mixed types
|
||||
if (cases.contains(TagTypeCompat.DBL))
|
||||
{
|
||||
tags.forEach(t -> tag.add(DoubleTag.of(((AbstractNumberTag)t).getDouble())));
|
||||
tags.forEach(t -> tag.add(NbtDouble.of(((AbstractNbtNumber)t).doubleValue())));
|
||||
}
|
||||
else
|
||||
{
|
||||
tags.forEach(t -> tag.add(LongTag.of(((AbstractNumberTag)t).getLong())));
|
||||
tags.forEach(t -> tag.add(NbtLong.of(((AbstractNbtNumber)t).longValue())));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user