9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +00:00

移动matchObject到MiscUtil类

This commit is contained in:
halogly
2025-08-23 16:00:01 +08:00
parent cdad8190f1
commit 0bdfdcd40a
5 changed files with 18 additions and 21 deletions

View File

@@ -30,18 +30,4 @@ public final class CommonConditions {
public static final Key EXPRESSION = Key.from("craftengine:expression");
public static final Key IS_NULL = Key.from("craftengine:is_null");
public static final Key HAND = Key.from("craftengine:hand");
public static boolean matchObject(Key key, boolean regexMatch, Set<String> ids) {
String id = key.toString();
if (regexMatch) {
for (String regex : ids) {
if (id.matches(regex)) {
return true;
}
}
} else {
return ids.contains(id);
}
return false;
}
}

View File

@@ -32,7 +32,7 @@ public class MatchBlockTypeCondition<CTX extends Context> implements Condition<C
if (block.isEmpty()) return false;
Optional<ImmutableBlockState> customBlock = ctx.getOptionalParameter(DirectContextParameters.CUSTOM_BLOCK_STATE);
Key key = customBlock.isPresent() ? customBlock.get().owner().value().id() : block.get().type();
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {

View File

@@ -30,7 +30,7 @@
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
if (entity.isEmpty()) return false;
Key key = entity.get().type();
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {

View File

@@ -30,7 +30,7 @@ public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
Optional<Item<?>> item = ctx.getOptionalParameter(DirectContextParameters.ITEM_IN_HAND);
if (item.isEmpty()) return false;
Key key = item.get().id();
return CommonConditions.matchObject(key, this.regexMatch, this.ids);
return MiscUtils.matchObject(key, this.regexMatch, this.ids);
}
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {

View File

@@ -4,10 +4,7 @@ import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigExce
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
public class MiscUtils {
@@ -153,4 +150,18 @@ public class MiscUtils {
return o;
}
}
public static boolean matchObject(Key key, boolean regexMatch, Set<String> ids) {
String id = key.toString();
if (regexMatch) {
for (String regex : ids) {
if (id.matches(regex)) {
return true;
}
}
} else {
return ids.contains(id);
}
return false;
}
}