reworked script host, working on nbttags
This commit is contained in:
1 parent
5e404d62be
commit
239e7006a5
11 files changed
+175
-51
No files matched your search
@@ -313,7 +313,7 @@ public class EntityValue extends Value
|
||||
put("nbt",(e, a) -> {
|
||||
CompoundTag nbttagcompound = e.toTag((new CompoundTag()));
|
||||
if (a==null)
|
||||
return new StringValue(nbttagcompound.toString());
|
||||
return new NBTSerializableValue(nbttagcompound);//StringValue(nbttagcompound.toString());
|
||||
NbtPathArgumentType.NbtPath path;
|
||||
try
|
||||
{
|
||||
@@ -330,11 +330,11 @@ public class EntityValue extends Value
|
||||
if (tags.size()==0)
|
||||
return Value.NULL;
|
||||
if (tags.size()==1)
|
||||
return new StringValue(tags.get(0).toText().getString());
|
||||
return ListValue.wrap(tags.stream().map((t) -> new StringValue(t.toText().getString())).collect(Collectors.toList()));
|
||||
return new NBTSerializableValue((CompoundTag) tags.get(0));
|
||||
return ListValue.wrap(tags.stream().map(t -> new NBTSerializableValue((CompoundTag) t)).collect(Collectors.toList()));
|
||||
}
|
||||
catch (CommandSyntaxException ignored) { }
|
||||
return new StringValue(res);
|
||||
return Value.NULL;
|
||||
});
|
||||
}};
|
||||
private static <Req extends Entity> Req assertEntityArgType(Class<Req> klass, Value arg)
|
||||
|
||||
@@ -106,4 +106,10 @@ public abstract class LazyListValue extends ListValue implements Iterator<Value>
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getElementAt(Value v2)
|
||||
{
|
||||
throw new InternalExpressionException("get element can only be obtained for regular lists");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -316,6 +316,17 @@ public class ListValue extends Value
|
||||
return (double)items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getElementAt(Value value)
|
||||
{
|
||||
long index = NumericValue.asNumber(value).getLong();
|
||||
int numitems = items.size();
|
||||
long range = abs(index)/numitems;
|
||||
index += (range+2)*numitems;
|
||||
index = index % numitems;
|
||||
return items.get((int)index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.StringNbtReader;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -22,6 +23,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
public class NBTSerializableValue extends Value
|
||||
{
|
||||
private String nbtString = null;
|
||||
@@ -195,4 +198,43 @@ public class NBTSerializableValue extends Value
|
||||
offset = o;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getElementAt(Value value)
|
||||
{
|
||||
String path = value.getString();
|
||||
|
||||
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;
|
||||
index = index % numitems;
|
||||
return items.get((int)index); */
|
||||
}
|
||||
}
|
||||
@@ -172,4 +172,9 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
{
|
||||
return (long)readNumber();
|
||||
}
|
||||
|
||||
public Value getElementAt(Value v2)
|
||||
{
|
||||
throw new InternalExpressionException("get element can only be obtained for lists and nbt values");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user