Merge branch 'master' into 1.17
# Conflicts: # src/main/java/carpet/script/api/Auxiliary.java # src/main/java/carpet/script/utils/ShapeDispatcher.java # src/main/java/carpet/script/value/EntityValue.java # src/main/java/carpet/script/value/ListValue.java
This commit is contained in:
commit
c720c2c935
18 files changed
+83
-110
No files matched your search
@@ -465,7 +465,7 @@ public class CarpetEventServer
|
|||||||
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking)
|
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking)
|
||||||
{
|
{
|
||||||
handler.call( () -> Arrays.asList(new EntityValue(player),
|
handler.call( () -> Arrays.asList(new EntityValue(player),
|
||||||
new NumericValue(forwardSpeed), new NumericValue(strafeSpeed), new NumericValue(jumping), new NumericValue(sneaking)
|
new NumericValue(forwardSpeed), new NumericValue(strafeSpeed), BooleanValue.of(jumping), BooleanValue.of(sneaking)
|
||||||
), player::getCommandSource);
|
), player::getCommandSource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -479,7 +479,7 @@ public class CarpetEventServer
|
|||||||
//ItemStack itemstack = player.getStackInHand(enumhand);
|
//ItemStack itemstack = player.getStackInHand(enumhand);
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
ListValue.fromItemStack(itemstack),
|
ValueConversions.of(itemstack),
|
||||||
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
||||||
);
|
);
|
||||||
}, player::getCommandSource);
|
}, player::getCommandSource);
|
||||||
@@ -513,7 +513,7 @@ public class CarpetEventServer
|
|||||||
Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
|
Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
ListValue.fromItemStack(itemstack),
|
ValueConversions.of(itemstack),
|
||||||
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"),
|
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"),
|
||||||
new BlockValue(null, player.getServerWorld(), blockpos),
|
new BlockValue(null, player.getServerWorld(), blockpos),
|
||||||
StringValue.of(enumfacing.getName()),
|
StringValue.of(enumfacing.getName()),
|
||||||
@@ -557,7 +557,7 @@ public class CarpetEventServer
|
|||||||
{
|
{
|
||||||
handler.call( () -> Arrays.asList(
|
handler.call( () -> Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
ListValue.fromItemStack(itemstack),
|
ValueConversions.of(itemstack),
|
||||||
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"),
|
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"),
|
||||||
new BlockValue(null, player.getServerWorld(), pos)
|
new BlockValue(null, player.getServerWorld(), pos)
|
||||||
), player::getCommandSource);
|
), player::getCommandSource);
|
||||||
@@ -602,7 +602,7 @@ public class CarpetEventServer
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack) {
|
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack) {
|
||||||
handler.call( () -> Arrays.asList(new EntityValue(player), ListValue.fromItemStack(itemstack)), player::getCommandSource);
|
handler.call( () -> Arrays.asList(new EntityValue(player), ValueConversions.of(itemstack)), player::getCommandSource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -656,7 +656,7 @@ public class CarpetEventServer
|
|||||||
handler.call( () ->
|
handler.call( () ->
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
ListValue.fromItemStack(itemstack),
|
ValueConversions.of(itemstack),
|
||||||
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
StringValue.of(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
||||||
), player::getCommandSource);
|
), player::getCommandSource);
|
||||||
}
|
}
|
||||||
@@ -670,7 +670,7 @@ public class CarpetEventServer
|
|||||||
handler.call( () ->
|
handler.call( () ->
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
ListValue.fromItemStack(itemstack),
|
ValueConversions.of(itemstack),
|
||||||
new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")
|
||||||
), player::getCommandSource);
|
), player::getCommandSource);
|
||||||
}
|
}
|
||||||
@@ -700,7 +700,7 @@ public class CarpetEventServer
|
|||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
new EntityValue(player),
|
new EntityValue(player),
|
||||||
StringValue.of(NBTSerializableValue.nameFromRegistryId(recipe)),
|
StringValue.of(NBTSerializableValue.nameFromRegistryId(recipe)),
|
||||||
new NumericValue(fullStack)
|
BooleanValue.of(fullStack)
|
||||||
), player::getCommandSource);
|
), player::getCommandSource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,9 +84,8 @@ public final class AnnotationParser
|
|||||||
* <p>There is a set of requirements for the class and its methods:</p>
|
* <p>There is a set of requirements for the class and its methods:</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Class must be concrete. That is, no interfaces or abstract classes should be passed</li>
|
* <li>Class must be concrete. That is, no interfaces or abstract classes should be passed</li>
|
||||||
* <li>Class must have the default constructor (or an equivalent) available. That is done in order to not need the {@code static} modifier in every method, making them faster to
|
* <li>Class must have the default constructor (or an equivalent) available. That is done in order to not need the {@code static} modifier in every
|
||||||
* code and simpler to look at.</li>
|
* method, making them faster to code and simpler to look at.</li>
|
||||||
* <li>Annotated methods must not be {@code static}. See claim above</li>
|
|
||||||
* <li>Annotated methods must not throw checked exceptions. They can throw regular {@link RuntimeException}s (including but not limited to
|
* <li>Annotated methods must not throw checked exceptions. They can throw regular {@link RuntimeException}s (including but not limited to
|
||||||
* {@link InternalExpressionException}).
|
* {@link InternalExpressionException}).
|
||||||
* Basically, it's fine as long as you don't add a {@code throws} declaration to your methods.</li>
|
* Basically, it's fine as long as you don't add a {@code throws} declaration to your methods.</li>
|
||||||
@@ -121,9 +120,7 @@ public final class AnnotationParser
|
|||||||
{
|
{
|
||||||
if (!method.isAnnotationPresent(ScarpetFunction.class))
|
if (!method.isAnnotationPresent(ScarpetFunction.class))
|
||||||
continue;
|
continue;
|
||||||
// Checks
|
|
||||||
if (Modifier.isStatic(method.getModifiers()))
|
|
||||||
throw new IllegalArgumentException("Annotated method '" + method.getName() + "', provided in '" + clazz + "' must not be static");
|
|
||||||
if (method.getExceptionTypes().length != 0)
|
if (method.getExceptionTypes().length != 0)
|
||||||
throw new IllegalArgumentException("Annotated method '" + method.getName() +"', provided in '"+clazz+"' must not declare checked exceptions");
|
throw new IllegalArgumentException("Annotated method '" + method.getName() +"', provided in '"+clazz+"' must not declare checked exceptions");
|
||||||
|
|
||||||
@@ -212,7 +209,8 @@ public final class AnnotationParser
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
MethodHandle tempHandle = MethodHandles.publicLookup().unreflect(method).asFixedArity().asSpreader(Object[].class, this.methodParamCount);
|
MethodHandle tempHandle = MethodHandles.publicLookup().unreflect(method).asFixedArity().asSpreader(Object[].class, this.methodParamCount);
|
||||||
this.handle = tempHandle.asType(tempHandle.type().changeReturnType(Object.class)).bindTo(instance);
|
tempHandle = tempHandle.asType(tempHandle.type().changeReturnType(Object.class));
|
||||||
|
this.handle = Modifier.isStatic(method.getModifiers()) ? tempHandle : tempHandle.bindTo(instance);
|
||||||
} catch (IllegalAccessException e)
|
} catch (IllegalAccessException e)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
|
|||||||
@@ -133,42 +133,14 @@ public interface Param
|
|||||||
/**
|
/**
|
||||||
* <p>Class that holds the actual converters and converter getting logic for those annotated types and things.</p>
|
* <p>Class that holds the actual converters and converter getting logic for those annotated types and things.</p>
|
||||||
*
|
*
|
||||||
* <p>It also holds the registry for strict {@link ValueConverter}s.</p>
|
* <p>It also holds the registry for strict and custom {@link ValueConverter}s.</p>
|
||||||
*
|
*
|
||||||
* @see #registerStrictConverter(Class, boolean, ValueConverter)
|
* @see #registerStrictConverter(Class, boolean, ValueConverter)
|
||||||
|
* @see #registerCustomConverterFactory(BiFunction)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static final class Params
|
public static final class Params
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* <p>A {@link ValueConverter} that outputs the given {@link LazyValue} when running {@link #checkAndConvert(Iterator, Context, Context.Type)}, and
|
|
||||||
* throws {@link UnsupportedOperationException} when trying to convert a {@link Value} directly.</p>
|
|
||||||
*
|
|
||||||
* <p>Public in order to allow custom {@link ValueConverter} to check whether values should be evaluated while testing conditions.</p>
|
|
||||||
*/
|
|
||||||
/*public static final ValueConverter<LazyValue> LAZY_VALUE_IDENTITY = new ValueConverter<LazyValue>()
|
|
||||||
{ // No longer possible
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LazyValue convert(Value val)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"Called convert() with a Value in LazyValue identity, where only evalAndConvert is supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LazyValue checkAndConvert(Iterator<Value> lazyValueIterator, Context c, Context.Type theLazyT)
|
|
||||||
{
|
|
||||||
return lazyValueIterator.hasNext() ? lazyValueIterator.next() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTypeName()
|
|
||||||
{
|
|
||||||
return "something";
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A {@link ValueConverter} that outputs the {@link Context} in which the function has been called, and throws {@link UnsupportedOperationException} when trying to convert a {@link Value}
|
* <p>A {@link ValueConverter} that outputs the {@link Context} in which the function has been called, and throws {@link UnsupportedOperationException} when trying to convert a {@link Value}
|
||||||
* directly.</p>
|
* directly.</p>
|
||||||
@@ -228,7 +200,7 @@ public interface Param
|
|||||||
*
|
*
|
||||||
* <p>Stored as {@code <Pair<Type, shallow?>, Converter>}</p>
|
* <p>Stored as {@code <Pair<Type, shallow?>, Converter>}</p>
|
||||||
*/
|
*/
|
||||||
private static Map<Pair<Class<?>, Boolean>, ValueConverter<?>> strictParamsByClassAndShallowness = new HashMap<>();
|
private static final Map<Pair<Class<?>, Boolean>, ValueConverter<?>> strictParamsByClassAndShallowness = new HashMap<>();
|
||||||
static
|
static
|
||||||
{ // TODO Specify strictness in name?
|
{ // TODO Specify strictness in name?
|
||||||
registerStrictConverter(String.class, false, new SimpleTypeConverter<>(StringValue.class, StringValue::getString, "string"));
|
registerStrictConverter(String.class, false, new SimpleTypeConverter<>(StringValue.class, StringValue::getString, "string"));
|
||||||
@@ -279,7 +251,7 @@ public interface Param
|
|||||||
strictParamsByClassAndShallowness.put(key, converter);
|
strictParamsByClassAndShallowness.put(key, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<BiFunction<AnnotatedType, Class<?>, ValueConverter<?>>> customFactories = new ArrayList<>();
|
private static final List<BiFunction<AnnotatedType, Class<?>, ValueConverter<?>>> customFactories = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Allows extensions to register <b>COMPLEX</b> {@link ValueConverter} factories in order to be used with the {@link Param.Custom}
|
* <p>Allows extensions to register <b>COMPLEX</b> {@link ValueConverter} factories in order to be used with the {@link Param.Custom}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import carpet.script.value.Value;
|
|||||||
* {@link AnnotationParser#parseFunctionClass(Class)} ONCE. The provided {@link Class} must be concrete and provide the default constructor or an
|
* {@link AnnotationParser#parseFunctionClass(Class)} ONCE. The provided {@link Class} must be concrete and provide the default constructor or an
|
||||||
* equivalent to it.</p>
|
* equivalent to it.</p>
|
||||||
*
|
*
|
||||||
* <p>Methods annotated with this annotation must not be static and must not declare throwing any checked exceptions.</p>
|
* <p>Methods annotated with this annotation must not declare throwing any checked exceptions.</p>
|
||||||
*
|
*
|
||||||
* <p>If one of the method's parameters is {@link Context}, Carpet will pass the actual {@link Context} of the expression to the
|
* <p>If one of the method's parameters is {@link Context}, Carpet will pass the actual {@link Context} of the expression to the
|
||||||
* method. If one of the method's parameters is {@link Context.Type}, Carpet will pass the Context Type the function was called inside. That
|
* method. If one of the method's parameters is {@link Context.Type}, Carpet will pass the Context Type the function was called inside. That
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ public class Auxiliary {
|
|||||||
if (lv.get(0).isNull()) return Value.FALSE;
|
if (lv.get(0).isNull()) return Value.FALSE;
|
||||||
NbtElement source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
NbtElement source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||||
NbtElement match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
NbtElement match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||||
return new NumericValue(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
return BooleanValue.of(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addFunction("encode_nbt", lv -> {
|
expression.addFunction("encode_nbt", lv -> {
|
||||||
@@ -799,7 +799,7 @@ public class Auxiliary {
|
|||||||
return;
|
return;
|
||||||
if (what.equalsIgnoreCase("boulder")) // there might be more of those
|
if (what.equalsIgnoreCase("boulder")) // there might be more of those
|
||||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getWorld());
|
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getWorld());
|
||||||
result[0] = new NumericValue(res);
|
result[0] = BooleanValue.of(res);
|
||||||
});
|
});
|
||||||
return result[0];
|
return result[0];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ public class Inventories {
|
|||||||
CarpetContext cc = (CarpetContext) c;
|
CarpetContext cc = (CarpetContext) c;
|
||||||
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
|
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
|
||||||
if (inventoryLocator == null) return Value.NULL;
|
if (inventoryLocator == null) return Value.NULL;
|
||||||
return new NumericValue(!inventoryLocator.inventory.isEmpty());
|
return BooleanValue.of(!inventoryLocator.inventory.isEmpty());
|
||||||
});
|
});
|
||||||
|
|
||||||
//inventory_get(<b, e>, <n>) -> item_triple
|
//inventory_get(<b, e>, <n>) -> item_triple
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import carpet.script.LazyValue;
|
|||||||
import carpet.script.exception.InternalExpressionException;
|
import carpet.script.exception.InternalExpressionException;
|
||||||
import carpet.script.exception.ThrowStatement;
|
import carpet.script.exception.ThrowStatement;
|
||||||
import carpet.script.exception.Throwables;
|
import carpet.script.exception.Throwables;
|
||||||
|
import carpet.script.value.BooleanValue;
|
||||||
import carpet.script.value.EntityValue;
|
import carpet.script.value.EntityValue;
|
||||||
import carpet.script.value.ListValue;
|
import carpet.script.value.ListValue;
|
||||||
import carpet.script.value.NullValue;
|
import carpet.script.value.NullValue;
|
||||||
@@ -301,7 +302,7 @@ public class Scoreboards {
|
|||||||
Value playerVal = lv.get(0);
|
Value playerVal = lv.get(0);
|
||||||
String player = EntityValue.getPlayerNameByValue(playerVal);
|
String player = EntityValue.getPlayerNameByValue(playerVal);
|
||||||
if(player == null) return Value.NULL;
|
if(player == null) return Value.NULL;
|
||||||
return new NumericValue(scoreboard.clearPlayerTeam(player));
|
return BooleanValue.of(scoreboard.clearPlayerTeam(player));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("team_property", -1, (c, t, lv) ->
|
expression.addContextFunction("team_property", -1, (c, t, lv) ->
|
||||||
@@ -357,7 +358,7 @@ public class Scoreboards {
|
|||||||
team.setDisplayName(displayName);
|
team.setDisplayName(displayName);
|
||||||
break;
|
break;
|
||||||
case "friendlyFire":
|
case "friendlyFire":
|
||||||
if(!modifying) return new NumericValue(team.isFriendlyFireAllowed());
|
if(!modifying) return BooleanValue.of(team.isFriendlyFireAllowed());
|
||||||
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
|
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
|
||||||
boolean friendlyFire = settingVal.getBoolean();
|
boolean friendlyFire = settingVal.getBoolean();
|
||||||
team.setFriendlyFireAllowed(friendlyFire);
|
team.setFriendlyFireAllowed(friendlyFire);
|
||||||
@@ -378,7 +379,7 @@ public class Scoreboards {
|
|||||||
team.setPrefix(prefix);
|
team.setPrefix(prefix);
|
||||||
break;
|
break;
|
||||||
case "seeFriendlyInvisibles":
|
case "seeFriendlyInvisibles":
|
||||||
if(!modifying) return new NumericValue(team.shouldShowFriendlyInvisibles());
|
if(!modifying) return BooleanValue.of(team.shouldShowFriendlyInvisibles());
|
||||||
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
|
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
|
||||||
boolean seeFriendlyInvisibles = settingVal.getBoolean();
|
boolean seeFriendlyInvisibles = settingVal.getBoolean();
|
||||||
team.setShowFriendlyInvisibles(seeFriendlyInvisibles);
|
team.setShowFriendlyInvisibles(seeFriendlyInvisibles);
|
||||||
@@ -500,7 +501,7 @@ public class Scoreboards {
|
|||||||
bossBar.setValue(((NumericValue) propertyValue).getInt());
|
bossBar.setValue(((NumericValue) propertyValue).getInt());
|
||||||
return Value.TRUE;
|
return Value.TRUE;
|
||||||
case "visible":
|
case "visible":
|
||||||
if(propertyValue == null) return new NumericValue(bossBar.isVisible());
|
if(propertyValue == null) return BooleanValue.of(bossBar.isVisible());
|
||||||
|
|
||||||
bossBar.setVisible(propertyValue.getBoolean());
|
bossBar.setVisible(propertyValue.getBoolean());
|
||||||
return Value.TRUE;
|
return Value.TRUE;
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ public class WorldAccess {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("solid", -1, (c, t, lv) ->
|
expression.addContextFunction("solid", -1, (c, t, lv) ->
|
||||||
genericStateTest(c, "solid", lv, (s, p, w) -> new NumericValue(s.isSolidBlock(w, p)))); // isSimpleFullBlock
|
genericStateTest(c, "solid", lv, (s, p, w) -> BooleanValue.of(s.isSolidBlock(w, p)))); // isSimpleFullBlock
|
||||||
|
|
||||||
expression.addContextFunction("air", -1, (c, t, lv) ->
|
expression.addContextFunction("air", -1, (c, t, lv) ->
|
||||||
booleanStateTest(c, "air", lv, (s, p) -> s.isAir()));
|
booleanStateTest(c, "air", lv, (s, p) -> s.isAir()));
|
||||||
@@ -526,7 +526,7 @@ public class WorldAccess {
|
|||||||
genericStateTest(c, "sky_light", lv, (s, p, w) -> new NumericValue(w.getLightLevel(LightType.SKY, p))));
|
genericStateTest(c, "sky_light", lv, (s, p, w) -> new NumericValue(w.getLightLevel(LightType.SKY, p))));
|
||||||
|
|
||||||
expression.addContextFunction("see_sky", -1, (c, t, lv) ->
|
expression.addContextFunction("see_sky", -1, (c, t, lv) ->
|
||||||
genericStateTest(c, "see_sky", lv, (s, p, w) -> new NumericValue(w.isSkyVisible(p))));
|
genericStateTest(c, "see_sky", lv, (s, p, w) -> BooleanValue.of(w.isSkyVisible(p))));
|
||||||
|
|
||||||
expression.addContextFunction("brightness", -1, (c, t, lv) ->
|
expression.addContextFunction("brightness", -1, (c, t, lv) ->
|
||||||
genericStateTest(c, "brightness", lv, (s, p, w) -> new NumericValue(w.getBrightness(p))));
|
genericStateTest(c, "brightness", lv, (s, p, w) -> new NumericValue(w.getBrightness(p))));
|
||||||
@@ -541,7 +541,7 @@ public class WorldAccess {
|
|||||||
{
|
{
|
||||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||||
ChunkPos chunkPos = new ChunkPos(pos);
|
ChunkPos chunkPos = new ChunkPos(pos);
|
||||||
return new NumericValue(ChunkRandom.getSlimeRandom(
|
return BooleanValue.of(ChunkRandom.getSlimeRandom(
|
||||||
chunkPos.x, chunkPos.z,
|
chunkPos.x, chunkPos.z,
|
||||||
((CarpetContext)c).s.getWorld().getSeed(),
|
((CarpetContext)c).s.getWorld().getSeed(),
|
||||||
987234911L
|
987234911L
|
||||||
@@ -594,7 +594,7 @@ public class WorldAccess {
|
|||||||
boolean force = false;
|
boolean force = false;
|
||||||
if (lv.size() > locator.offset)
|
if (lv.size() > locator.offset)
|
||||||
force = lv.get(locator.offset).getBoolean();
|
force = lv.get(locator.offset).getBoolean();
|
||||||
return new NumericValue(canHasChunk(((CarpetContext)c).s.getWorld(), new ChunkPos(pos), null, force));
|
return BooleanValue.of(canHasChunk(((CarpetContext)c).s.getWorld(), new ChunkPos(pos), null, force));
|
||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("generation_status", -1, (c, t, lv) ->
|
expression.addContextFunction("generation_status", -1, (c, t, lv) ->
|
||||||
@@ -654,7 +654,7 @@ public class WorldAccess {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expression.addContextFunction("suffocates", -1, (c, t, lv) ->
|
expression.addContextFunction("suffocates", -1, (c, t, lv) ->
|
||||||
genericStateTest(c, "suffocates", lv, (s, p, w) -> new NumericValue(s.shouldSuffocate(w, p)))); // canSuffocate
|
genericStateTest(c, "suffocates", lv, (s, p, w) -> BooleanValue.of(s.shouldSuffocate(w, p)))); // canSuffocate
|
||||||
|
|
||||||
expression.addContextFunction("power", -1, (c, t, lv) ->
|
expression.addContextFunction("power", -1, (c, t, lv) ->
|
||||||
genericStateTest(c, "power", lv, (s, p, w) -> new NumericValue(w.getReceivedRedstonePower(p))));
|
genericStateTest(c, "power", lv, (s, p, w) -> new NumericValue(w.getReceivedRedstonePower(p))));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import carpet.script.CarpetScriptHost;
|
|||||||
import carpet.script.argument.FunctionArgument;
|
import carpet.script.argument.FunctionArgument;
|
||||||
import carpet.script.exception.InternalExpressionException;
|
import carpet.script.exception.InternalExpressionException;
|
||||||
import carpet.script.value.BlockValue;
|
import carpet.script.value.BlockValue;
|
||||||
|
import carpet.script.value.BooleanValue;
|
||||||
import carpet.script.value.EntityValue;
|
import carpet.script.value.EntityValue;
|
||||||
import carpet.script.value.FormattedTextValue;
|
import carpet.script.value.FormattedTextValue;
|
||||||
import carpet.script.value.ListValue;
|
import carpet.script.value.ListValue;
|
||||||
@@ -114,7 +115,7 @@ public abstract class CommandArgument
|
|||||||
new StringArgument(),
|
new StringArgument(),
|
||||||
// vanilla arguments as per https://minecraft.gamepedia.com/Argument_types
|
// vanilla arguments as per https://minecraft.gamepedia.com/Argument_types
|
||||||
new VanillaUnconfigurableArgument( "bool", BoolArgumentType::bool,
|
new VanillaUnconfigurableArgument( "bool", BoolArgumentType::bool,
|
||||||
(c, p) -> new NumericValue(BoolArgumentType.getBool(c, p)), false
|
(c, p) -> BooleanValue.of(BoolArgumentType.getBool(c, p)), false
|
||||||
),
|
),
|
||||||
new FloatArgument(),
|
new FloatArgument(),
|
||||||
new IntArgument(),
|
new IntArgument(),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import carpet.script.exception.InternalExpressionException;
|
|||||||
import carpet.script.exception.ThrowStatement;
|
import carpet.script.exception.ThrowStatement;
|
||||||
import carpet.script.exception.Throwables;
|
import carpet.script.exception.Throwables;
|
||||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||||
|
import carpet.script.value.BooleanValue;
|
||||||
import carpet.script.value.ContainerValueInterface;
|
import carpet.script.value.ContainerValueInterface;
|
||||||
import carpet.script.value.LContainerValue;
|
import carpet.script.value.LContainerValue;
|
||||||
import carpet.script.value.LazyListValue;
|
import carpet.script.value.LazyListValue;
|
||||||
@@ -246,7 +247,7 @@ public class DataStructures {
|
|||||||
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
||||||
if (container == null)
|
if (container == null)
|
||||||
return LazyValue.NULL;
|
return LazyValue.NULL;
|
||||||
Value ret = new NumericValue(container.has(((LContainerValue) v).getAddress()));
|
Value ret = BooleanValue.of(container.has(((LContainerValue) v).getAddress()));
|
||||||
return (cc, tt) -> ret;
|
return (cc, tt) -> ret;
|
||||||
}
|
}
|
||||||
Value container = lv.get(0).evalValue(c);
|
Value container = lv.get(0).evalValue(c);
|
||||||
@@ -257,7 +258,7 @@ public class DataStructures {
|
|||||||
}
|
}
|
||||||
if (!(container instanceof ContainerValueInterface))
|
if (!(container instanceof ContainerValueInterface))
|
||||||
return LazyValue.NULL;
|
return LazyValue.NULL;
|
||||||
Value ret = new NumericValue(((ContainerValueInterface) container).has(lv.get(lv.size()-1).evalValue(c)));
|
Value ret = BooleanValue.of(((ContainerValueInterface) container).has(lv.get(lv.size()-1).evalValue(c)));
|
||||||
return (cc, tt) -> ret;
|
return (cc, tt) -> ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -278,7 +279,7 @@ public class DataStructures {
|
|||||||
}
|
}
|
||||||
Value address = ((LContainerValue) container).getAddress();
|
Value address = ((LContainerValue) container).getAddress();
|
||||||
Value what = lv.get(1).evalValue(c);
|
Value what = lv.get(1).evalValue(c);
|
||||||
Value retVal = new NumericValue( (lv.size() > 2)
|
Value retVal = BooleanValue.of((lv.size() > 2)
|
||||||
? internalContainer.put(address, what, lv.get(2).evalValue(c))
|
? internalContainer.put(address, what, lv.get(2).evalValue(c))
|
||||||
: internalContainer.put(address, what));
|
: internalContainer.put(address, what));
|
||||||
return (cc, tt) -> retVal;
|
return (cc, tt) -> retVal;
|
||||||
@@ -294,7 +295,7 @@ public class DataStructures {
|
|||||||
}
|
}
|
||||||
Value where = lv.get(1).evalValue(c);
|
Value where = lv.get(1).evalValue(c);
|
||||||
Value what = lv.get(2).evalValue(c);
|
Value what = lv.get(2).evalValue(c);
|
||||||
Value retVal = new NumericValue( (lv.size()>3)
|
Value retVal = BooleanValue.of((lv.size()>3)
|
||||||
? ((ContainerValueInterface) container).put(where, what, lv.get(3).evalValue(c))
|
? ((ContainerValueInterface) container).put(where, what, lv.get(3).evalValue(c))
|
||||||
: ((ContainerValueInterface) container).put(where, what));
|
: ((ContainerValueInterface) container).put(where, what));
|
||||||
return (cc, tt) -> retVal;
|
return (cc, tt) -> retVal;
|
||||||
@@ -313,7 +314,7 @@ public class DataStructures {
|
|||||||
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
ContainerValueInterface container = ((LContainerValue) v).getContainer();
|
||||||
if (container == null)
|
if (container == null)
|
||||||
return LazyValue.NULL;
|
return LazyValue.NULL;
|
||||||
Value ret = new NumericValue(container.delete(((LContainerValue) v).getAddress()));
|
Value ret = BooleanValue.of(container.delete(((LContainerValue) v).getAddress()));
|
||||||
return (cc, tt) -> ret;
|
return (cc, tt) -> ret;
|
||||||
}
|
}
|
||||||
Value container = lv.get(0).evalValue(c);
|
Value container = lv.get(0).evalValue(c);
|
||||||
@@ -324,7 +325,7 @@ public class DataStructures {
|
|||||||
}
|
}
|
||||||
if (!(container instanceof ContainerValueInterface))
|
if (!(container instanceof ContainerValueInterface))
|
||||||
return LazyValue.NULL;
|
return LazyValue.NULL;
|
||||||
Value ret = new NumericValue(((ContainerValueInterface) container).delete(lv.get(lv.size()-1).evalValue(c)));
|
Value ret = BooleanValue.of(((ContainerValueInterface) container).delete(lv.get(lv.size()-1).evalValue(c)));
|
||||||
return (cc, tt) -> ret;
|
return (cc, tt) -> ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import carpet.script.Expression;
|
|||||||
import carpet.script.argument.FunctionArgument;
|
import carpet.script.argument.FunctionArgument;
|
||||||
import carpet.script.exception.ExitStatement;
|
import carpet.script.exception.ExitStatement;
|
||||||
import carpet.script.exception.InternalExpressionException;
|
import carpet.script.exception.InternalExpressionException;
|
||||||
|
import carpet.script.value.BooleanValue;
|
||||||
import carpet.script.value.NumericValue;
|
import carpet.script.value.NumericValue;
|
||||||
import carpet.script.value.ThreadValue;
|
import carpet.script.value.ThreadValue;
|
||||||
import carpet.script.value.Value;
|
import carpet.script.value.Value;
|
||||||
@@ -62,7 +63,7 @@ public class Threading
|
|||||||
{
|
{
|
||||||
if (!(v instanceof ThreadValue))
|
if (!(v instanceof ThreadValue))
|
||||||
throw new InternalExpressionException("'task_completed' could only be used with a task value");
|
throw new InternalExpressionException("'task_completed' could only be used with a task value");
|
||||||
return new NumericValue(((ThreadValue) v).isFinished());
|
return BooleanValue.of(((ThreadValue) v).isFinished());
|
||||||
});
|
});
|
||||||
|
|
||||||
// lazy cause expr is evaluated in the same type
|
// lazy cause expr is evaluated in the same type
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import carpet.script.exception.ThrowStatement;
|
|||||||
import carpet.script.exception.Throwables;
|
import carpet.script.exception.Throwables;
|
||||||
import carpet.script.language.Sys;
|
import carpet.script.language.Sys;
|
||||||
import carpet.script.value.BlockValue;
|
import carpet.script.value.BlockValue;
|
||||||
|
import carpet.script.value.BooleanValue;
|
||||||
import carpet.script.value.EntityValue;
|
import carpet.script.value.EntityValue;
|
||||||
import carpet.script.value.FormattedTextValue;
|
import carpet.script.value.FormattedTextValue;
|
||||||
import carpet.script.value.ListValue;
|
import carpet.script.value.ListValue;
|
||||||
@@ -1023,7 +1024,7 @@ public class ShapeDispatcher
|
|||||||
@Override
|
@Override
|
||||||
public Value decode(NbtElement tag)
|
public Value decode(NbtElement tag)
|
||||||
{
|
{
|
||||||
return new NumericValue(((NbtByte) tag).byteValue() > 0);
|
return BooleanValue.of(((NbtByte) tag).byteValue() > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class FloatParam extends NumericParam
|
public static class FloatParam extends NumericParam
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class SystemInfo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
put("game_difficulty", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getDifficulty().getName()));
|
put("game_difficulty", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getDifficulty().getName()));
|
||||||
put("game_hardcore", c -> new NumericValue(c.s.getMinecraftServer().getSaveProperties().isHardcore()));
|
put("game_hardcore", c -> BooleanValue.of(c.s.getMinecraftServer().getSaveProperties().isHardcore()));
|
||||||
put("game_storage_format", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getFormatName(c.s.getMinecraftServer().getSaveProperties().getVersion())));
|
put("game_storage_format", c -> StringValue.of(c.s.getMinecraftServer().getSaveProperties().getFormatName(c.s.getMinecraftServer().getSaveProperties().getVersion())));
|
||||||
put("game_default_gamemode", c -> StringValue.of(c.s.getMinecraftServer().getDefaultGameMode().getName()));
|
put("game_default_gamemode", c -> StringValue.of(c.s.getMinecraftServer().getDefaultGameMode().getName()));
|
||||||
put("game_max_players", c -> new NumericValue(c.s.getMinecraftServer().getMaxPlayerCount()));
|
put("game_max_players", c -> new NumericValue(c.s.getMinecraftServer().getMaxPlayerCount()));
|
||||||
@@ -82,7 +82,7 @@ public class SystemInfo {
|
|||||||
put("game_pack_version", c->NumericValue.of(SharedConstants.getGameVersion().getPackVersion()));
|
put("game_pack_version", c->NumericValue.of(SharedConstants.getGameVersion().getPackVersion()));
|
||||||
|
|
||||||
put("server_ip", c -> StringValue.of(c.s.getMinecraftServer().getServerIp()));
|
put("server_ip", c -> StringValue.of(c.s.getMinecraftServer().getServerIp()));
|
||||||
put("server_whitelisted", c -> new NumericValue(c.s.getMinecraftServer().isEnforceWhitelist()));
|
put("server_whitelisted", c -> BooleanValue.of(c.s.getMinecraftServer().isEnforceWhitelist()));
|
||||||
put("server_whitelist", c -> {
|
put("server_whitelist", c -> {
|
||||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||||
for (String s: c.s.getMinecraftServer().getPlayerManager().getWhitelistedNames())
|
for (String s: c.s.getMinecraftServer().getPlayerManager().getWhitelistedNames())
|
||||||
@@ -107,7 +107,7 @@ public class SystemInfo {
|
|||||||
}
|
}
|
||||||
return whitelist;
|
return whitelist;
|
||||||
});
|
});
|
||||||
put("server_dev_environment", c-> new NumericValue(FabricLoader.getInstance().isDevelopmentEnvironment()));
|
put("server_dev_environment", c-> BooleanValue.of(FabricLoader.getInstance().isDevelopmentEnvironment()));
|
||||||
put("server_mods", c -> {
|
put("server_mods", c -> {
|
||||||
Map<Value, Value> ret = new HashMap<>();
|
Map<Value, Value> ret = new HashMap<>();
|
||||||
for (ModContainer mod : FabricLoader.getInstance().getAllMods())
|
for (ModContainer mod : FabricLoader.getInstance().getAllMods())
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class BooleanValue extends NumericValue
|
|||||||
|
|
||||||
public static BooleanValue of(boolean value)
|
public static BooleanValue of(boolean value)
|
||||||
{
|
{
|
||||||
return value?TRUE:FALSE;
|
return value ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package carpet.script.value;
|
package carpet.script.value;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
|
||||||
import carpet.fakes.BrainInterface;
|
import carpet.fakes.BrainInterface;
|
||||||
import carpet.fakes.EntityInterface;
|
import carpet.fakes.EntityInterface;
|
||||||
import carpet.fakes.ItemEntityInterface;
|
import carpet.fakes.ItemEntityInterface;
|
||||||
@@ -60,7 +59,6 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.tag.Tag;
|
import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.text.LiteralText;
|
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.TypeFilter;
|
import net.minecraft.util.TypeFilter;
|
||||||
@@ -425,7 +423,7 @@ public class EntityValue extends Value
|
|||||||
|
|
||||||
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
||||||
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
||||||
put("removed", (entity, arg) -> new NumericValue(entity.isRemoved()));
|
put("removed", (entity, arg) -> BooleanValue.of(entity.isRemoved()));
|
||||||
put("uuid",(e, a) -> new StringValue(e.getUuidAsString()));
|
put("uuid",(e, a) -> new StringValue(e.getUuidAsString()));
|
||||||
put("id",(e, a) -> new NumericValue(e.getId()));
|
put("id",(e, a) -> new NumericValue(e.getId()));
|
||||||
put("pos", (e, a) -> ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ())));
|
put("pos", (e, a) -> ListValue.of(new NumericValue(e.getX()), new NumericValue(e.getY()), new NumericValue(e.getZ())));
|
||||||
@@ -441,30 +439,30 @@ public class EntityValue extends Value
|
|||||||
put("motion_x", (e, a) -> new NumericValue(e.getVelocity().x));
|
put("motion_x", (e, a) -> new NumericValue(e.getVelocity().x));
|
||||||
put("motion_y", (e, a) -> new NumericValue(e.getVelocity().y));
|
put("motion_y", (e, a) -> new NumericValue(e.getVelocity().y));
|
||||||
put("motion_z", (e, a) -> new NumericValue(e.getVelocity().z));
|
put("motion_z", (e, a) -> new NumericValue(e.getVelocity().z));
|
||||||
put("on_ground", (e, a) -> new NumericValue(e.isOnGround()));
|
put("on_ground", (e, a) -> BooleanValue.of(e.isOnGround()));
|
||||||
put("name", (e, a) -> new StringValue(e.getName().getString()));
|
put("name", (e, a) -> new StringValue(e.getName().getString()));
|
||||||
put("display_name", (e, a) -> new FormattedTextValue(e.getDisplayName()));
|
put("display_name", (e, a) -> new FormattedTextValue(e.getDisplayName()));
|
||||||
put("command_name", (e, a) -> new StringValue(e.getEntityName()));
|
put("command_name", (e, a) -> new StringValue(e.getEntityName()));
|
||||||
put("custom_name", (e, a) -> e.hasCustomName()?new StringValue(e.getCustomName().getString()):Value.NULL);
|
put("custom_name", (e, a) -> e.hasCustomName()?new StringValue(e.getCustomName().getString()):Value.NULL);
|
||||||
put("type", (e, a) -> new StringValue(nameFromRegistryId(Registry.ENTITY_TYPE.getId(e.getType()))));
|
put("type", (e, a) -> new StringValue(nameFromRegistryId(Registry.ENTITY_TYPE.getId(e.getType()))));
|
||||||
put("is_riding", (e, a) -> new NumericValue(e.hasVehicle()));
|
put("is_riding", (e, a) -> BooleanValue.of(e.hasVehicle()));
|
||||||
put("is_ridden", (e, a) -> new NumericValue(e.hasPassengers()));
|
put("is_ridden", (e, a) -> BooleanValue.of(e.hasPassengers()));
|
||||||
put("passengers", (e, a) -> ListValue.wrap(e.getPassengerList().stream().map(EntityValue::new).collect(Collectors.toList())));
|
put("passengers", (e, a) -> ListValue.wrap(e.getPassengerList().stream().map(EntityValue::new).collect(Collectors.toList())));
|
||||||
put("mount", (e, a) -> (e.getVehicle()!=null)?new EntityValue(e.getVehicle()):Value.NULL);
|
put("mount", (e, a) -> (e.getVehicle()!=null)?new EntityValue(e.getVehicle()):Value.NULL);
|
||||||
put("unmountable", (e, a) -> new NumericValue(((EntityInterface)e).isPermanentVehicle()));
|
put("unmountable", (e, a) -> BooleanValue.of(((EntityInterface)e).isPermanentVehicle()));
|
||||||
// deprecated
|
// deprecated
|
||||||
put("tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
put("tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||||
|
|
||||||
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||||
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList())));
|
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList())));
|
||||||
// deprecated
|
// deprecated
|
||||||
put("has_tag", (e, a) -> new NumericValue(e.getScoreboardTags().contains(a.getString())));
|
put("has_tag", (e, a) -> BooleanValue.of(e.getScoreboardTags().contains(a.getString())));
|
||||||
|
|
||||||
put("has_scoreboard_tag", (e, a) -> new NumericValue(e.getScoreboardTags().contains(a.getString())));
|
put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getScoreboardTags().contains(a.getString())));
|
||||||
put("has_entity_tag", (e, a) -> {
|
put("has_entity_tag", (e, a) -> {
|
||||||
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
|
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
|
||||||
if (tag == null) return Value.NULL;
|
if (tag == null) return Value.NULL;
|
||||||
return new NumericValue(e.getType().isIn(tag));
|
return BooleanValue.of(e.getType().isIn(tag));
|
||||||
});
|
});
|
||||||
|
|
||||||
put("yaw", (e, a)-> new NumericValue(e.getYaw()));
|
put("yaw", (e, a)-> new NumericValue(e.getYaw()));
|
||||||
@@ -488,13 +486,13 @@ public class EntityValue extends Value
|
|||||||
Vec3d look = e.getRotationVector();
|
Vec3d look = e.getRotationVector();
|
||||||
return ListValue.of(new NumericValue(look.x),new NumericValue(look.y),new NumericValue(look.z));
|
return ListValue.of(new NumericValue(look.x),new NumericValue(look.y),new NumericValue(look.z));
|
||||||
});
|
});
|
||||||
put("is_burning", (e, a) -> new NumericValue(e.isOnFire()));
|
put("is_burning", (e, a) -> BooleanValue.of(e.isOnFire()));
|
||||||
put("fire", (e, a) -> new NumericValue(e.getFireTicks()));
|
put("fire", (e, a) -> new NumericValue(e.getFireTicks()));
|
||||||
put("silent", (e, a)-> new NumericValue(e.isSilent()));
|
put("silent", (e, a)-> BooleanValue.of(e.isSilent()));
|
||||||
put("gravity", (e, a) -> new NumericValue(!e.hasNoGravity()));
|
put("gravity", (e, a) -> BooleanValue.of(!e.hasNoGravity()));
|
||||||
put("immune_to_fire", (e, a) -> new NumericValue(e.isFireImmune()));
|
put("immune_to_fire", (e, a) -> BooleanValue.of(e.isFireImmune()));
|
||||||
|
|
||||||
put("invulnerable", (e, a) -> new NumericValue(e.isInvulnerable()));
|
put("invulnerable", (e, a) -> BooleanValue.of(e.isInvulnerable()));
|
||||||
put("dimension", (e, a) -> new StringValue(nameFromRegistryId(e.world.getRegistryKey().getValue()))); // getDimId
|
put("dimension", (e, a) -> new StringValue(nameFromRegistryId(e.world.getRegistryKey().getValue()))); // getDimId
|
||||||
put("height", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).height));
|
put("height", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).height));
|
||||||
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
|
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
|
||||||
@@ -502,13 +500,13 @@ public class EntityValue extends Value
|
|||||||
put("age", (e, a) -> new NumericValue(e.age));
|
put("age", (e, a) -> new NumericValue(e.age));
|
||||||
put("breeding_age", (e, a) -> e instanceof PassiveEntity?new NumericValue(((PassiveEntity) e).getBreedingAge()):Value.NULL);
|
put("breeding_age", (e, a) -> e instanceof PassiveEntity?new NumericValue(((PassiveEntity) e).getBreedingAge()):Value.NULL);
|
||||||
put("despawn_timer", (e, a) -> e instanceof LivingEntity?new NumericValue(((LivingEntity) e).getDespawnCounter()):Value.NULL);
|
put("despawn_timer", (e, a) -> e instanceof LivingEntity?new NumericValue(((LivingEntity) e).getDespawnCounter()):Value.NULL);
|
||||||
put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL);
|
put("item", (e, a) -> (e instanceof ItemEntity)?ValueConversions.of(((ItemEntity) e).getStack()):Value.NULL);
|
||||||
put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL);
|
put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL);
|
||||||
put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelayCM()):Value.NULL);
|
put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelayCM()):Value.NULL);
|
||||||
put("portal_cooldown", (e , a) ->new NumericValue(((EntityInterface)e).getPortalTimer()));
|
put("portal_cooldown", (e , a) ->new NumericValue(((EntityInterface)e).getPortalTimer()));
|
||||||
put("portal_timer", (e , a) ->new NumericValue(((EntityInterface)e).getPublicNetherPortalCooldown()));
|
put("portal_timer", (e , a) ->new NumericValue(((EntityInterface)e).getPublicNetherPortalCooldown()));
|
||||||
// ItemEntity -> despawn timer via ssGetAge
|
// ItemEntity -> despawn timer via ssGetAge
|
||||||
put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL);
|
put("is_baby", (e, a) -> (e instanceof LivingEntity)?BooleanValue.of(((LivingEntity) e).isBaby()):Value.NULL);
|
||||||
put("target", (e, a) -> {
|
put("target", (e, a) -> {
|
||||||
if (e instanceof MobEntity)
|
if (e instanceof MobEntity)
|
||||||
{
|
{
|
||||||
@@ -536,7 +534,7 @@ public class EntityValue extends Value
|
|||||||
ValueConversions.of(spe.getSpawnPointPosition()),
|
ValueConversions.of(spe.getSpawnPointPosition()),
|
||||||
ValueConversions.of(spe.getSpawnPointDimension()),
|
ValueConversions.of(spe.getSpawnPointDimension()),
|
||||||
new NumericValue(spe.getSpawnAngle()),
|
new NumericValue(spe.getSpawnAngle()),
|
||||||
new NumericValue(spe.isSpawnPointSet()) // true if forced spawn point
|
BooleanValue.of(spe.isSpawnPointSet())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
@@ -546,7 +544,7 @@ public class EntityValue extends Value
|
|||||||
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
||||||
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
||||||
put("swinging", (e, a) -> {
|
put("swinging", (e, a) -> {
|
||||||
if (e instanceof LivingEntity) return new NumericValue(((LivingEntity) e).handSwinging);
|
if (e instanceof LivingEntity) return BooleanValue.of(((LivingEntity) e).handSwinging);
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -558,7 +556,7 @@ public class EntityValue extends Value
|
|||||||
return StringValue.of(lang);
|
return StringValue.of(lang);
|
||||||
});
|
});
|
||||||
put("persistence", (e, a) -> {
|
put("persistence", (e, a) -> {
|
||||||
if (e instanceof MobEntity) return new NumericValue(((MobEntity) e).isPersistent());
|
if (e instanceof MobEntity) return BooleanValue.of(((MobEntity) e).isPersistent());
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
put("hunger", (e, a) -> {
|
put("hunger", (e, a) -> {
|
||||||
@@ -750,7 +748,7 @@ public class EntityValue extends Value
|
|||||||
if (where == null)
|
if (where == null)
|
||||||
throw new InternalExpressionException("Unknown inventory slot: "+a.getString());
|
throw new InternalExpressionException("Unknown inventory slot: "+a.getString());
|
||||||
if (e instanceof LivingEntity)
|
if (e instanceof LivingEntity)
|
||||||
return ListValue.fromItemStack(((LivingEntity)e).getEquippedStack(where));
|
return ValueConversions.of(((LivingEntity)e).getEquippedStack(where));
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1474,7 +1472,7 @@ public class EntityValue extends Value
|
|||||||
});
|
});
|
||||||
|
|
||||||
put("add_exhaustion", (e, v)-> {
|
put("add_exhaustion", (e, v)-> {
|
||||||
if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().addExhaustion((int) NumericValue.asNumber(v).getLong());
|
if (e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().addExhaustion(NumericValue.asNumber(v).getFloat());
|
||||||
});
|
});
|
||||||
|
|
||||||
put("absorption", (e, v) -> {
|
put("absorption", (e, v) -> {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import carpet.script.LazyValue;
|
|||||||
import carpet.script.exception.InternalExpressionException;
|
import carpet.script.exception.InternalExpressionException;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.AbstractNbtNumber;
|
import net.minecraft.nbt.AbstractNbtNumber;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtDouble;
|
import net.minecraft.nbt.NbtDouble;
|
||||||
@@ -75,12 +74,6 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
|||||||
items = list;
|
items = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static Value fromItemStack(ItemStack itemstack)
|
|
||||||
{
|
|
||||||
return ValueConversions.of(itemstack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Value fromTriple(double a, double b, double c)
|
public static Value fromTriple(double a, double b, double c)
|
||||||
{
|
{
|
||||||
return ListValue.of(new NumericValue(a), new NumericValue(b), new NumericValue(c));
|
return ListValue.of(new NumericValue(a), new NumericValue(b), new NumericValue(c));
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static java.lang.Math.signum;
|
|||||||
|
|
||||||
public class NumericValue extends Value
|
public class NumericValue extends Value
|
||||||
{
|
{
|
||||||
private final Double value;
|
private final double value;
|
||||||
private Long longValue;
|
private Long longValue;
|
||||||
private final static double epsilon = abs(32*((7*0.1)*10-7));
|
private final static double epsilon = abs(32*((7*0.1)*10-7));
|
||||||
private final static MathContext displayRounding = new MathContext(12, RoundingMode.HALF_EVEN);
|
private final static MathContext displayRounding = new MathContext(12, RoundingMode.HALF_EVEN);
|
||||||
@@ -56,8 +56,8 @@ public class NumericValue extends Value
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (value.isInfinite()) return "INFINITY";
|
if (Double.isInfinite(value)) return "INFINITY";
|
||||||
if (value.isNaN()) return "NaN";
|
if (Double.isNaN(value)) return "NaN";
|
||||||
if (abs(value) < epsilon) return (signum(value) < 0)?"-0":"0"; //zero rounding fails with big decimals
|
if (abs(value) < epsilon) return (signum(value) < 0)?"-0":"0"; //zero rounding fails with big decimals
|
||||||
// dobules have 16 point precision, 12 is plenty to display
|
// dobules have 16 point precision, 12 is plenty to display
|
||||||
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
|
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
|
||||||
@@ -93,7 +93,7 @@ public class NumericValue extends Value
|
|||||||
}
|
}
|
||||||
public float getFloat()
|
public float getFloat()
|
||||||
{
|
{
|
||||||
return value.floatValue();
|
return (float) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long floor(double double_1) {
|
private static long floor(double double_1) {
|
||||||
@@ -178,7 +178,7 @@ public class NumericValue extends Value
|
|||||||
NumericValue no = (NumericValue)o;
|
NumericValue no = (NumericValue)o;
|
||||||
if (longValue != null && no.longValue != null)
|
if (longValue != null && no.longValue != null)
|
||||||
return longValue.compareTo(no.longValue);
|
return longValue.compareTo(no.longValue);
|
||||||
return value.compareTo(no.value);
|
return Double.compare(value, no.value);
|
||||||
}
|
}
|
||||||
return getString().compareTo(o.getString());
|
return getString().compareTo(o.getString());
|
||||||
}
|
}
|
||||||
@@ -227,6 +227,13 @@ public class NumericValue extends Value
|
|||||||
this.longValue = value;
|
this.longValue = value;
|
||||||
this.value = (double)value;
|
this.value = (double)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a legacy {@link NumericValue} for a {@code boolean}.
|
||||||
|
* @param boolval The boolean to set 1 or 0 for this {@link NumericValue}
|
||||||
|
* @deprecated Use {@link BooleanValue#of(boolean)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public NumericValue(boolean boolval)
|
public NumericValue(boolean boolval)
|
||||||
{
|
{
|
||||||
this(boolval?1L:0L);
|
this(boolval?1L:0L);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class ValueConversions
|
|||||||
{
|
{
|
||||||
return ListValue.of(
|
return ListValue.of(
|
||||||
StringValue.of(criteria.getName()),
|
StringValue.of(criteria.getName()),
|
||||||
new NumericValue(criteria.isReadOnly())
|
BooleanValue.of(criteria.isReadOnly())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class ValueConversions
|
|||||||
new BlockValue(null, world, node.getBlockPos()),
|
new BlockValue(null, world, node.getBlockPos()),
|
||||||
new StringValue(node.type.name().toLowerCase(Locale.ROOT)),
|
new StringValue(node.type.name().toLowerCase(Locale.ROOT)),
|
||||||
new NumericValue(node.penalty),
|
new NumericValue(node.penalty),
|
||||||
new NumericValue(node.visited)
|
BooleanValue.of(node.visited)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return ListValue.wrap(nodes);
|
return ListValue.wrap(nodes);
|
||||||
@@ -243,7 +243,7 @@ public class ValueConversions
|
|||||||
}
|
}
|
||||||
if (v instanceof Boolean)
|
if (v instanceof Boolean)
|
||||||
{
|
{
|
||||||
return new NumericValue((Boolean) v);
|
return BooleanValue.of((Boolean) v);
|
||||||
}
|
}
|
||||||
if (v instanceof UUID)
|
if (v instanceof UUID)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user