nbt contd
This commit is contained in:
1 parent
2b4be7d0b8
commit
eee23e4ba6
4 files changed
+60
-39
No files matched your search
@@ -1162,9 +1162,9 @@ public class CarpetExpression
|
||||
{
|
||||
Value nbtValue = lv.get(inventoryLocator.offset+3).evalValue(c);
|
||||
if (nbtValue instanceof NBTSerializableValue)
|
||||
nbt = ((NBTSerializableValue)nbtValue).getTag();
|
||||
nbt = ((NBTSerializableValue)nbtValue).getCompoundTag();
|
||||
else
|
||||
nbt = new NBTSerializableValue(nbtValue.getString()).getTag();
|
||||
nbt = new NBTSerializableValue(nbtValue.getString()).getCompoundTag();
|
||||
}
|
||||
ItemStackArgument newitem = NBTSerializableValue.parseItem(
|
||||
lv.get(inventoryLocator.offset+2).evalValue(c).getString(),
|
||||
@@ -1644,7 +1644,7 @@ public class CarpetExpression
|
||||
if (lv.size() > position.offset)
|
||||
{
|
||||
hasTag = true;
|
||||
tag = new NBTSerializableValue(lv.get(position.offset).evalValue(c).getString()).getTag();
|
||||
tag = new NBTSerializableValue(lv.get(position.offset).evalValue(c).getString()).getCompoundTag();
|
||||
}
|
||||
tag.putString("id", entityId.toString());
|
||||
Vec3d vec3d = position.vec;
|
||||
|
||||
@@ -1892,10 +1892,9 @@ public class Expression implements Cloneable
|
||||
return LazyListValue.range(from, to, step);
|
||||
});
|
||||
|
||||
addBinaryFunction("get", (v1, v2) ->
|
||||
{
|
||||
return v1.getElementAt(v2);
|
||||
});
|
||||
addUnaryFunction("is_list", value -> (value instanceof ListValue)? Value.TRUE : Value.FALSE);
|
||||
|
||||
addBinaryFunction("get", (v1, v2) -> v1.getElementAt(v2));
|
||||
|
||||
//Deprecated, use "get" instead
|
||||
addBinaryFunction("element", (v1, v2) ->
|
||||
|
||||
@@ -330,8 +330,8 @@ public class EntityValue extends Value
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1)
|
||||
return new NBTSerializableValue((CompoundTag) tags.get(0));
|
||||
return ListValue.wrap(tags.stream().map(t -> new NBTSerializableValue((CompoundTag) t)).collect(Collectors.toList()));
|
||||
return NBTSerializableValue.decodeTag(tags.get(0));
|
||||
return ListValue.wrap(tags.stream().map(t -> NBTSerializableValue.decodeTag(t)).collect(Collectors.toList()));
|
||||
}
|
||||
catch (CommandSyntaxException ignored) { }
|
||||
return Value.NULL;
|
||||
|
||||
@@ -8,11 +8,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.command.arguments.ItemStackArgument;
|
||||
import net.minecraft.command.arguments.ItemStringReader;
|
||||
import net.minecraft.command.arguments.NbtPathArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
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.AbstractNumberTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.nbt.Tag;
|
||||
@@ -22,13 +24,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
public class NBTSerializableValue extends Value
|
||||
{
|
||||
private String nbtString = null;
|
||||
private CompoundTag nbtTag = null;
|
||||
private Tag nbtTag = null;
|
||||
private Supplier<CompoundTag> nbtSupplier = null;
|
||||
|
||||
public NBTSerializableValue(ItemStack stack)
|
||||
@@ -51,7 +54,7 @@ public class NBTSerializableValue extends Value
|
||||
};
|
||||
}
|
||||
|
||||
public NBTSerializableValue(CompoundTag tag)
|
||||
public NBTSerializableValue(Tag tag)
|
||||
{
|
||||
nbtTag = tag;
|
||||
}
|
||||
@@ -155,7 +158,17 @@ public class NBTSerializableValue extends Value
|
||||
return slot;
|
||||
}
|
||||
|
||||
public CompoundTag getTag()
|
||||
public static Value decodeTag(Tag t)
|
||||
{
|
||||
if (t instanceof CompoundTag)
|
||||
return new NBTSerializableValue(t);
|
||||
if (t instanceof AbstractNumberTag)
|
||||
return new NumericValue(((AbstractNumberTag) t).getDouble());
|
||||
// more can be done here
|
||||
return new StringValue(t.asString());
|
||||
}
|
||||
|
||||
public Tag getTag()
|
||||
{
|
||||
if (nbtTag == null)
|
||||
nbtTag = nbtSupplier.get();
|
||||
@@ -184,6 +197,18 @@ public class NBTSerializableValue extends Value
|
||||
return true;
|
||||
}
|
||||
|
||||
public CompoundTag getCompoundTag()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (CompoundTag) getTag();
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
throw new InternalExpressionException(getString()+" is not a valid compound tag");
|
||||
}
|
||||
}
|
||||
|
||||
public static class InventoryLocator
|
||||
{
|
||||
public Object owner;
|
||||
@@ -202,35 +227,32 @@ public class NBTSerializableValue extends Value
|
||||
@Override
|
||||
public Value getElementAt(Value value)
|
||||
{
|
||||
String path = value.getString();
|
||||
String pathString = value.getString();
|
||||
|
||||
//return Value.NULL;
|
||||
|
||||
NbtPathArgumentType.NbtPath path;
|
||||
try
|
||||
{
|
||||
path = NbtPathArgumentType.nbtPath().method_9362(new StringReader(pathString));
|
||||
}
|
||||
catch (CommandSyntaxException exc)
|
||||
{
|
||||
throw new InternalExpressionException("Incorrect nbt path: "+pathString);
|
||||
}
|
||||
String res = null;
|
||||
try
|
||||
{
|
||||
List<Tag> tags = path.get(getTag());
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1)
|
||||
return new NBTSerializableValue(tags.get(0));
|
||||
return ListValue.wrap(tags.stream().map(NBTSerializableValue::new).collect(Collectors.toList()));
|
||||
}
|
||||
catch (CommandSyntaxException ignored) { }
|
||||
return Value.NULL;
|
||||
/*
|
||||
CompoundTag nbttagcompound = e.toTag((new CompoundTag()));
|
||||
if (a==null)
|
||||
return new NBTSerializableValue(nbttagcompound);//StringValue(nbttagcompound.toString());
|
||||
NbtPathArgumentType.NbtPath path;
|
||||
try
|
||||
{
|
||||
path = NbtPathArgumentType.nbtPath().method_9362(new StringReader(a.getString()));
|
||||
}
|
||||
catch (CommandSyntaxException exc)
|
||||
{
|
||||
throw new InternalExpressionException("Incorrect path: "+a.getString());
|
||||
}
|
||||
String res = null;
|
||||
try
|
||||
{
|
||||
List<Tag> tags = path.get(nbttagcompound);
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1)
|
||||
return new NBTSerializableValue(tags.get(0));
|
||||
return ListValue.wrap(tags.stream().map(NBTSerializableValue::new).collect(Collectors.toList()));
|
||||
}
|
||||
catch (CommandSyntaxException ignored) { }
|
||||
return Value.NULL;
|
||||
*/
|
||||
|
||||
/*int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
|
||||
Reference in new issue
Block a user