mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
@@ -169,6 +169,7 @@ public final class InteractUtils {
|
||||
registerInteraction(BlockKeys.DAMAGED_ANVIL, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.FURNACE, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.CRAFTING_TABLE, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.CARTOGRAPHY_TABLE, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.STONECUTTER, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.SMITHING_TABLE, (player, item, blockState, result) -> true);
|
||||
registerInteraction(BlockKeys.LOOM, (player, item, blockState, result) -> true);
|
||||
|
||||
@@ -8,6 +8,7 @@ public final class BlockKeys {
|
||||
public static final Key NOTE_BLOCK = Key.of("minecraft:note_block");
|
||||
public static final Key TRIPWIRE = Key.of("minecraft:tripwire");
|
||||
public static final Key CRAFTING_TABLE = Key.of("minecraft:crafting_table");
|
||||
public static final Key CARTOGRAPHY_TABLE = Key.of("minecraft:cartography_table");
|
||||
public static final Key STONECUTTER = Key.of("minecraft:stonecutter");
|
||||
public static final Key BELL = Key.of("minecraft:bell");
|
||||
public static final Key SMITHING_TABLE = Key.of("minecraft:smithing_table");
|
||||
@@ -176,8 +177,6 @@ public final class BlockKeys {
|
||||
public static final Key WAXED_OXIDIZED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_oxidized_copper_trapdoor");
|
||||
public static final Key WAXED_WEATHERED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_weathered_copper_trapdoor");
|
||||
|
||||
|
||||
|
||||
public static final Key OAK_FENCE_GATE = Key.of("minecraft:oak_fence_gate");
|
||||
public static final Key SPRUCE_FENCE_GATE = Key.of("minecraft:spruce_fence_gate");
|
||||
public static final Key BIRCH_FENCE_GATE = Key.of("minecraft:birch_fence_gate");
|
||||
|
||||
@@ -22,7 +22,7 @@ public class MatchBlockTypeCondition<CTX extends Context> implements Condition<C
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonConditions.MATCH_ENTITY_TYPE;
|
||||
return CommonConditions.MATCH_BLOCK_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.condition;
|
||||
package net.momirealms.craftengine.core.plugin.context.condition;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.Entity;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.entity.Entity;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MatchEntityTypeCondition<CTX extends Context> implements Condition<CTX> {
|
||||
private final Set<String> ids;
|
||||
private final boolean regexMatch;
|
||||
public class MatchEntityTypeCondition<CTX extends Context> implements Condition<CTX> {
|
||||
private final Set<String> ids;
|
||||
private final boolean regexMatch;
|
||||
|
||||
public MatchEntityTypeCondition(Collection<String> ids, boolean regexMatch) {
|
||||
this.ids = new HashSet<>(ids);
|
||||
this.regexMatch = regexMatch;
|
||||
}
|
||||
public MatchEntityTypeCondition(Collection<String> ids, boolean regexMatch) {
|
||||
this.ids = new HashSet<>(ids);
|
||||
this.regexMatch = regexMatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonConditions.MATCH_ENTITY_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CTX ctx) {
|
||||
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
|
||||
return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent();
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonConditions.MATCH_ENTITY_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CTX ctx) {
|
||||
Optional<Entity> entity = ctx.getOptionalParameter(DirectContextParameters.ENTITY);
|
||||
return entity.filter(value -> MiscUtils.matchRegex(value.type().asString(), this.ids, this.regexMatch)).isPresent();
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements ConditionFactory<CTX> {
|
||||
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
||||
if (ids.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.match_entity_type.missing_id");
|
||||
}
|
||||
boolean regex = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("regex", false), "regex");
|
||||
return new MatchEntityTypeCondition<>(ids, regex);
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
||||
if (ids.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.match_entity_type.missing_id");
|
||||
}
|
||||
boolean regex = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("regex", false), "regex");
|
||||
return new MatchEntityTypeCondition<>(ids, regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user