Merge branch 'master' into 1.17

# Conflicts:
#	src/main/java/carpet/script/api/Auxiliary.java
#	src/main/java/carpet/script/api/Entities.java
#	src/main/java/carpet/script/api/Inventories.java
#	src/main/java/carpet/script/api/Scoreboards.java
#	src/main/java/carpet/script/api/WorldAccess.java
#	src/main/java/carpet/script/value/FunctionValue.java
#	src/main/java/carpet/script/value/NBTSerializableValue.java
This commit is contained in:
gnembon committed 2021-04-23 01:46:11 -03:00
commit 5e3812e1f0
35 files changed
+1250 -1416

No files matched your search

@@ -29,21 +29,22 @@ public class BlockArgument extends Argument
block = b;
this.replacement = replacement;
}
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset)
public static BlockArgument findIn(CarpetContext c, List<Value> params, int offset)
{
return findIn(c, params,offset, false, false, false);
}
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean acceptString)
public static BlockArgument findIn(CarpetContext c, List<Value> params, int offset, boolean acceptString)
{
return findIn(c, params,offset, acceptString, false, false);
}
public static BlockArgument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean acceptString, boolean optional, boolean anyString)
public static BlockArgument findIn(CarpetContext c, List<Value> params, int offset, boolean acceptString, boolean optional, boolean anyString)
{
try
{
Value v1 = params.get(0 + offset).evalValue(c);
Value v1 = params.get(0 + offset);
//add conditional from string name
if (optional && v1 instanceof NullValue)
{
@@ -76,8 +77,8 @@ public class BlockArgument extends Argument
1+offset);
}
int xpos = (int) NumericValue.asNumber(v1).getLong();
int ypos = (int) NumericValue.asNumber( params.get(1 + offset).evalValue(c)).getLong();
int zpos = (int) NumericValue.asNumber( params.get(2 + offset).evalValue(c)).getLong();
int ypos = (int) NumericValue.asNumber( params.get(1 + offset)).getLong();
int zpos = (int) NumericValue.asNumber( params.get(2 + offset)).getLong();
return new BlockArgument(
new BlockValue(
null,
@@ -117,11 +117,11 @@ public class FileArgument
return "path: "+resource+" zip: "+zipContainer+" type: "+type.id+" folder: "+isFolder+" shared: "+isShared+" reason: "+reason.toString();
}
public static FileArgument from(List<LazyValue> lv, Context c, boolean isFolder, Reason reason)
public static FileArgument from(List<Value> lv, boolean isFolder, Reason reason)
{
if (lv.size() < 2) throw new InternalExpressionException("File functions require path and type as first two arguments");
Pair<String, String> resource = recognizeResource(lv.get(0).evalValue(c), isFolder);
String origtype = lv.get(1).evalValue(c).getString().toLowerCase(Locale.ROOT);
Pair<String, String> resource = recognizeResource(lv.get(0), isFolder);
String origtype = lv.get(1).getString().toLowerCase(Locale.ROOT);
boolean shared = origtype.startsWith("shared_");
String typeString = shared ? origtype.substring(7) : origtype; //len(shared_)
Type type = Type.of.get(typeString);
@@ -1,6 +1,7 @@
package carpet.script.argument;
import carpet.script.Context;
import carpet.script.Fluff;
import carpet.script.LazyValue;
import carpet.script.ScriptHost;
import carpet.script.bundled.Module;
@@ -15,12 +16,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class FunctionArgument<T> extends Argument
public class FunctionArgument extends Argument
{
public FunctionValue function;
public List<T> args;
public List<Value> args;
private FunctionArgument(FunctionValue function, int offset, List<T> args)
private FunctionArgument(FunctionValue function, int offset, List<Value> args)
{
super(offset);
this.function = function;
@@ -38,18 +39,18 @@ public class FunctionArgument<T> extends Argument
* if the number of supplied arguments is right
* @return argument data
*/
public static FunctionArgument<LazyValue> findIn(
public static FunctionArgument findIn(
Context c,
Module module,
List<LazyValue> params,
List<Value> params,
int offset,
boolean allowNone,
boolean checkArgs)
{
Value functionValue = params.get(offset).evalValue(c);
Value functionValue = params.get(offset);
if (functionValue.isNull())
{
if (allowNone) return new FunctionArgument<>(null, offset+1, Collections.emptyList());
if (allowNone) return new FunctionArgument(null, offset+1, Collections.emptyList());
throw new InternalExpressionException("function argument cannot be null");
}
if (!(functionValue instanceof FunctionValue))
@@ -67,12 +68,12 @@ public class FunctionArgument<T> extends Argument
if (extraargs > 0 && fun.getVarArgs() == null)
throw new InternalExpressionException("Function " + fun.getPrettyString() + " requires " + fun.getArguments().size() + " arguments");
}
List<LazyValue> lvargs = new ArrayList<>();
List<Value> lvargs = new ArrayList<>();
for (int i = offset+1, mx = params.size(); i < mx; i++) lvargs.add(params.get(i));
return new FunctionArgument<>(fun, offset + 1 + argsize, lvargs);
return new FunctionArgument(fun, offset + 1 + argsize, lvargs);
}
public static FunctionArgument<Value> fromCommandSpec(ScriptHost host, Value funSpec) throws CommandSyntaxException {
public static FunctionArgument fromCommandSpec(ScriptHost host, Value funSpec) throws CommandSyntaxException {
FunctionValue function;
List<Value> args = Collections.emptyList();
if (!(funSpec instanceof ListValue))
@@ -92,6 +93,11 @@ public class FunctionArgument<T> extends Argument
}
if (params.size() > 1) args = params.subList(1,params.size());
return new FunctionArgument<>(function, 0, args);
return new FunctionArgument(function, 0, args);
}
public List<Value> checkedArgs() {
function.checkArgs(args.size());
return args;
}
}
@@ -47,66 +47,12 @@ public class Vector3Argument extends Argument
return this;
}
public static Vector3Argument findIn(CarpetContext c, List<LazyValue> params, int offset)
public static Vector3Argument findIn(List<Value> params, int offset)
{
return findIn(c,params, offset, false, false);
return findIn(params, offset, false, false);
}
public static Vector3Argument findIn(CarpetContext c, List<LazyValue> params, int offset, boolean optionalDirection, boolean optionalEntity)
{
try
{
Value v1 = params.get(0 + offset).evalValue(c);
if (v1 instanceof BlockValue)
{
// pos + 0.5v
return (new Vector3Argument(Vec3d.ofCenter(((BlockValue) v1).getPos()), 1+offset)).fromBlock();
}
if (optionalEntity && v1 instanceof EntityValue)
{
Entity e = ((EntityValue) v1).getEntity();
return new Vector3Argument(e.getPos(), 1+offset).withEntity(e);
}
if (v1 instanceof ListValue)
{
List<Value> args = ((ListValue) v1).getItems();
Vec3d pos = new Vec3d(
NumericValue.asNumber(args.get(0)).getDouble(),
NumericValue.asNumber(args.get(1)).getDouble(),
NumericValue.asNumber(args.get(2)).getDouble());
double yaw = 0.0D;
double pitch = 0.0D;
if (args.size()>3 && optionalDirection)
{
yaw = NumericValue.asNumber(args.get(3)).getDouble();
pitch = NumericValue.asNumber(args.get(4)).getDouble();
}
return new Vector3Argument(pos,offset+1, yaw, pitch);
}
Vec3d pos = new Vec3d(
NumericValue.asNumber(v1).getDouble(),
NumericValue.asNumber(params.get(1 + offset).evalValue(c)).getDouble(),
NumericValue.asNumber(params.get(2 + offset).evalValue(c)).getDouble());
double yaw = 0.0D;
double pitch = 0.0D;
int eatenLength = 3;
if (params.size()>3+offset && optionalDirection)
{
yaw = NumericValue.asNumber(params.get(3 + offset).evalValue(c)).getDouble();
pitch = NumericValue.asNumber(params.get(4 + offset).evalValue(c)).getDouble();
eatenLength = 5;
}
return new Vector3Argument(pos,offset+eatenLength, yaw, pitch);
}
catch (IndexOutOfBoundsException e)
{
throw new InternalExpressionException("Position argument should be defined either by three coordinates (a triple or by three arguments), or a positioned block value");
}
}
public static Vector3Argument findIn(List<Value> params, int offset, boolean optionalDirection)
public static Vector3Argument findIn(List<Value> params, int offset, boolean optionalDirection, boolean optionalEntity)
{
try
{
@@ -115,6 +61,11 @@ public class Vector3Argument extends Argument
{
return (new Vector3Argument(Vec3d.ofCenter(((BlockValue) v1).getPos()), 1+offset)).fromBlock();
}
if (optionalEntity && v1 instanceof EntityValue)
{
Entity e = ((EntityValue) v1).getEntity();
return new Vector3Argument(e.getPos(), 1+offset).withEntity(e);
}
if (v1 instanceof ListValue)
{
List<Value> args = ((ListValue) v1).getItems();