diff --git a/src/main/java/carpet/script/api/Entities.java b/src/main/java/carpet/script/api/Entities.java index b76c5622..b4e8a33e 100644 --- a/src/main/java/carpet/script/api/Entities.java +++ b/src/main/java/carpet/script/api/Entities.java @@ -244,7 +244,7 @@ public class Entities { { if (lv.size() > 1) throw new InternalExpressionException("'entity_types' requires one or no arguments"); String desc = (lv.size() == 1)?lv.get(0).getString():"*"; - return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getServer()).listValue; + return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getServer()).listValue(); }); expression.addContextFunction("entity_load_handler", -1, (c, t, lv) -> @@ -255,7 +255,7 @@ public class Entities { ? ((ListValue) entityValue).getItems().stream().map(Value::getString).collect(Collectors.toList()) : Collections.singletonList(entityValue.getString()); Set> types = new HashSet<>(); - descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getServer()).typeList)); + descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getServer()).types)); FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false); CarpetEventServer events = ((CarpetScriptHost)c.host).scriptServer().events; if (funArg.function == null) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index a082c7c5..718e15f5 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -283,29 +283,15 @@ public class EntityValue extends Value public static class EntityClassDescriptor { - public EntityTypeTest directType; // interface of EntityType - public Predicate filteringPredicate; - public List> typeList; - public Value listValue; - EntityClassDescriptor(EntityType type, Predicate predicate, List> types) - { - directType = type; - filteringPredicate = predicate; - typeList = types; - listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et)))).collect(Collectors.toList())); - } + public final EntityTypeTest directType; // interface of EntityType + public final Predicate filteringPredicate; + public final List> types; - EntityClassDescriptor( EntityTypeTest type, Predicate predicate, List> types) + EntityClassDescriptor(EntityTypeTest type, Predicate predicate, List> types) { - directType = type; - filteringPredicate = predicate; - typeList = types; - listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et)))).collect(Collectors.toList())); - } - - EntityClassDescriptor(EntityType type, Predicate predicate, Stream> types) - { - this(type, predicate, types.toList()); + this.directType = type; + this.filteringPredicate = predicate; + this.types = types; } EntityClassDescriptor(EntityTypeTest type, Predicate predicate, Stream> types) @@ -313,6 +299,10 @@ public class EntityValue extends Value this(type, predicate, types.toList()); } + public Value listValue() { + return ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et))))); + } + public final static Map byName = new HashMap<>() {{ List> allTypes = Registry.ENTITY_TYPE.stream().toList(); // nonliving types