9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

添加条件元素

This commit is contained in:
XiaoMoMi
2025-12-26 03:29:14 +08:00
parent 1122291e85
commit 368c3cad39
17 changed files with 199 additions and 282 deletions

View File

@@ -0,0 +1,37 @@
package net.momirealms.craftengine.core.entity.furniture.element;
import net.momirealms.craftengine.core.entity.furniture.Furniture;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
import net.momirealms.craftengine.core.plugin.context.PlayerContext;
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
import org.jetbrains.annotations.NotNull;
import java.util.function.Predicate;
public interface ConditionalFurnitureElement extends FurnitureElement {
@NotNull
Predicate<PlayerContext> viewCondition();
@NotNull
Furniture furniture();
boolean hasCondition();
@Override
default void show(Player player) {
if (hasCondition()) {
PlayerOptionalContext context = PlayerOptionalContext.of(player, ContextHolder.builder()
.withParameter(DirectContextParameters.FURNITURE, furniture()));
if (viewCondition().test(context)) {
showInternal(player);
}
} else {
showInternal(player);
}
}
void showInternal(Player player);
}

View File

@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.plugin.context;
import net.momirealms.craftengine.core.entity.player.Player;
public interface PlayerContext {
public interface PlayerContext extends Context {
Player player();
}

View File

@@ -49,7 +49,8 @@ public class EventConditions {
.register(ResourceKey.create(Registries.EVENT_CONDITION_FACTORY.location(), key), factory);
}
public static Condition<Context> fromMap(Map<String, Object> map) {
@SuppressWarnings("unchecked")
public static <CTX extends Context> Condition<CTX> fromMap(Map<String, Object> map) {
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.event.condition.missing_type");
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
if (key.value().charAt(0) == '!') {
@@ -57,13 +58,13 @@ public class EventConditions {
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
}
return new InvertedCondition<>(factory.create(map));
return new InvertedCondition<>((Condition<CTX>) factory.create(map));
} else {
ConditionFactory<Context> factory = BuiltInRegistries.EVENT_CONDITION_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.event.condition.invalid_type", type);
}
return factory.create(map);
return (Condition<CTX>) factory.create(map);
}
}
}

View File

@@ -1,10 +0,0 @@
package net.momirealms.craftengine.core.world;
import net.momirealms.craftengine.core.util.LegacyChatFormatter;
import org.jetbrains.annotations.Nullable;
public interface Glowing {
@Nullable
LegacyChatFormatter glowColor();
}