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