its a doozie
This commit is contained in:
1 parent
365892b9ca
commit
ab553187c5
43 files changed
+356
-351
No files matched your search
@@ -13,9 +13,9 @@ import net.minecraft.command.argument.BlockArgumentParser;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.dynamic.GlobalPos;
|
||||
@@ -45,7 +45,7 @@ public class BlockValue extends Value
|
||||
private BlockState blockState;
|
||||
private final BlockPos pos;
|
||||
private final ServerWorld world;
|
||||
private CompoundTag data;
|
||||
private NbtCompound data;
|
||||
|
||||
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
|
||||
{
|
||||
@@ -63,9 +63,9 @@ public class BlockValue extends Value
|
||||
BlockArgumentParser blockstateparser = (new BlockArgumentParser(new StringReader(str), false)).parse(true);
|
||||
if (blockstateparser.getBlockState() != null)
|
||||
{
|
||||
CompoundTag bd = blockstateparser.getNbtData();
|
||||
NbtCompound bd = blockstateparser.getNbtData();
|
||||
if (bd == null)
|
||||
bd = new CompoundTag();
|
||||
bd = new NbtCompound();
|
||||
bv = new BlockValue(blockstateparser.getBlockState(), null, null, bd );
|
||||
if (bvCache.size()>10000)
|
||||
bvCache.clear();
|
||||
@@ -107,7 +107,7 @@ public class BlockValue extends Value
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag getData()
|
||||
public NbtCompound getData()
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
@@ -118,7 +118,7 @@ public class BlockValue extends Value
|
||||
if (world != null && pos != null)
|
||||
{
|
||||
BlockEntity be = getBlockEntity(world, pos);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
if (be == null)
|
||||
{
|
||||
data = tag;
|
||||
@@ -139,7 +139,7 @@ public class BlockValue extends Value
|
||||
data = null;
|
||||
}
|
||||
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position, CompoundTag nbt)
|
||||
public BlockValue(BlockState state, ServerWorld world, BlockPos position, NbtCompound nbt)
|
||||
{
|
||||
this.world = world;
|
||||
blockState = state;
|
||||
@@ -188,26 +188,26 @@ public class BlockValue extends Value
|
||||
public ServerWorld getWorld() { return world;}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
// follows falling block convertion
|
||||
CompoundTag tag = new CompoundTag();
|
||||
CompoundTag state = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
NbtCompound state = new NbtCompound();
|
||||
BlockState s = getBlockState();
|
||||
state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
|
||||
state.put("Name", NbtString.of(Registry.BLOCK.getId(s.getBlock()).toString()));
|
||||
Collection<Property<?>> properties = s.getProperties();
|
||||
if (!properties.isEmpty())
|
||||
{
|
||||
CompoundTag props = new CompoundTag();
|
||||
NbtCompound props = new NbtCompound();
|
||||
for (Property<?> p: properties)
|
||||
{
|
||||
props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
|
||||
props.put(p.getName(), NbtString.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
state.put("Properties", props);
|
||||
}
|
||||
tag.put("BlockState", state);
|
||||
CompoundTag dataTag = getData();
|
||||
NbtCompound dataTag = getData();
|
||||
if (dataTag != null)
|
||||
{
|
||||
tag.put("TileEntityData", dataTag);
|
||||
|
||||
@@ -2,8 +2,8 @@ package carpet.script.value;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtByte;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class BooleanValue extends NumericValue
|
||||
{
|
||||
@@ -47,8 +47,8 @@ public class BooleanValue extends NumericValue
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force) {
|
||||
return ByteTag.of(boolValue);
|
||||
public NbtElement toTag(boolean force) {
|
||||
return NbtByte.of(boolValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,8 +27,8 @@ import net.minecraft.entity.ai.brain.MemoryModuleType;
|
||||
import net.minecraft.entity.ai.pathing.Path;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket;
|
||||
@@ -49,12 +49,13 @@ import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.mob.PathAwareEntity;
|
||||
import net.minecraft.entity.passive.PassiveEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TypeFilter;
|
||||
@@ -241,7 +242,7 @@ public class EntityValue extends Value
|
||||
positive = false;
|
||||
who = who.substring(1);
|
||||
}
|
||||
net.minecraft.tag.Tag<EntityType<?>> eTag = server.getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(who));
|
||||
Tag<EntityType<?>> eTag = server.getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(who));
|
||||
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor");
|
||||
if (positive)
|
||||
{
|
||||
@@ -450,7 +451,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("has_scoreboard_tag", (e, a) -> new NumericValue(e.getScoreboardTags().contains(a.getString())));
|
||||
put("has_entity_tag", (e, a) -> {
|
||||
net.minecraft.tag.Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
|
||||
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
|
||||
if (tag == null) return Value.NULL;
|
||||
return new NumericValue(e.getType().isIn(tag));
|
||||
});
|
||||
@@ -841,7 +842,7 @@ public class EntityValue extends Value
|
||||
});
|
||||
|
||||
put("nbt",(e, a) -> {
|
||||
CompoundTag nbttagcompound = e.writeNbt((new CompoundTag()));
|
||||
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
|
||||
if (a==null)
|
||||
return new NBTSerializableValue(nbttagcompound);
|
||||
return new NBTSerializableValue(nbttagcompound).get(a);
|
||||
@@ -1470,7 +1471,7 @@ public class EntityValue extends Value
|
||||
Value tagValue = NBTSerializableValue.fromValue(v);
|
||||
if (tagValue instanceof NBTSerializableValue)
|
||||
{
|
||||
CompoundTag nbttagcompound = e.writeNbt((new CompoundTag()));
|
||||
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
|
||||
nbttagcompound.copyFrom(((NBTSerializableValue) tagValue).getCompoundTag());
|
||||
e.readNbt(nbttagcompound);
|
||||
e.setUuid(uUID);
|
||||
@@ -1493,12 +1494,12 @@ public class EntityValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("Data", getEntity().writeNbt( new CompoundTag()));
|
||||
tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
|
||||
NbtCompound tag = new NbtCompound();
|
||||
tag.put("Data", getEntity().writeNbt( new NbtCompound()));
|
||||
tag.put("Name", NbtString.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
@@ -70,10 +70,10 @@ public class FormattedTextValue extends StringValue
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(Text.Serializer.toJson(text));
|
||||
return NbtString.of(Text.Serializer.toJson(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public abstract class FrameworkValue extends Value
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public abstract class FrameworkValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
throw new UnsupportedOperationException("Scarpet language component cannot be serialized to the tag");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class FunctionAnnotationValue extends Value
|
||||
{
|
||||
@@ -35,7 +35,7 @@ public class FunctionAnnotationValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
throw new UnsupportedOperationException("Global value cannot be serialized to the tag");
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import carpet.script.exception.ExpressionException;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ReturnStatement;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -246,10 +246,10 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
public String getVarArgs() {return varArgs; }
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(getString());
|
||||
return NbtString.of(getString());
|
||||
}
|
||||
|
||||
public void assertArgsOk(List<?> list, Consumer<Boolean> feedback)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -199,9 +199,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of(getString());
|
||||
return NbtString.of(getString());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -254,9 +254,9 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
CompoundTag tag = new CompoundTag() ;
|
||||
NbtCompound tag = new NbtCompound() ;
|
||||
map.forEach( (k, v) ->
|
||||
{
|
||||
if (!force && !(k instanceof StringValue)) throw new NBTSerializableValue.IncompatibleTypeException(k);
|
||||
|
||||
@@ -25,13 +25,13 @@ import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.AbstractListTag;
|
||||
import net.minecraft.nbt.AbstractNumberTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.AbstractNbtList;
|
||||
import net.minecraft.nbt.AbstractNbtNumber;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -53,8 +53,8 @@ import java.util.stream.Collectors;
|
||||
public class NBTSerializableValue extends Value implements ContainerValueInterface
|
||||
{
|
||||
private String nbtString = null;
|
||||
private Tag nbtTag = null;
|
||||
private Supplier<Tag> nbtSupplier = null;
|
||||
private NbtElement nbtTag = null;
|
||||
private Supplier<NbtElement> nbtSupplier = null;
|
||||
private boolean owned = false;
|
||||
|
||||
private NBTSerializableValue() {}
|
||||
@@ -65,7 +65,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
{
|
||||
try
|
||||
{
|
||||
return (new StringNbtReader(new StringReader(nbtString))).parseTag();
|
||||
return (new StringNbtReader(new StringReader(nbtString))).parseElement();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -75,13 +75,13 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
owned = true;
|
||||
}
|
||||
|
||||
public NBTSerializableValue(Tag tag)
|
||||
public NBTSerializableValue(NbtElement tag)
|
||||
{
|
||||
nbtTag = tag;
|
||||
owned = true;
|
||||
}
|
||||
|
||||
public NBTSerializableValue(Supplier<Tag> tagSupplier)
|
||||
public NBTSerializableValue(Supplier<NbtElement> tagSupplier)
|
||||
{
|
||||
nbtSupplier = tagSupplier;
|
||||
}
|
||||
@@ -108,10 +108,10 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
public static NBTSerializableValue parseString(String nbtString, boolean fail)
|
||||
{
|
||||
Tag tag;
|
||||
NbtElement tag;
|
||||
try
|
||||
{
|
||||
tag = (new StringNbtReader(new StringReader(nbtString))).parseTag();
|
||||
tag = (new StringNbtReader(new StringReader(nbtString))).parseElement();
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -276,7 +276,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return parseItem(itemString, null);
|
||||
}
|
||||
|
||||
public static ItemStackArgument parseItem(String itemString, CompoundTag customTag)
|
||||
public static ItemStackArgument parseItem(String itemString, NbtCompound customTag)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -313,12 +313,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return slot;
|
||||
}
|
||||
|
||||
private static Value decodeTag(Tag t)
|
||||
private static Value decodeTag(NbtElement t)
|
||||
{
|
||||
if (t instanceof CompoundTag)
|
||||
if (t instanceof NbtCompound)
|
||||
return new NBTSerializableValue(() -> t);
|
||||
if (t instanceof AbstractNumberTag)
|
||||
return new NumericValue(((AbstractNumberTag) t).getDouble());
|
||||
if (t instanceof AbstractNbtNumber)
|
||||
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
|
||||
// more can be done here
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
@@ -338,35 +338,35 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
|
||||
private static Value decodeTagDeep(Tag t)
|
||||
private static Value decodeTagDeep(NbtElement t)
|
||||
{
|
||||
if (t instanceof CompoundTag)
|
||||
if (t instanceof NbtCompound)
|
||||
{
|
||||
Map<Value, Value> pairs = new HashMap<>();
|
||||
CompoundTag ctag = (CompoundTag)t;
|
||||
NbtCompound ctag = (NbtCompound)t;
|
||||
for (String key: ctag.getKeys())
|
||||
{
|
||||
pairs.put(new StringValue(key), decodeTagDeep(ctag.get(key)));
|
||||
}
|
||||
return MapValue.wrap(pairs);
|
||||
}
|
||||
if (t instanceof AbstractListTag)
|
||||
if (t instanceof AbstractNbtList)
|
||||
{
|
||||
List<Value> elems = new ArrayList<>();
|
||||
AbstractListTag<? extends Tag> ltag = (AbstractListTag<? extends Tag>)t;
|
||||
for (Tag elem: ltag)
|
||||
AbstractNbtList<? extends NbtElement> ltag = (AbstractNbtList<? extends NbtElement>)t;
|
||||
for (NbtElement elem: ltag)
|
||||
{
|
||||
elems.add(decodeTagDeep(elem));
|
||||
}
|
||||
return ListValue.wrap(elems);
|
||||
}
|
||||
if (t instanceof AbstractNumberTag)
|
||||
return new NumericValue(((AbstractNumberTag) t).getDouble());
|
||||
if (t instanceof AbstractNbtNumber)
|
||||
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
|
||||
// more can be done here
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
|
||||
public Tag getTag()
|
||||
public NbtElement getTag()
|
||||
{
|
||||
if (nbtTag == null)
|
||||
nbtTag = nbtSupplier.get();
|
||||
@@ -392,24 +392,24 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
@Override
|
||||
public boolean getBoolean()
|
||||
{
|
||||
Tag tag = getTag();
|
||||
if (tag instanceof CompoundTag)
|
||||
return !((CompoundTag) tag).isEmpty();
|
||||
if (tag instanceof AbstractListTag)
|
||||
return ((AbstractListTag) tag).isEmpty();
|
||||
if (tag instanceof AbstractNumberTag)
|
||||
return ((AbstractNumberTag) tag).getDouble()!=0.0;
|
||||
if (tag instanceof StringTag)
|
||||
NbtElement tag = getTag();
|
||||
if (tag instanceof NbtCompound)
|
||||
return !((NbtCompound) tag).isEmpty();
|
||||
if (tag instanceof AbstractNbtList)
|
||||
return ((AbstractNbtList) tag).isEmpty();
|
||||
if (tag instanceof AbstractNbtNumber)
|
||||
return ((AbstractNbtNumber) tag).doubleValue()!=0.0;
|
||||
if (tag instanceof NbtString)
|
||||
return tag.asString().isEmpty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public CompoundTag getCompoundTag()
|
||||
public NbtCompound getCompoundTag()
|
||||
{
|
||||
try
|
||||
{
|
||||
ensureOwnership();
|
||||
return (CompoundTag) getTag();
|
||||
return (NbtCompound) getTag();
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
@@ -429,7 +429,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
/// WIP
|
||||
ensureOwnership();
|
||||
NbtPathArgumentType.NbtPath path = cachePath(where.getString());
|
||||
Tag tagToInsert = value instanceof NBTSerializableValue ?
|
||||
NbtElement tagToInsert = value instanceof NBTSerializableValue ?
|
||||
((NBTSerializableValue) value).getTag() :
|
||||
new NBTSerializableValue(value.getString()).getTag();
|
||||
boolean modifiedTag;
|
||||
@@ -459,17 +459,17 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
|
||||
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement)
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement)
|
||||
{
|
||||
return modify_insert(index, nbtPath, newElement, this.getTag());
|
||||
}
|
||||
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement, Tag currentTag)
|
||||
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement, NbtElement currentTag)
|
||||
{
|
||||
Collection<Tag> targets;
|
||||
Collection<NbtElement> targets;
|
||||
try
|
||||
{
|
||||
targets = nbtPath.getOrInit(currentTag, ListTag::new);
|
||||
targets = nbtPath.getOrInit(currentTag, NbtList::new);
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -477,16 +477,16 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
boolean modified = false;
|
||||
for (Tag target : targets)
|
||||
for (NbtElement target : targets)
|
||||
{
|
||||
if (!(target instanceof AbstractListTag))
|
||||
if (!(target instanceof AbstractNbtList))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
AbstractListTag<?> targetList = (AbstractListTag) target;
|
||||
if (!targetList.addTag(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
|
||||
AbstractNbtList<?> targetList = (AbstractNbtList) target;
|
||||
if (!targetList.addElement(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
|
||||
return false;
|
||||
modified = true;
|
||||
}
|
||||
@@ -498,22 +498,22 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
|
||||
|
||||
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
{
|
||||
if (!(replacement instanceof CompoundTag))
|
||||
if (!(replacement instanceof NbtCompound))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Tag ownTag = getTag();
|
||||
NbtElement ownTag = getTag();
|
||||
try
|
||||
{
|
||||
for (Tag target : nbtPath.getOrInit(ownTag, CompoundTag::new))
|
||||
for (NbtElement target : nbtPath.getOrInit(ownTag, NbtCompound::new))
|
||||
{
|
||||
if (!(target instanceof CompoundTag))
|
||||
if (!(target instanceof NbtCompound))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
((CompoundTag) target).copyFrom((CompoundTag) replacement);
|
||||
((NbtCompound) target).copyFrom((NbtCompound) replacement);
|
||||
}
|
||||
}
|
||||
catch (CommandSyntaxException ignored)
|
||||
@@ -523,9 +523,9 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
|
||||
{
|
||||
Tag tag = getTag();
|
||||
NbtElement tag = getTag();
|
||||
String pathText = nbtPath.toString();
|
||||
if (pathText.endsWith("]")) // workaround for array replacement or item in the array replacement
|
||||
{
|
||||
@@ -572,7 +572,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
NbtPathArgumentType.NbtPath path = cachePath(value.getString());
|
||||
try
|
||||
{
|
||||
List<Tag> tags = path.get(getTag());
|
||||
List<NbtElement> tags = path.get(getTag());
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1)
|
||||
@@ -669,7 +669,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
ensureOwnership();
|
||||
|
||||
@@ -4,8 +4,8 @@ import java.util.ArrayList;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
{
|
||||
@@ -80,10 +80,10 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return StringTag.of("null");
|
||||
return NbtString.of("null");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,10 +3,10 @@ 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;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtDouble;
|
||||
import net.minecraft.nbt.NbtInt;
|
||||
import net.minecraft.nbt.NbtLong;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -271,20 +271,20 @@ public class NumericValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (longValue != null)
|
||||
return LongTag.of(longValue);
|
||||
return NbtLong.of(longValue);
|
||||
long lv = getLong();
|
||||
if (value == (double)lv)
|
||||
{
|
||||
if (abs(value) < Integer.MAX_VALUE-2)
|
||||
return IntTag.of((int)lv);
|
||||
return LongTag.of(getLong());
|
||||
return NbtInt.of((int)lv);
|
||||
return NbtLong.of(getLong());
|
||||
}
|
||||
else
|
||||
{
|
||||
return DoubleTag.of(value);
|
||||
return NbtDouble.of(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
public class StringValue extends Value
|
||||
{
|
||||
@@ -43,8 +43,8 @@ public class StringValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
return StringTag.of(str);
|
||||
return NbtString.of(str);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import carpet.script.Tokenizer;
|
||||
import carpet.script.exception.ExitStatement;
|
||||
import carpet.script.exception.ExpressionException;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -117,7 +117,7 @@ public class ThreadValue extends Value
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(boolean force)
|
||||
public NbtElement toTag(boolean force)
|
||||
{
|
||||
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
|
||||
return getValue().toTag(true);
|
||||
|
||||
@@ -3,7 +3,7 @@ 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 net.minecraft.nbt.NbtElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -251,7 +251,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Tag toTag(boolean force);
|
||||
public abstract NbtElement toTag(boolean force);
|
||||
|
||||
public JsonElement toJson()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user