warning cleanup

This commit is contained in:
gnembon committed 2023-02-08 21:13:15 +01:00
1 parent 5ab4a9e442
commit 277872b33c
106 files changed
+4495 -4345

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -31,7 +31,7 @@ import static java.lang.Math.min;
public class BlockIterators
{
public static void apply(final Expression expression)
public static void apply(Expression expression)
{
// lazy cause of lazy expression
expression.addLazyFunction("scan", (c, t, llv) ->
@@ -40,12 +40,12 @@ public class BlockIterators
{
throw new InternalExpressionException("'scan' needs many more arguments");
}
final List<Value> lv = Fluff.AbstractFunction.unpackLazy(llv.subList(0, llv.size() - 1), c, Context.NONE);
final CarpetContext cc = (CarpetContext) c;
final BlockArgument centerLocator = BlockArgument.findIn(cc, lv, 0);
List<Value> lv = Fluff.AbstractFunction.unpackLazy(llv.subList(0, llv.size() - 1), c, Context.NONE);
CarpetContext cc = (CarpetContext) c;
BlockArgument centerLocator = BlockArgument.findIn(cc, lv, 0);
Vector3Argument rangeLocator = Vector3Argument.findIn(lv, centerLocator.offset);
final BlockPos center = centerLocator.block.getPos();
final Vec3i range;
BlockPos center = centerLocator.block.getPos();
Vec3i range;
if (rangeLocator.fromBlock)
{
@@ -80,50 +80,50 @@ public class BlockIterators
{
throw new InternalExpressionException("'scan' takes two, or three block positions, and an expression: " + lv.size() + " " + rangeLocator.offset);
}
final LazyValue expr = llv.get(rangeLocator.offset);
LazyValue expr = llv.get(rangeLocator.offset);
final int cx = center.getX();
final int cy = center.getY();
final int cz = center.getZ();
final int xrange = range.getX();
final int yrange = range.getY();
final int zrange = range.getZ();
final int xprange = upperRange.getX();
final int yprange = upperRange.getY();
final int zprange = upperRange.getZ();
int cx = center.getX();
int cy = center.getY();
int cz = center.getZ();
int xrange = range.getX();
int yrange = range.getY();
int zrange = range.getZ();
int xprange = upperRange.getX();
int yprange = upperRange.getY();
int zprange = upperRange.getZ();
//saving outer scope
final LazyValue _x = c.getVariable("_x");
final LazyValue _y = c.getVariable("_y");
final LazyValue _z = c.getVariable("_z");
final LazyValue __ = c.getVariable("_");
LazyValue xVal = c.getVariable("_x");
LazyValue yVal = c.getVariable("_y");
LazyValue zVal = c.getVariable("_z");
LazyValue defaultVal = c.getVariable("_");
int sCount = 0;
outer:
for (int y = cy - yrange; y <= cy + yprange; y++)
{
final int yFinal = y;
c.setVariable("_y", (c_, t_) -> new NumericValue(yFinal).bindTo("_y"));
int yFinal = y;
c.setVariable("_y", (ct, tt) -> new NumericValue(yFinal).bindTo("_y"));
for (int x = cx - xrange; x <= cx + xprange; x++)
{
final int xFinal = x;
c.setVariable("_x", (c_, t_) -> new NumericValue(xFinal).bindTo("_x"));
int xFinal = x;
c.setVariable("_x", (ct, tt) -> new NumericValue(xFinal).bindTo("_x"));
for (int z = cz - zrange; z <= cz + zprange; z++)
{
final int zFinal = z;
int zFinal = z;
c.setVariable("_z", (c_, t_) -> new NumericValue(zFinal).bindTo("_z"));
final Value blockValue = BlockValue.fromCoords(((CarpetContext) c), xFinal, yFinal, zFinal).bindTo("_");
c.setVariable("_", (cc_, t_c) -> blockValue);
c.setVariable("_z", (ct, tt) -> new NumericValue(zFinal).bindTo("_z"));
Value blockValue = BlockValue.fromCoords(((CarpetContext) c), xFinal, yFinal, zFinal).bindTo("_");
c.setVariable("_", (ct, tt) -> blockValue);
Value result;
try
{
result = expr.evalValue(c, t);
}
catch (final ContinueStatement notIgnored)
catch (ContinueStatement notIgnored)
{
result = notIgnored.retval;
}
catch (final BreakStatement notIgnored)
catch (BreakStatement notIgnored)
{
break outer;
}
@@ -135,74 +135,74 @@ public class BlockIterators
}
}
//restoring outer scope
c.setVariable("_x", _x);
c.setVariable("_y", _y);
c.setVariable("_z", _z);
c.setVariable("_", __);
final int finalSCount = sCount;
return (c_, t_) -> new NumericValue(finalSCount);
c.setVariable("_x", xVal);
c.setVariable("_y", yVal);
c.setVariable("_z", zVal);
c.setVariable("_", defaultVal);
int finalSCount = sCount;
return (ct, tt) -> new NumericValue(finalSCount);
});
// must be lazy
expression.addLazyFunction("volume", (c, t, llv) ->
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
if (llv.size() < 3)
{
throw new InternalExpressionException("'volume' needs many more arguments");
}
final List<Value> lv = Fluff.AbstractFunction.unpackLazy(llv.subList(0, llv.size() - 1), c, Context.NONE);
List<Value> lv = Fluff.AbstractFunction.unpackLazy(llv.subList(0, llv.size() - 1), c, Context.NONE);
final BlockArgument pos1Locator = BlockArgument.findIn(cc, lv, 0);
final BlockArgument pos2Locator = BlockArgument.findIn(cc, lv, pos1Locator.offset);
final BlockPos pos1 = pos1Locator.block.getPos();
final BlockPos pos2 = pos2Locator.block.getPos();
BlockArgument pos1Locator = BlockArgument.findIn(cc, lv, 0);
BlockArgument pos2Locator = BlockArgument.findIn(cc, lv, pos1Locator.offset);
BlockPos pos1 = pos1Locator.block.getPos();
BlockPos pos2 = pos2Locator.block.getPos();
final int x1 = pos1.getX();
final int y1 = pos1.getY();
final int z1 = pos1.getZ();
final int x2 = pos2.getX();
final int y2 = pos2.getY();
final int z2 = pos2.getZ();
final int minx = min(x1, x2);
final int miny = min(y1, y2);
final int minz = min(z1, z2);
final int maxx = max(x1, x2);
final int maxy = max(y1, y2);
final int maxz = max(z1, z2);
final LazyValue expr = llv.get(pos2Locator.offset);
int x1 = pos1.getX();
int y1 = pos1.getY();
int z1 = pos1.getZ();
int x2 = pos2.getX();
int y2 = pos2.getY();
int z2 = pos2.getZ();
int minx = min(x1, x2);
int miny = min(y1, y2);
int minz = min(z1, z2);
int maxx = max(x1, x2);
int maxy = max(y1, y2);
int maxz = max(z1, z2);
LazyValue expr = llv.get(pos2Locator.offset);
//saving outer scope
final LazyValue _x = c.getVariable("_x");
final LazyValue _y = c.getVariable("_y");
final LazyValue _z = c.getVariable("_z");
final LazyValue __ = c.getVariable("_");
LazyValue xVal = c.getVariable("_x");
LazyValue yVal = c.getVariable("_y");
LazyValue zVal = c.getVariable("_z");
LazyValue defaultVal = c.getVariable("_");
int sCount = 0;
outer:
for (int y = miny; y <= maxy; y++)
{
final int yFinal = y;
c.setVariable("_y", (c_, t_) -> new NumericValue(yFinal).bindTo("_y"));
int yFinal = y;
c.setVariable("_y", (ct, tt) -> new NumericValue(yFinal).bindTo("_y"));
for (int x = minx; x <= maxx; x++)
{
final int xFinal = x;
c.setVariable("_x", (c_, t_) -> new NumericValue(xFinal).bindTo("_x"));
int xFinal = x;
c.setVariable("_x", (ct, tt) -> new NumericValue(xFinal).bindTo("_x"));
for (int z = minz; z <= maxz; z++)
{
final int zFinal = z;
c.setVariable("_z", (c_, t_) -> new NumericValue(zFinal).bindTo("_z"));
final Value blockValue = BlockValue.fromCoords(((CarpetContext) c), xFinal, yFinal, zFinal).bindTo("_");
c.setVariable("_", (cc_, t_c) -> blockValue);
int zFinal = z;
c.setVariable("_z", (ct, tt) -> new NumericValue(zFinal).bindTo("_z"));
Value blockValue = BlockValue.fromCoords(((CarpetContext) c), xFinal, yFinal, zFinal).bindTo("_");
c.setVariable("_", (ct, tt) -> blockValue);
Value result;
try
{
result = expr.evalValue(c, t);
}
catch (final ContinueStatement notIgnored)
catch (ContinueStatement notIgnored)
{
result = notIgnored.retval;
}
catch (final BreakStatement notIgnored)
catch (BreakStatement notIgnored)
{
break outer;
}
@@ -214,49 +214,49 @@ public class BlockIterators
}
}
//restoring outer scope
c.setVariable("_x", _x);
c.setVariable("_y", _y);
c.setVariable("_z", _z);
c.setVariable("_", __);
final int finalSCount = sCount;
return (c_, t_) -> new NumericValue(finalSCount);
c.setVariable("_x", xVal);
c.setVariable("_y", yVal);
c.setVariable("_z", zVal);
c.setVariable("_", defaultVal);
int finalSCount = sCount;
return (ct, tt) -> new NumericValue(finalSCount);
});
expression.addContextFunction("neighbours", -1, (c, t, lv) ->
{
final BlockPos center = BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos();
final ServerLevel world = ((CarpetContext) c).level();
BlockPos center = BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos();
ServerLevel world = ((CarpetContext) c).level();
final List<Value> neighbours = new ArrayList<>();
neighbours.add(new BlockValue(null, world, center.above()));
neighbours.add(new BlockValue(null, world, center.below()));
neighbours.add(new BlockValue(null, world, center.north()));
neighbours.add(new BlockValue(null, world, center.south()));
neighbours.add(new BlockValue(null, world, center.east()));
neighbours.add(new BlockValue(null, world, center.west()));
List<Value> neighbours = new ArrayList<>();
neighbours.add(new BlockValue(world, center.above()));
neighbours.add(new BlockValue(world, center.below()));
neighbours.add(new BlockValue(world, center.north()));
neighbours.add(new BlockValue(world, center.south()));
neighbours.add(new BlockValue(world, center.east()));
neighbours.add(new BlockValue(world, center.west()));
return ListValue.wrap(neighbours);
});
expression.addContextFunction("rect", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final int cx;
final int cy;
final int cz;
final int sminx;
final int sminy;
final int sminz;
final int smaxx;
final int smaxy;
final int smaxz;
final BlockArgument cposLocator = BlockArgument.findIn(cc, lv, 0);
final BlockPos cpos = cposLocator.block.getPos();
CarpetContext cc = (CarpetContext) c;
int cx;
int cy;
int cz;
int sminx;
int sminy;
int sminz;
int smaxx;
int smaxy;
int smaxz;
BlockArgument cposLocator = BlockArgument.findIn(cc, lv, 0);
BlockPos cpos = cposLocator.block.getPos();
cx = cpos.getX();
cy = cpos.getY();
cz = cpos.getZ();
if (lv.size() > cposLocator.offset)
{
final Vector3Argument diffLocator = Vector3Argument.findIn(lv, cposLocator.offset);
Vector3Argument diffLocator = Vector3Argument.findIn(lv, cposLocator.offset);
if (diffLocator.fromBlock)
{
sminx = Mth.floor(abs(diffLocator.vec.x - cx));
@@ -271,7 +271,7 @@ public class BlockIterators
}
if (lv.size() > diffLocator.offset)
{
final Vector3Argument posDiff = Vector3Argument.findIn(lv, diffLocator.offset);
Vector3Argument posDiff = Vector3Argument.findIn(lv, diffLocator.offset);
if (posDiff.fromBlock)
{
smaxx = Mth.floor(abs(posDiff.vec.x - cx));
@@ -328,7 +328,7 @@ public class BlockIterators
@Override
public Value next()
{
final Value r = BlockValue.fromCoords(cc, x, y, z);
Value r = BlockValue.fromCoords(cc, x, y, z);
//possibly reroll context
x++;
if (x > maxx)
@@ -371,16 +371,16 @@ public class BlockIterators
expression.addContextFunction("diamond", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
final BlockArgument cposLocator = BlockArgument.findIn((CarpetContext) c, lv, 0);
final BlockPos cpos = cposLocator.block.getPos();
BlockArgument cposLocator = BlockArgument.findIn((CarpetContext) c, lv, 0);
BlockPos cpos = cposLocator.block.getPos();
final int cx;
final int cy;
final int cz;
final int width;
final int height;
int cx;
int cy;
int cz;
int width;
int height;
try
{
cx = cpos.getX();
@@ -414,7 +414,7 @@ public class BlockIterators
throw new InternalExpressionException("Incorrect number of arguments for 'diamond'");
}
}
catch (final ClassCastException ignored)
catch (ClassCastException ignored)
{
throw new InternalExpressionException("Attempted to pass a non-number to 'diamond'");
}
@@ -445,7 +445,7 @@ public class BlockIterators
}
// x = 3-|i-6|
// z = |( (i-3)%12-6|-3
final Value block = BlockValue.fromCoords(cc, cx + (curradius - abs(curpos - 2 * curradius)), cy, cz - curradius + abs(abs(curpos - curradius) % (4 * curradius) - 2 * curradius));
Value block = BlockValue.fromCoords(cc, cx + (curradius - abs(curpos - 2 * curradius)), cy, cz - curradius + abs(abs(curpos - curradius) % (4 * curradius) - 2 * curradius));
curpos++;
if (curpos >= curradius * 4)
{
@@ -503,7 +503,7 @@ public class BlockIterators
// x = 3-|i-6|
// z = |( (i-3)%12-6|-3
final Value block = BlockValue.fromCoords(cc, cx + (curradius - abs(curpos - 2 * curradius)), cy + curheight, cz - curradius + abs(abs(curpos - curradius) % (4 * curradius) - 2 * curradius));
Value block = BlockValue.fromCoords(cc, cx + (curradius - abs(curpos - 2 * curradius)), cy + curheight, cz - curradius + abs(abs(curpos - curradius) % (4 * curradius) - 2 * curradius));
curpos++;
if (curpos >= curradius * 4)
{
+65 -60
View File
@@ -42,10 +42,10 @@ import net.minecraft.world.phys.Vec3;
public class Entities
{
private static ListValue getPlayersFromWorldMatching(final Context c, final Predicate<ServerPlayer> condition)
private static ListValue getPlayersFromWorldMatching(Context c, Predicate<ServerPlayer> condition)
{
final List<Value> ret = new ArrayList<>();
for (final ServerPlayer player : ((CarpetContext) c).level().players())
List<Value> ret = new ArrayList<>();
for (ServerPlayer player : ((CarpetContext) c).level().players())
{
if (condition.test(player))
{
@@ -55,45 +55,45 @@ public class Entities
return ListValue.wrap(ret);
}
public static void apply(final Expression expression)
public static void apply(Expression expression)
{
expression.addContextFunction("player", -1, (c, t, lv) ->
{
if (lv.size() == 0)
if (lv.isEmpty())
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
if (cc.host.user != null)
{
final ServerPlayer player = cc.server().getPlayerList().getPlayerByName(cc.host.user);
ServerPlayer player = cc.server().getPlayerList().getPlayerByName(cc.host.user);
return EntityValue.of(player);
}
final Entity callingEntity = cc.source().getEntity();
Entity callingEntity = cc.source().getEntity();
if (callingEntity instanceof Player)
{
return EntityValue.of(callingEntity);
}
final Vec3 pos = ((CarpetContext) c).source().getPosition();
final Player closestPlayer = ((CarpetContext) c).level().getNearestPlayer(pos.x, pos.y, pos.z, -1.0, EntitySelector.ENTITY_STILL_ALIVE);
Vec3 pos = ((CarpetContext) c).source().getPosition();
Player closestPlayer = ((CarpetContext) c).level().getNearestPlayer(pos.x, pos.y, pos.z, -1.0, EntitySelector.ENTITY_STILL_ALIVE);
return EntityValue.of(closestPlayer);
}
final String playerName = lv.get(0).getString();
String playerName = lv.get(0).getString();
return switch (playerName)
{
case "all" -> {
final List<Value> ret = new ArrayList<>();
for (final ServerPlayer player : ((CarpetContext) c).server().getPlayerList().getPlayers())
List<Value> ret = new ArrayList<>();
for (ServerPlayer player : ((CarpetContext) c).server().getPlayerList().getPlayers())
{
ret.add(new EntityValue(player));
}
yield ListValue.wrap(ret);
}
case "*" -> getPlayersFromWorldMatching(c, p -> true);
case "survival" -> getPlayersFromWorldMatching(c, p -> p.gameMode.isSurvival()); // todo assert correct
case "survival" -> getPlayersFromWorldMatching(c, p -> p.gameMode.isSurvival()); // includes adventure
case "creative" -> getPlayersFromWorldMatching(c, ServerPlayer::isCreative);
case "spectating" -> getPlayersFromWorldMatching(c, ServerPlayer::isSpectator);
case "!spectating" -> getPlayersFromWorldMatching(c, p -> !p.isSpectator());
default -> {
final ServerPlayer player = ((CarpetContext) c).server().getPlayerList().getPlayerByName(playerName);
ServerPlayer player = ((CarpetContext) c).server().getPlayerList().getPlayerByName(playerName);
yield player != null ? new EntityValue(player) : Value.NULL;
}
};
@@ -101,28 +101,28 @@ public class Entities
expression.addContextFunction("spawn", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
if (lv.size() < 2)
{
throw new InternalExpressionException("'spawn' function takes mob name, and position to spawn");
}
final String entityString = lv.get(0).getString();
final ResourceLocation entityId;
String entityString = lv.get(0).getString();
ResourceLocation entityId;
try
{
entityId = ResourceLocation.read(new StringReader(entityString));
final EntityType<? extends Entity> type = cc.registry(Registries.ENTITY_TYPE).getOptional(entityId).orElse(null);
EntityType<? extends Entity> type = cc.registry(Registries.ENTITY_TYPE).getOptional(entityId).orElse(null);
if (type == null || !type.canSummon())
{
return Value.NULL;
}
}
catch (final CommandSyntaxException ignored)
catch (CommandSyntaxException ignored)
{
return Value.NULL;
}
final Vector3Argument position = Vector3Argument.findIn(lv, 1);
Vector3Argument position = Vector3Argument.findIn(lv, 1);
if (position.fromBlock)
{
position.vec = position.vec.subtract(0, 0.5, 0);
@@ -131,20 +131,20 @@ public class Entities
boolean hasTag = false;
if (lv.size() > position.offset)
{
final Value nbt = lv.get(position.offset);
final NBTSerializableValue v = (nbt instanceof final NBTSerializableValue nbtsv)
Value nbt = lv.get(position.offset);
NBTSerializableValue v = (nbt instanceof final NBTSerializableValue nbtsv)
? nbtsv
: NBTSerializableValue.parseString(nbt.getString(), true);
: NBTSerializableValue.parseStringOrFail(nbt.getString());
hasTag = true;
tag = v.getCompoundTag();
}
tag.putString("id", entityId.toString());
final Vec3 vec3d = position.vec;
Vec3 vec3d = position.vec;
final ServerLevel serverWorld = cc.level();
final Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, e -> {
ServerLevel serverWorld = cc.level();
Entity entity = EntityType.loadEntityRecursive(tag, serverWorld, e -> {
e.moveTo(vec3d.x, vec3d.y, vec3d.z, e.getYRot(), e.getXRot());
return !serverWorld.addWithUUID(e) ? null : e;
return e;
});
if (entity == null)
{
@@ -154,12 +154,17 @@ public class Entities
{
mob.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null, null);
}
if (!serverWorld.tryAddFreshEntityWithPassengers(entity))
{
entity.discard();
return Value.NULL;
}
return new EntityValue(entity);
});
expression.addContextFunction("entity_id", 1, (c, t, lv) ->
{
final Value who = lv.get(0);
Value who = lv.get(0);
if (who instanceof final NumericValue numericValue)
{
return EntityValue.of(((CarpetContext) c).level().getEntity((int) numericValue.getLong()));
@@ -169,10 +174,10 @@ public class Entities
expression.addContextFunction("entity_list", 1, (c, t, lv) ->
{
final String who = lv.get(0).getString();
final CommandSourceStack source = ((CarpetContext) c).source();
final EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
final List<? extends Entity> entityList = source.getLevel().getEntities(eDesc.directType, eDesc.filteringPredicate);
String who = lv.get(0).getString();
CommandSourceStack source = ((CarpetContext) c).source();
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
List<? extends Entity> entityList = source.getLevel().getEntities(eDesc.directType, eDesc.filteringPredicate);
return ListValue.wrap(entityList.stream().map(EntityValue::new));
});
@@ -182,41 +187,41 @@ public class Entities
{
throw new InternalExpressionException("'entity_area' requires entity type, center and range arguments");
}
final String who = lv.get(0).getString();
final CarpetContext cc = (CarpetContext) c;
final Vector3Argument centerLocator = Vector3Argument.findIn(lv, 1, false, true);
String who = lv.get(0).getString();
CarpetContext cc = (CarpetContext) c;
Vector3Argument centerLocator = Vector3Argument.findIn(lv, 1, false, true);
final AABB centerBox;
AABB centerBox;
if (centerLocator.entity != null)
{
centerBox = centerLocator.entity.getBoundingBox();
}
else
{
final Vec3 center = centerLocator.vec;
Vec3 center = centerLocator.vec;
if (centerLocator.fromBlock)
{
center.add(0.5, 0.5, 0.5);
}
centerBox = new AABB(center, center);
}
final Vector3Argument rangeLocator = Vector3Argument.findIn(lv, centerLocator.offset);
Vector3Argument rangeLocator = Vector3Argument.findIn(lv, centerLocator.offset);
if (rangeLocator.fromBlock)
{
throw new InternalExpressionException("Range of 'entity_area' cannot come from a block argument");
}
final Vec3 range = rangeLocator.vec;
final AABB area = centerBox.inflate(range.x, range.y, range.z);
final EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.server());
final List<? extends Entity> entityList = cc.level().getEntities(eDesc.directType, area, eDesc.filteringPredicate);
Vec3 range = rangeLocator.vec;
AABB area = centerBox.inflate(range.x, range.y, range.z);
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.server());
List<? extends Entity> entityList = cc.level().getEntities(eDesc.directType, area, eDesc.filteringPredicate);
return ListValue.wrap(entityList.stream().map(EntityValue::new));
});
expression.addContextFunction("entity_selector", -1, (c, t, lv) ->
{
final String selector = lv.get(0).getString();
final List<Value> retlist = new ArrayList<>();
for (final Entity e : EntityValue.getEntitiesFromSelector(((CarpetContext) c).source(), selector))
String selector = lv.get(0).getString();
List<Value> retlist = new ArrayList<>();
for (Entity e : EntityValue.getEntitiesFromSelector(((CarpetContext) c).source(), selector))
{
retlist.add(new EntityValue(e));
}
@@ -229,12 +234,12 @@ public class Entities
{
throw new InternalExpressionException("'query' takes entity as a first argument, and queried feature as a second");
}
final Value v = lv.get(0);
Value v = lv.get(0);
if (!(v instanceof final EntityValue ev))
{
throw new InternalExpressionException("First argument to query should be an entity");
}
final String what = lv.get(1).getString().toLowerCase(Locale.ROOT);
String what = lv.get(1).getString().toLowerCase(Locale.ROOT);
if (what.equals("tags"))
{
c.host.issueDeprecation("'tags' for entity querying");
@@ -254,12 +259,12 @@ public class Entities
{
throw new InternalExpressionException("'modify' takes entity as a first argument, and queried feature as a second");
}
final Value v = lv.get(0);
Value v = lv.get(0);
if (!(v instanceof final EntityValue ev))
{
throw new InternalExpressionException("First argument to modify should be an entity");
}
final String what = lv.get(1).getString();
String what = lv.get(1).getString();
switch (lv.size())
{
case 2 -> ev.set(what, null);
@@ -275,7 +280,7 @@ public class Entities
{
throw new InternalExpressionException("'entity_types' requires one or no arguments");
}
final String desc = (lv.size() == 1) ? lv.get(0).getString() : "*";
String desc = (lv.size() == 1) ? lv.get(0).getString() : "*";
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).server()).listValue(((CarpetContext) c).registryAccess());
});
@@ -285,14 +290,14 @@ public class Entities
{
throw new InternalExpressionException("'entity_load_handler' required the entity type, and a function to call");
}
final Value entityValue = lv.get(0);
final List<String> descriptors = (entityValue instanceof final ListValue list)
Value entityValue = lv.get(0);
List<String> descriptors = (entityValue instanceof final ListValue list)
? list.getItems().stream().map(Value::getString).toList()
: Collections.singletonList(entityValue.getString());
final Set<EntityType<? extends Entity>> types = new HashSet<>();
Set<EntityType<? extends Entity>> types = new HashSet<>();
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).server()).types));
final FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
final CarpetEventServer events = ((CarpetScriptHost) c.host).scriptServer().events;
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
CarpetEventServer events = ((CarpetScriptHost) c.host).scriptServer().events;
if (funArg.function == null)
{
types.forEach(et -> events.removeBuiltInEvent(CarpetEventServer.Event.getEntityLoadEventName(et), (CarpetScriptHost) c.host));
@@ -301,7 +306,7 @@ public class Entities
else
{
///compat
final int numberOfArguments = funArg.function.getArguments().size() - funArg.args.size();
int numberOfArguments = funArg.function.getArguments().size() - funArg.args.size();
if (numberOfArguments == 1)
{
c.host.issueDeprecation("entity_load_handler() with single argument callback");
@@ -322,14 +327,14 @@ public class Entities
{
throw new InternalExpressionException("'entity_event' requires at least 3 arguments, entity, event to be handled, and function name, with optional arguments");
}
final Value v = lv.get(0);
Value v = lv.get(0);
if (!(v instanceof final EntityValue ev))
{
throw new InternalExpressionException("First argument to entity_event should be an entity");
}
final String what = lv.get(1).getString();
String what = lv.get(1).getString();
final FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 2, true, false);
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 2, true, false);
ev.setEvent((CarpetContext) c, what, funArg.function, funArg.args);
@@ -24,6 +24,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -54,7 +55,7 @@ import net.minecraft.world.phys.Vec3;
public class Inventories
{
public static void apply(final Expression expression)
public static void apply(Expression expression)
{
expression.addContextFunction("stack_limit", 1, (c, t, lv) ->
new NumericValue(NBTSerializableValue.parseItem(lv.get(0).getString(), ((CarpetContext) c).registryAccess()).getItem().getMaxStackSize()));
@@ -66,78 +67,82 @@ public class Inventories
expression.addContextFunction("item_list", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final Registry<Item> items = cc.registry(Registries.ITEM);
if (lv.size() == 0)
CarpetContext cc = (CarpetContext) c;
Registry<Item> items = cc.registry(Registries.ITEM);
if (lv.isEmpty())
{
return ListValue.wrap(items.keySet().stream().map(ValueConversions::of));
}
final String tag = lv.get(0).getString();
final Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
return itemTag.isEmpty() ? Value.NULL : ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))));
String tag = lv.get(0).getString();
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
return itemTag.isEmpty() ? Value.NULL : ListValue.wrap(itemTag.get().stream().map(b -> items.getKey(b.value())).filter(Objects::nonNull).map(ValueConversions::of));
});
expression.addContextFunction("item_tags", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
final Registry<Item> blocks = cc.registry(Registries.ITEM);
if (lv.size() == 0)
Registry<Item> blocks = cc.registry(Registries.ITEM);
if (lv.isEmpty())
{
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of));
}
final Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
if (lv.size() == 1)
{
return ListValue.wrap(blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())));
}
final String tag = lv.get(1).getString();
final Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
String tag = lv.get(1).getString();
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
return tagSet.isEmpty() ? Value.NULL : BooleanValue.of(tagSet.get().stream().anyMatch(h -> h.value() == item));
});
expression.addContextFunction("recipe_data", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
CarpetContext cc = (CarpetContext) c;
if (lv.size() < 1)
{
throw new InternalExpressionException("'recipe_data' requires at least one argument");
}
final String recipeName = lv.get(0).getString();
String recipeName = lv.get(0).getString();
RecipeType<?> type = RecipeType.CRAFTING;
if (lv.size() > 1)
{
final String recipeType = lv.get(1).getString();
String recipeType = lv.get(1).getString();
type = cc.registry(Registries.RECIPE_TYPE).get(InputValidator.identifierOf(recipeType));
if (type == null)
{
throw new InternalExpressionException("Unknown recipe type: "+recipeType);
}
}
final List<Recipe<?>> recipes = Vanilla.RecipeManager_getAllMatching(cc.server().getRecipeManager(), type, InputValidator.identifierOf(recipeName), cc.registryAccess());
List<Recipe<?>> recipes = Vanilla.RecipeManager_getAllMatching(cc.server().getRecipeManager(), type, InputValidator.identifierOf(recipeName), cc.registryAccess());
if (recipes.isEmpty())
{
return Value.NULL;
}
final List<Value> recipesOutput = new ArrayList<>();
final RegistryAccess regs = cc.registryAccess();
for (final Recipe<?> recipe : recipes)
List<Value> recipesOutput = new ArrayList<>();
RegistryAccess regs = cc.registryAccess();
for (Recipe<?> recipe : recipes)
{
final ItemStack result = recipe.getResultItem(regs);
final List<Value> ingredientValue = new ArrayList<>();
ItemStack result = recipe.getResultItem(regs);
List<Value> ingredientValue = new ArrayList<>();
recipe.getIngredients().forEach( ingredient -> {
// I am flattening ingredient lists per slot.
// consider recipe_data('wooden_sword','crafting') and ('iron_nugget', 'blasting') and notice difference
// in depths of lists.
final List<Collection<ItemStack>> stacks = Vanilla.Ingredient_getRecipeStacks(ingredient);
List<Collection<ItemStack>> stacks = Vanilla.Ingredient_getRecipeStacks(ingredient);
if (stacks.isEmpty())
{
ingredientValue.add(Value.NULL);
}
else
{
final List<Value> alternatives = new ArrayList<>();
List<Value> alternatives = new ArrayList<>();
stacks.forEach(col -> col.stream().map(is -> ValueConversions.of(is, regs)).forEach(alternatives::add));
ingredientValue.add(ListValue.wrap(alternatives));
}
});
final Value recipeSpec;
Value recipeSpec;
if (recipe instanceof final ShapedRecipe shapedRecipe)
{
recipeSpec = ListValue.of(
@@ -178,42 +183,41 @@ public class Inventories
expression.addContextFunction("crafting_remaining_item", 1, (c, t, v) ->
{
final String itemStr = v.get(0).getString();
final ResourceLocation id = InputValidator.identifierOf(itemStr);
final Registry<Item> registry = ((CarpetContext) c).registry(Registries.ITEM);
final Item item = registry.getOptional(id).orElseThrow(() -> new ThrowStatement(itemStr, Throwables.UNKNOWN_ITEM));
return !item.hasCraftingRemainingItem()
? Value.NULL
: new StringValue(NBTSerializableValue.nameFromRegistryId(registry.getKey(item.getCraftingRemainingItem())));
String itemStr = v.get(0).getString();
ResourceLocation id = InputValidator.identifierOf(itemStr);
Registry<Item> registry = ((CarpetContext) c).registry(Registries.ITEM);
Item item = registry.getOptional(id).orElseThrow(() -> new ThrowStatement(itemStr, Throwables.UNKNOWN_ITEM));
Item reminder = item.getCraftingRemainingItem();
return reminder == null ? Value.NULL : NBTSerializableValue.nameFromRegistryId(registry.getKey(reminder));
});
expression.addContextFunction("inventory_size", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
return inventoryLocator == null ? Value.NULL : new NumericValue(inventoryLocator.inventory().getContainerSize());
});
expression.addContextFunction("inventory_has_items", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
return inventoryLocator == null ? Value.NULL : BooleanValue.of(!inventoryLocator.inventory().isEmpty());
});
//inventory_get(<b, e>, <n>) -> item_triple
expression.addContextFunction("inventory_get", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
{
return Value.NULL;
}
final RegistryAccess regs = cc.registryAccess();
RegistryAccess regs = cc.registryAccess();
if (lv.size() == inventoryLocator.offset())
{
final List<Value> fullInventory = new ArrayList<>();
List<Value> fullInventory = new ArrayList<>();
for (int i = 0, maxi = inventoryLocator.inventory().getContainerSize(); i < maxi; i++)
{
fullInventory.add(ValueConversions.of(inventoryLocator.inventory().getItem(i), regs));
@@ -230,8 +234,8 @@ public class Inventories
//inventory_set(<b,e>, <n>, <count>, <item>, <nbt>)
expression.addContextFunction("inventory_set", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
{
return Value.NULL;
@@ -240,25 +244,25 @@ public class Inventories
{
throw new InternalExpressionException("'inventory_set' requires at least slot number and new stack size, and optional new item");
}
int slot = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset() + 0)).getLong();
int slot = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset())).getLong();
slot = NBTSerializableValue.validateSlot(slot, inventoryLocator.inventory());
if (slot == inventoryLocator.inventory().getContainerSize())
{
return Value.NULL;
}
final int count = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset() + 1)).getLong();
final RegistryAccess regs = cc.registryAccess();
int count = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset() + 1)).getLong();
RegistryAccess regs = cc.registryAccess();
if (count == 0)
{
// clear slot
final ItemStack removedStack = inventoryLocator.inventory().removeItemNoUpdate(slot);
ItemStack removedStack = inventoryLocator.inventory().removeItemNoUpdate(slot);
syncPlayerInventory(inventoryLocator, slot);
return ValueConversions.of(removedStack, regs);
}
if (lv.size() < inventoryLocator.offset() + 3)
{
final ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
final ItemStack newStack = previousStack.copy();
ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
ItemStack newStack = previousStack.copy();
newStack.setCount(count);
inventoryLocator.inventory().setItem(slot, newStack);
syncPlayerInventory(inventoryLocator, slot);
@@ -267,28 +271,24 @@ public class Inventories
CompoundTag nbt = null; // skipping one argument
if (lv.size() > inventoryLocator.offset() + 3)
{
final Value nbtValue = lv.get(inventoryLocator.offset() + 3);
Value nbtValue = lv.get(inventoryLocator.offset() + 3);
if (nbtValue instanceof final NBTSerializableValue nbtsv)
{
nbt = nbtsv.getCompoundTag();
}
else if (nbtValue.isNull())
{
nbt = null;
}
else
else if (!nbtValue.isNull())
{
nbt = new NBTSerializableValue(nbtValue.getString()).getCompoundTag();
}
}
final ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset() + 2).getString(), nbt, cc.registryAccess());
final ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset() + 2).getString(), nbt, cc.registryAccess());
ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
try
{
inventoryLocator.inventory().setItem(slot, newitem.createItemStack(count, false));
syncPlayerInventory(inventoryLocator, slot);
}
catch (final CommandSyntaxException e)
catch (CommandSyntaxException e)
{
throw new InternalExpressionException(e.getMessage());
}
@@ -298,8 +298,8 @@ public class Inventories
//inventory_find(<b, e>, <item> or null (first empty slot), <start_from=0> ) -> <N> or null
expression.addContextFunction("inventory_find", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
{
return Value.NULL;
@@ -307,7 +307,7 @@ public class Inventories
ItemInput itemArg = null;
if (lv.size() > inventoryLocator.offset())
{
final Value secondArg = lv.get(inventoryLocator.offset() + 0);
Value secondArg = lv.get(inventoryLocator.offset());
if (!secondArg.isNull())
{
itemArg = NBTSerializableValue.parseItem(secondArg.getString(), cc.registryAccess());
@@ -321,7 +321,7 @@ public class Inventories
startIndex = NBTSerializableValue.validateSlot(startIndex, inventoryLocator.inventory());
for (int i = startIndex, maxi = inventoryLocator.inventory().getContainerSize(); i < maxi; i++)
{
final ItemStack stack = inventoryLocator.inventory().getItem(i);
ItemStack stack = inventoryLocator.inventory().getItem(i);
if ((itemArg == null && stack.isEmpty()) || (itemArg != null && itemArg.getItem().equals(stack.getItem())))
{
return new NumericValue(i);
@@ -333,8 +333,8 @@ public class Inventories
//inventory_remove(<b, e>, <item>, <amount=1>) -> bool
expression.addContextFunction("inventory_remove", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
{
return Value.NULL;
@@ -343,7 +343,7 @@ public class Inventories
{
throw new InternalExpressionException("'inventory_remove' requires at least an item to be removed");
}
final ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString(), cc.registryAccess());
ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString(), cc.registryAccess());
int amount = 1;
if (lv.size() > inventoryLocator.offset() + 1)
{
@@ -357,12 +357,12 @@ public class Inventories
}
for (int i = 0, maxi = inventoryLocator.inventory().getContainerSize(); i < maxi; i++)
{
final ItemStack stack = inventoryLocator.inventory().getItem(i);
ItemStack stack = inventoryLocator.inventory().getItem(i);
if (stack.isEmpty() || !stack.getItem().equals(searchItem.getItem()))
{
continue;
}
final int left = stack.getCount() - amount;
int left = stack.getCount() - amount;
if (left > 0)
{
stack.setCount(left);
@@ -384,8 +384,8 @@ public class Inventories
//inventory_drop(<b, e>, <n>, <amount=1, 0-whatever's there>) -> entity_item (and sets slot) or null if cannot
expression.addContextFunction("drop_item", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
{
return Value.NULL;
@@ -409,7 +409,7 @@ public class Inventories
{
throw new InternalExpressionException("Cannot throw negative number of items");
}
final ItemStack stack = inventoryLocator.inventory().getItem(slot);
ItemStack stack = inventoryLocator.inventory().getItem(slot);
if (stack == null || stack.isEmpty())
{
return Value.ZERO;
@@ -418,30 +418,34 @@ public class Inventories
{
amount = stack.getCount();
}
final ItemStack droppedStack = inventoryLocator.inventory().removeItem(slot, amount);
ItemStack droppedStack = inventoryLocator.inventory().removeItem(slot, amount);
if (droppedStack.isEmpty())
{
return Value.ZERO;
}
final Object owner = inventoryLocator.owner();
final ItemEntity item;
Object owner = inventoryLocator.owner();
ItemEntity item;
if (owner instanceof final Player player)
{
item = player.drop(droppedStack, false, true);
if (item == null)
{
return Value.ZERO;
}
}
else if (owner instanceof LivingEntity livingEntity)
{
// stolen from LookTargetUtil.give((VillagerEntity)owner, droppedStack, (LivingEntity) owner);
double double_1 = livingEntity.getY() - 0.30000001192092896D + livingEntity.getEyeHeight();
item = new ItemEntity(livingEntity.level, livingEntity.getX(), double_1, livingEntity.getZ(), droppedStack);
final Vec3 vec3d = livingEntity.getViewVector(1.0F).normalize().scale(0.3);// new Vec3d(0, 0.3, 0);
double dropY = livingEntity.getY() - 0.30000001192092896D + livingEntity.getEyeHeight();
item = new ItemEntity(livingEntity.level, livingEntity.getX(), dropY, livingEntity.getZ(), droppedStack);
Vec3 vec3d = livingEntity.getViewVector(1.0F).normalize().scale(0.3);// new Vec3d(0, 0.3, 0);
item.setDeltaMovement(vec3d);
item.setDefaultPickUpDelay();
cc.level().addFreshEntity(item);
}
else
{
final Vec3 point = Vec3.atCenterOf(inventoryLocator.position()); //pos+0.5v
Vec3 point = Vec3.atCenterOf(inventoryLocator.position()); //pos+0.5v
item = new ItemEntity(cc.level(), point.x, point.y, point.z, droppedStack);
item.setDefaultPickUpDelay();
cc.level().addFreshEntity(item);
@@ -455,14 +459,14 @@ public class Inventories
{
throw new InternalExpressionException("'create_screen' requires at least three arguments");
}
final Value playerValue = lv.get(0);
final ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), playerValue);
Value playerValue = lv.get(0);
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), playerValue);
if (player == null)
{
throw new InternalExpressionException("'create_screen' requires a valid online player as the first argument.");
}
final String type = lv.get(1).getString();
final Component name = FormattedTextValue.getTextByValue(lv.get(2));
String type = lv.get(1).getString();
Component name = FormattedTextValue.getTextByValue(lv.get(2));
FunctionValue function = null;
if (lv.size() > 3)
{
@@ -474,7 +478,7 @@ public class Inventories
expression.addContextFunction("close_screen", 1, (c, t, lv) ->
{
final Value value = lv.get(0);
Value value = lv.get(0);
if (!(value instanceof final ScreenValue screenValue))
{
throw new InternalExpressionException("'close_screen' requires a screen value as the first argument.");
@@ -497,21 +501,21 @@ public class Inventories
{
throw new InternalExpressionException("'screen_property' requires a screen value as the first argument");
}
final String propertyName = lv.get(1).getString();
String propertyName = lv.get(1).getString();
return lv.size() >= 3
? screenValue.modifyProperty(propertyName, lv.subList(2, lv.size()))
: screenValue.queryProperty(propertyName);
});
}
private static void syncPlayerInventory(final NBTSerializableValue.InventoryLocator inventory, final int int_1)
private static void syncPlayerInventory(NBTSerializableValue.InventoryLocator inventory, int slot)
{
if (inventory.owner() instanceof final ServerPlayer player && !inventory.isEnder() && !(inventory.inventory() instanceof ScreenValue.ScreenHandlerInventory))
{
player.connection.send(new ClientboundContainerSetSlotPacket(
-2, 0, // resolve mystery argument
int_1,
inventory.inventory().getItem(int_1)
slot,
inventory.inventory().getItem(slot)
));
}
}
+16 -16
View File
@@ -27,18 +27,18 @@ public class Monitoring
{
private static final Map<String, MobCategory> MOB_CATEGORY_MAP = Arrays.stream(MobCategory.values()).collect(Collectors.toMap(MobCategory::getName, Function.identity()));
public static void apply(final Expression expression)
public static void apply(Expression expression)
{
expression.addContextFunction("system_info", -1, (c, t, lv) ->
{
if (lv.size() == 0)
if (lv.isEmpty())
{
return SystemInfo.getAll();
}
if (lv.size() == 1)
{
final String what = lv.get(0).getString();
final Value res = SystemInfo.get(what, (CarpetContext) c);
String what = lv.get(0).getString();
Value res = SystemInfo.get(what, (CarpetContext) c);
if (res == null)
{
throw new InternalExpressionException("Unknown option for 'system_info': " + what);
@@ -50,21 +50,21 @@ public class Monitoring
// game processed snooper functions
expression.addContextFunction("get_mob_counts", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final ServerLevel world = cc.level();
final NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState();
CarpetContext cc = (CarpetContext) c;
ServerLevel world = cc.level();
NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState();
if (info == null)
{
return Value.NULL;
}
final Object2IntMap<MobCategory> mobcounts = info.getMobCategoryCounts();
final int chunks = info.getSpawnableChunkCount();
if (lv.size() == 0)
Object2IntMap<MobCategory> mobcounts = info.getMobCategoryCounts();
int chunks = info.getSpawnableChunkCount();
if (lv.isEmpty())
{
final Map<Value, Value> retDict = new HashMap<>();
for (final MobCategory category : mobcounts.keySet())
Map<Value, Value> retDict = new HashMap<>();
for (MobCategory category : mobcounts.keySet())
{
final int currentCap = category.getMaxInstancesPerChunk() * chunks / Vanilla.NaturalSpawner_MAGIC_NUMBER();
int currentCap = category.getMaxInstancesPerChunk() * chunks / Vanilla.NaturalSpawner_MAGIC_NUMBER();
retDict.put(
new StringValue(category.getSerializedName().toLowerCase(Locale.ROOT)),
ListValue.of(
@@ -74,15 +74,15 @@ public class Monitoring
}
return MapValue.wrap(retDict);
}
final String catString = lv.get(0).getString();
final MobCategory cat = MOB_CATEGORY_MAP.get(catString.toLowerCase(Locale.ROOT));
String catString = lv.get(0).getString();
MobCategory cat = MOB_CATEGORY_MAP.get(catString.toLowerCase(Locale.ROOT));
if (cat == null)
{
throw new InternalExpressionException("Unreconized mob category: " + catString);
}
return ListValue.of(
new NumericValue(mobcounts.getInt(cat)),
new NumericValue((int) (cat.getMaxInstancesPerChunk() * chunks / Vanilla.NaturalSpawner_MAGIC_NUMBER()))
new NumericValue((long) cat.getMaxInstancesPerChunk() * chunks / Vanilla.NaturalSpawner_MAGIC_NUMBER())
);
});
}
@@ -38,30 +38,30 @@ import net.minecraft.world.scores.criteria.ObjectiveCriteria;
public class Scoreboards
{
private static String getScoreboardKeyFromValue(final Value keyValue)
private static String getScoreboardKeyFromValue(Value keyValue)
{
if (keyValue instanceof final EntityValue ev)
{
final Entity e = ev.getEntity();
Entity e = ev.getEntity();
return e instanceof Player ? e.getName().getString() : e.getStringUUID();
}
return keyValue.getString();
}
public static void apply(final Expression expression)
public static void apply(Expression expression)
{
// scoreboard(player,'objective')
// scoreboard(player, objective, newValue)
expression.addContextFunction("scoreboard", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final Scoreboard scoreboard = cc.server().getScoreboard();
if (lv.size() == 0)
CarpetContext cc = (CarpetContext) c;
Scoreboard scoreboard = cc.server().getScoreboard();
if (lv.isEmpty())
{
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new));
}
final String objectiveName = lv.get(0).getString();
final Objective objective = scoreboard.getOrCreateObjective(objectiveName);
String objectiveName = lv.get(0).getString();
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
if (objective == null)
{
return Value.NULL;
@@ -70,7 +70,7 @@ public class Scoreboards
{
return ListValue.wrap(scoreboard.getPlayerScores(objective).stream().map(s -> new StringValue(s.getOwner())));
}
final String key = getScoreboardKeyFromValue(lv.get(1));
String key = getScoreboardKeyFromValue(lv.get(1));
if (lv.size() == 2)
{
return !scoreboard.hasPlayerScore(key, objective)
@@ -78,16 +78,16 @@ public class Scoreboards
: NumericValue.of(scoreboard.getOrCreatePlayerScore(key, objective).getScore());
}
final Value value = lv.get(2);
Value value = lv.get(2);
if (value.isNull())
{
final Score score = scoreboard.getOrCreatePlayerScore(key, objective);
Score score = scoreboard.getOrCreatePlayerScore(key, objective);
scoreboard.resetPlayerScore(key, objective);
return NumericValue.of(score.getScore());
}
if (value instanceof NumericValue)
{
final Score score = scoreboard.getOrCreatePlayerScore(key, objective);
Score score = scoreboard.getOrCreatePlayerScore(key, objective);
score.setScore(NumericValue.asNumber(value).getInt());
return NumericValue.of(score.getScore());
}
@@ -96,14 +96,14 @@ public class Scoreboards
expression.addContextFunction("scoreboard_remove", -1, (c, t, lv) ->
{
if (lv.size() == 0)
if (lv.isEmpty())
{
throw new InternalExpressionException("'scoreboard_remove' requires at least one parameter");
}
final CarpetContext cc = (CarpetContext) c;
final Scoreboard scoreboard = cc.server().getScoreboard();
final String objectiveName = lv.get(0).getString();
final Objective objective = scoreboard.getOrCreateObjective(objectiveName);
CarpetContext cc = (CarpetContext) c;
Scoreboard scoreboard = cc.server().getScoreboard();
String objectiveName = lv.get(0).getString();
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
if (objective == null)
{
return Value.FALSE;
@@ -113,13 +113,13 @@ public class Scoreboards
scoreboard.removeObjective(objective);
return Value.TRUE;
}
final String key = getScoreboardKeyFromValue(lv.get(1));
String key = getScoreboardKeyFromValue(lv.get(1));
if (!scoreboard.hasPlayerScore(key, objective))
{
return Value.NULL;
}
final Score scoreboardPlayerScore = scoreboard.getOrCreatePlayerScore(key, objective);
final Value previous = new NumericValue(scoreboardPlayerScore.getScore());
Score scoreboardPlayerScore = scoreboard.getOrCreatePlayerScore(key, objective);
Value previous = new NumericValue(scoreboardPlayerScore.getScore());
scoreboard.resetPlayerScore(key, objective);
return previous;
});
@@ -129,21 +129,21 @@ public class Scoreboards
expression.addContextFunction("scoreboard_add", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final Scoreboard scoreboard = cc.server().getScoreboard();
if (lv.size() == 0 || lv.size() > 2)
CarpetContext cc = (CarpetContext) c;
Scoreboard scoreboard = cc.server().getScoreboard();
if (lv.isEmpty() || lv.size() > 2)
{
throw new InternalExpressionException("'scoreboard_add' should have one or two parameters");
}
final String objectiveName = lv.get(0).getString();
final ObjectiveCriteria criterion;
String objectiveName = lv.get(0).getString();
ObjectiveCriteria criterion;
if (lv.size() == 1)
{
criterion = ObjectiveCriteria.DUMMY;
}
else
{
final String critetionName = lv.get(1).getString();
String critetionName = lv.get(1).getString();
criterion = ObjectiveCriteria.byName(critetionName).orElse(null);
if (criterion == null)
{
@@ -151,7 +151,7 @@ public class Scoreboards
}
}
final Objective objective = scoreboard.getOrCreateObjective(objectiveName);
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
if (objective != null)
{
c.host.issueDeprecation("reading or modifying an objective's criterion with scoreboard_add");
@@ -165,7 +165,7 @@ public class Scoreboards
}
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).get(objective.getCriteria()).remove(objective);
Vanilla.Objective_setCriterion(objective, criterion);
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, (criterion1) -> Lists.newArrayList())).add(objective);
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList())).add(objective);
scoreboard.onObjectiveAdded(objective);
return Value.FALSE;
}
@@ -179,27 +179,27 @@ public class Scoreboards
{
throw new InternalExpressionException("'scoreboard_property' requires at least two parameters");
}
final CarpetContext cc = (CarpetContext) c;
final Scoreboard scoreboard = cc.server().getScoreboard();
final Objective objective = scoreboard.getOrCreateObjective(lv.get(0).getString());
CarpetContext cc = (CarpetContext) c;
Scoreboard scoreboard = cc.server().getScoreboard();
Objective objective = scoreboard.getOrCreateObjective(lv.get(0).getString());
if (objective == null)
{
return Value.NULL;
}
final boolean modify = lv.size() > 2;
boolean modify = lv.size() > 2;
Value setValue = null;
if (modify)
{
setValue = lv.get(2);
}
final String property = lv.get(1).getString();
String property = lv.get(1).getString();
switch (property)
{
case "criterion" -> {
if (modify)
{
final ObjectiveCriteria criterion = ObjectiveCriteria.byName(setValue.getString()).orElse(null);
ObjectiveCriteria criterion = ObjectiveCriteria.byName(setValue.getString()).orElse(null);
if (criterion == null)
{
throw new InternalExpressionException("Unknown scoreboard criterion: " + setValue.getString());
@@ -210,7 +210,7 @@ public class Scoreboards
}
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).get(objective.getCriteria()).remove(objective);
Vanilla.Objective_setCriterion(objective, criterion);
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, (criterion1) -> Lists.newArrayList())).add(objective);
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList())).add(objective);
scoreboard.onObjectiveAdded(objective);
return Value.TRUE;
}
@@ -219,7 +219,7 @@ public class Scoreboards
case "display_name" -> {
if (modify)
{
final Component text = FormattedTextValue.getTextByValue(setValue);
Component text = FormattedTextValue.getTextByValue(setValue);
objective.setDisplayName(text);
return Value.TRUE;
}
@@ -228,7 +228,7 @@ public class Scoreboards
case "display_slot" -> {
if (modify)
{
final int slotId = Scoreboard.getDisplaySlotByName(setValue.getString());
int slotId = Scoreboard.getDisplaySlotByName(setValue.getString());
if (slotId == -1)
{
throw new InternalExpressionException("Unknown scoreboard display slot: " + setValue.getString());
@@ -240,12 +240,12 @@ public class Scoreboards
scoreboard.setDisplayObjective(slotId, objective);
return Value.TRUE;
}
final List<Value> slots = new ArrayList<>();
List<Value> slots = new ArrayList<>();
for (int i = 0; i < 19; i++)
{
if (scoreboard.getDisplayObjective(i) == objective)
{
final String slotName = Scoreboard.getDisplaySlotName(i);
String slotName = Scoreboard.getDisplaySlotName(i);
slots.add(StringValue.of(slotName));
}
}
@@ -254,7 +254,7 @@ public class Scoreboards
case "render_type" -> {
if (modify)
{
final ObjectiveCriteria.RenderType renderType = ObjectiveCriteria.RenderType.byId(setValue.getString().toLowerCase());
ObjectiveCriteria.RenderType renderType = ObjectiveCriteria.RenderType.byId(setValue.getString().toLowerCase());
if (objective.getRenderType().equals(renderType))
{
return Value.FALSE;
@@ -270,22 +270,22 @@ public class Scoreboards
expression.addContextFunction("scoreboard_display", 2, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final Scoreboard scoreboard = cc.server().getScoreboard();
final String location = lv.get(0).getString();
final int slot = Scoreboard.getDisplaySlotByName(location);
CarpetContext cc = (CarpetContext) c;
Scoreboard scoreboard = cc.server().getScoreboard();
String location = lv.get(0).getString();
int slot = Scoreboard.getDisplaySlotByName(location);
if (slot < 0)
{
throw new InternalExpressionException("Invalid objective slot: " + location);
}
final Value target = lv.get(1);
Value target = lv.get(1);
if (target.isNull())
{
scoreboard.setDisplayObjective(slot, null);
return new NumericValue(slot);
}
final String objectiveString = target.getString();
final Objective objective = scoreboard.getOrCreateObjective(objectiveString);
String objectiveString = target.getString();
Objective objective = scoreboard.getOrCreateObjective(objectiveString);
if (objective == null)
{
return Value.NULL;
@@ -300,9 +300,9 @@ public class Scoreboards
{
throw new InternalExpressionException("'team_list' requires zero or one parameters");
}
final CarpetContext cc = (CarpetContext) c;
final ServerScoreboard scoreboard = cc.server().getScoreboard();
if (lv.size() == 0)
CarpetContext cc = (CarpetContext) c;
ServerScoreboard scoreboard = cc.server().getScoreboard();
if (lv.isEmpty())
{
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of));
}
@@ -310,21 +310,21 @@ public class Scoreboards
{
return Value.NULL;
}
final PlayerTeam team = scoreboard.getPlayerTeam(lv.get(0).getString());
PlayerTeam team = scoreboard.getPlayerTeam(lv.get(0).getString());
return team == null ? Value.NULL : ListValue.wrap(team.getPlayers().stream().map(StringValue::of));
});
expression.addContextFunction("team_add", -1, (c, t, lv) ->
{
if (!(lv.size() < 3 && lv.size() > 0))
if (!(lv.size() < 3 && !lv.isEmpty()))
{
throw new InternalExpressionException("'team_add' requires one or two parameters");
}
final CarpetContext cc = (CarpetContext) c;
final ServerScoreboard scoreboard = cc.server().getScoreboard();
final String teamName = lv.get(0).getString();
CarpetContext cc = (CarpetContext) c;
ServerScoreboard scoreboard = cc.server().getScoreboard();
String teamName = lv.get(0).getString();
if (lv.size() == 1)
{
@@ -339,13 +339,13 @@ public class Scoreboards
{
return Value.NULL;
}
final Value playerVal = lv.get(1);
final String player = EntityValue.getPlayerNameByValue(playerVal);
Value playerVal = lv.get(1);
String player = EntityValue.getPlayerNameByValue(playerVal);
if (player == null)
{
return Value.NULL;
}
final PlayerTeam team = scoreboard.getPlayerTeam(teamName);
PlayerTeam team = scoreboard.getPlayerTeam(teamName);
if (team == null)
{
return Value.NULL;
@@ -354,44 +354,44 @@ public class Scoreboards
{
return Value.FALSE;
}
scoreboard.addPlayerToTeam(player, scoreboard.getPlayerTeam(teamName));
scoreboard.addPlayerToTeam(player, team);
return Value.TRUE;
});
expression.addContextFunction("team_remove", 1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final ServerScoreboard scoreboard = cc.server().getScoreboard();
final Value teamVal = lv.get(0);
final String team = teamVal.getString();
if (scoreboard.getPlayerTeam(team) == null)
CarpetContext cc = (CarpetContext) c;
ServerScoreboard scoreboard = cc.server().getScoreboard();
Value teamVal = lv.get(0);
PlayerTeam team = scoreboard.getPlayerTeam(teamVal.getString());
if (team == null)
{
return Value.NULL;
}
scoreboard.removePlayerTeam(scoreboard.getPlayerTeam(team));
scoreboard.removePlayerTeam(team);
return Value.TRUE;
});
expression.addContextFunction("team_leave", 1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final ServerScoreboard scoreboard = cc.server().getScoreboard();
final Value playerVal = lv.get(0);
final String player = EntityValue.getPlayerNameByValue(playerVal);
CarpetContext cc = (CarpetContext) c;
ServerScoreboard scoreboard = cc.server().getScoreboard();
Value playerVal = lv.get(0);
String player = EntityValue.getPlayerNameByValue(playerVal);
return player == null ? Value.NULL : BooleanValue.of(scoreboard.removePlayerFromTeam(player));
});
expression.addContextFunction("team_property", -1, (c, t, lv) ->
{
final CarpetContext cc = (CarpetContext) c;
final ServerScoreboard scoreboard = cc.server().getScoreboard();
CarpetContext cc = (CarpetContext) c;
ServerScoreboard scoreboard = cc.server().getScoreboard();
if (lv.size() < 2 || lv.size() > 3)
{
throw new InternalExpressionException("'team_property' requires two or three arguments");
}
final Value teamVal = lv.get(0);
final Value propertyVal = lv.get(1);
Value teamVal = lv.get(0);
Value propertyVal = lv.get(1);
Value settingVal = null;
boolean modifying = false;
@@ -401,7 +401,7 @@ public class Scoreboards
settingVal = lv.get(2);
}
final PlayerTeam team = scoreboard.getPlayerTeam(teamVal.getString());
PlayerTeam team = scoreboard.getPlayerTeam(teamVal.getString());
if (team == null)
{
return Value.NULL;
@@ -423,7 +423,7 @@ public class Scoreboards
{
throw new InternalExpressionException("'team_property' requires a string as the third argument for the property " + propertyVal.getString());
}
final Team.CollisionRule collisionRule = Team.CollisionRule.byName(settingVal.getString());
Team.CollisionRule collisionRule = Team.CollisionRule.byName(settingVal.getString());
if (collisionRule == null)
{
throw new InternalExpressionException("Unknown value for property " + propertyVal.getString() + ": " + settingVal.getString());
@@ -439,7 +439,7 @@ public class Scoreboards
{
throw new InternalExpressionException("'team_property' requires a string as the third argument for the property " + propertyVal.getString());
}
final ChatFormatting color = ChatFormatting.getByName(settingVal.getString().toUpperCase());
ChatFormatting color = ChatFormatting.getByName(settingVal.getString().toUpperCase());
if (color == null || !color.isColor())
{
throw new InternalExpressionException("Unknown value for property " + propertyVal.getString() + ": " + settingVal.getString());
@@ -455,7 +455,7 @@ public class Scoreboards
{
throw new InternalExpressionException("'team_property' requires a string as the third argument for the property " + propertyVal.getString());
}
final Team.Visibility deathMessageVisibility = Team.Visibility.byName(settingVal.getString());
Team.Visibility deathMessageVisibility = Team.Visibility.byName(settingVal.getString());
if (deathMessageVisibility == null)
{
throw new InternalExpressionException("Unknown value for property " + propertyVal.getString() + ": " + settingVal.getString());
@@ -493,7 +493,7 @@ public class Scoreboards
{
throw new InternalExpressionException("'team_property' requires a string as the third argument for the property " + propertyVal.getString());
}
final Team.Visibility nametagVisibility = Team.Visibility.byName(settingVal.getString());
Team.Visibility nametagVisibility = Team.Visibility.byName(settingVal.getString());
if (nametagVisibility == null)
{
throw new InternalExpressionException("Unknown value for property " + propertyVal.getString() + ": " + settingVal.getString());
@@ -540,19 +540,19 @@ public class Scoreboards
expression.addContextFunction("bossbar", -1, (c, t, lv) ->
{
final CustomBossEvents bossBarManager = ((CarpetContext) c).server().getCustomBossEvents();
CustomBossEvents bossBarManager = ((CarpetContext) c).server().getCustomBossEvents();
if (lv.size() > 3)
{
throw new InternalExpressionException("'bossbar' accepts max three arguments");
}
if (lv.size() == 0)
if (lv.isEmpty())
{
return ListValue.wrap(bossBarManager.getEvents().stream().map(CustomBossEvent::getTextId).map(ResourceLocation::toString).map(StringValue::of));
}
final String id = lv.get(0).getString();
final ResourceLocation identifier = InputValidator.identifierOf(id);
String id = lv.get(0).getString();
ResourceLocation identifier = InputValidator.identifierOf(id);
if (lv.size() == 1)
{
@@ -563,25 +563,25 @@ public class Scoreboards
return StringValue.of(bossBarManager.create(identifier, Component.literal(id)).getTextId().toString());
}
final String property = lv.get(1).getString();
String property = lv.get(1).getString();
final CustomBossEvent bossBar = bossBarManager.get(identifier);
CustomBossEvent bossBar = bossBarManager.get(identifier);
if (bossBar == null)
{
return Value.NULL;
}
final Value propertyValue = (lv.size() == 3) ? lv.get(2) : null;
Value propertyValue = (lv.size() == 3) ? lv.get(2) : null;
switch (property)
{
case "color" -> {
if (propertyValue == null)
{
final BossEvent.BossBarColor color = (bossBar).getColor();
BossEvent.BossBarColor color = (bossBar).getColor();
return color == null ? Value.NULL : StringValue.of(color.getName());
}
final BossEvent.BossBarColor color = BossEvent.BossBarColor.byName(propertyValue.getString());
BossEvent.BossBarColor color = BossEvent.BossBarColor.byName(propertyValue.getString());
if (color == null)
{
return Value.NULL;
@@ -616,8 +616,8 @@ public class Scoreboards
}
if (propertyValue instanceof final ListValue list)
{
list.getItems().forEach((v) -> {
final ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
list.getItems().forEach(v -> {
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
if (player != null)
{
bossBar.addPlayer(player);
@@ -625,7 +625,7 @@ public class Scoreboards
});
return Value.TRUE;
}
final ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
if (player != null)
{
bossBar.addPlayer(player);
@@ -650,7 +650,7 @@ public class Scoreboards
});
return Value.TRUE;
}
final ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
bossBar.removeAllPlayers();
if (p != null)
{
@@ -664,7 +664,7 @@ public class Scoreboards
{
return StringValue.of(bossBar.getOverlay().getName());
}
final BossEvent.BossBarOverlay style = BossEvent.BossBarOverlay.byName(propertyValue.getString());
BossEvent.BossBarOverlay style = BossEvent.BossBarOverlay.byName(propertyValue.getString());
if (style == null)
{
throw new InternalExpressionException("'" + propertyValue.getString() + "' is not a valid value for property " + property);
+12 -12
View File
@@ -14,13 +14,13 @@ public class Threading
{
public static void apply(Expression expression)
{
//"overidden" native call to cancel if on main thread
//"overridden" native call to cancel if on main thread
expression.addContextFunction("task_join", 1, (c, t, lv) -> {
if (((CarpetContext) c).server().isSameThread())
{
throw new InternalExpressionException("'task_join' cannot be called from main thread to avoid deadlocks");
}
final Value v = lv.get(0);
Value v = lv.get(0);
if (!(v instanceof final ThreadValue tv))
{
throw new InternalExpressionException("'task_join' could only be used with a task value");
@@ -30,14 +30,14 @@ public class Threading
// has to be lazy due to deferred execution of the expression
expression.addLazyFunctionWithDelegation("task_dock", 1, false, true, (c, t, expr, tok, lv) -> {
final CarpetContext cc = (CarpetContext) c;
final MinecraftServer server = cc.server();
CarpetContext cc = (CarpetContext) c;
MinecraftServer server = cc.server();
if (server.isSameThread())
{
return lv.get(0); // pass through for on thread tasks
}
final Value[] result = new Value[]{Value.NULL};
final RuntimeException[] internal = new RuntimeException[]{null};
Value[] result = new Value[]{Value.NULL};
RuntimeException[] internal = new RuntimeException[]{null};
try
{
((CarpetContext) c).server().executeBlocking(() ->
@@ -46,22 +46,22 @@ public class Threading
{
result[0] = lv.get(0).evalValue(c, t);
}
catch (final ExpressionException exc)
catch (ExpressionException exc)
{
internal[0] = exc;
}
catch (final InternalExpressionException exc)
catch (InternalExpressionException exc)
{
internal[0] = new ExpressionException(c, expr, tok, exc.getMessage(), exc.stack);
}
catch (final ArithmeticException exc)
catch (ArithmeticException exc)
{
internal[0] = new ExpressionException(c, expr, tok, "Your math is wrong, " + exc.getMessage());
}
});
}
catch (final CompletionException exc)
catch (CompletionException exc)
{
throw new InternalExpressionException("Error while executing docked task section, internal stack trace is gone");
}
@@ -69,8 +69,8 @@ public class Threading
{
throw internal[0];
}
final Value ret = result[0]; // preventing from lazy evaluating of the result in case a future completes later
return (_c, _t) -> ret;
Value ret = result[0]; // preventing from lazy evaluating of the result in case a future completes later
return (ct, tt) -> ret;
// pass through placeholder
// implmenetation should dock the task on the main thread.
});
File diff suppressed because it is too large. Load diff