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:
gnembon committed 2021-05-25 01:08:32 -03:00
commit c720c2c935
18 files changed
+83 -110

No files matched your search

@@ -18,7 +18,7 @@ public class BooleanValue extends NumericValue
public static BooleanValue of(boolean value)
{
return value?TRUE:FALSE;
return value ? TRUE : FALSE;
}
@Override
@@ -1,6 +1,5 @@
package carpet.script.value;
import carpet.CarpetServer;
import carpet.fakes.BrainInterface;
import carpet.fakes.EntityInterface;
import carpet.fakes.ItemEntityInterface;
@@ -60,7 +59,6 @@ import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.Tag;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
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>>() {{
//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("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())));
@@ -441,30 +439,30 @@ public class EntityValue extends Value
put("motion_x", (e, a) -> new NumericValue(e.getVelocity().x));
put("motion_y", (e, a) -> new NumericValue(e.getVelocity().y));
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("display_name", (e, a) -> new FormattedTextValue(e.getDisplayName()));
put("command_name", (e, a) -> new StringValue(e.getEntityName()));
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("is_riding", (e, a) -> new NumericValue(e.hasVehicle()));
put("is_ridden", (e, a) -> new NumericValue(e.hasPassengers()));
put("is_riding", (e, a) -> BooleanValue.of(e.hasVehicle()));
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("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
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("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
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) -> {
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
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()));
@@ -488,13 +486,13 @@ public class EntityValue extends Value
Vec3d look = e.getRotationVector();
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("silent", (e, a)-> new NumericValue(e.isSilent()));
put("gravity", (e, a) -> new NumericValue(!e.hasNoGravity()));
put("immune_to_fire", (e, a) -> new NumericValue(e.isFireImmune()));
put("silent", (e, a)-> BooleanValue.of(e.isSilent()));
put("gravity", (e, a) -> BooleanValue.of(!e.hasNoGravity()));
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("height", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).height));
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("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("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("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_timer", (e , a) ->new NumericValue(((EntityInterface)e).getPublicNetherPortalCooldown()));
// 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) -> {
if (e instanceof MobEntity)
{
@@ -536,7 +534,7 @@ public class EntityValue extends Value
ValueConversions.of(spe.getSpawnPointPosition()),
ValueConversions.of(spe.getSpawnPointDimension()),
new NumericValue(spe.getSpawnAngle()),
new NumericValue(spe.isSpawnPointSet()) // true if forced spawn point
BooleanValue.of(spe.isSpawnPointSet())
);
}
return Value.NULL;
@@ -546,7 +544,7 @@ public class EntityValue extends Value
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
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;
});
@@ -558,7 +556,7 @@ public class EntityValue extends Value
return StringValue.of(lang);
});
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;
});
put("hunger", (e, a) -> {
@@ -750,7 +748,7 @@ public class EntityValue extends Value
if (where == null)
throw new InternalExpressionException("Unknown inventory slot: "+a.getString());
if (e instanceof LivingEntity)
return ListValue.fromItemStack(((LivingEntity)e).getEquippedStack(where));
return ValueConversions.of(((LivingEntity)e).getEquippedStack(where));
return Value.NULL;
});
@@ -1474,7 +1472,7 @@ public class EntityValue extends Value
});
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) -> {
@@ -4,7 +4,6 @@ import carpet.script.LazyValue;
import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.AbstractNbtNumber;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtDouble;
@@ -75,12 +74,6 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
items = list;
}
@Deprecated
public static Value fromItemStack(ItemStack itemstack)
{
return ValueConversions.of(itemstack);
}
public static Value fromTriple(double a, double b, double 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
{
private final Double value;
private final double value;
private Long longValue;
private final static double epsilon = abs(32*((7*0.1)*10-7));
private final static MathContext displayRounding = new MathContext(12, RoundingMode.HALF_EVEN);
@@ -56,8 +56,8 @@ public class NumericValue extends Value
}
try
{
if (value.isInfinite()) return "INFINITY";
if (value.isNaN()) return "NaN";
if (Double.isInfinite(value)) return "INFINITY";
if (Double.isNaN(value)) return "NaN";
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
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
@@ -93,7 +93,7 @@ public class NumericValue extends Value
}
public float getFloat()
{
return value.floatValue();
return (float) value;
}
private static long floor(double double_1) {
@@ -178,7 +178,7 @@ public class NumericValue extends Value
NumericValue no = (NumericValue)o;
if (longValue != null && no.longValue != null)
return longValue.compareTo(no.longValue);
return value.compareTo(no.value);
return Double.compare(value, no.value);
}
return getString().compareTo(o.getString());
}
@@ -227,6 +227,13 @@ public class NumericValue extends Value
this.longValue = 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)
{
this(boolval?1L:0L);
@@ -102,7 +102,7 @@ public class ValueConversions
{
return ListValue.of(
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 StringValue(node.type.name().toLowerCase(Locale.ROOT)),
new NumericValue(node.penalty),
new NumericValue(node.visited)
BooleanValue.of(node.visited)
));
}
return ListValue.wrap(nodes);
@@ -243,7 +243,7 @@ public class ValueConversions
}
if (v instanceof Boolean)
{
return new NumericValue((Boolean) v);
return BooleanValue.of((Boolean) v);
}
if (v instanceof UUID)
{