mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 18:09:27 +00:00
添加捡起物品触发器
This commit is contained in:
@@ -48,4 +48,6 @@ public interface Entity {
|
||||
}
|
||||
|
||||
<T> void setEntityData(EntityData<T> data, T value, boolean force);
|
||||
|
||||
void remove();
|
||||
}
|
||||
|
||||
@@ -180,4 +180,8 @@ public abstract class Player extends AbstractEntity implements NetWorkUser {
|
||||
public abstract Locale selectedLocale();
|
||||
|
||||
public abstract void setSelectedLocale(@Nullable Locale locale);
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public class EventFunctions {
|
||||
register(CommonFunctions.TOAST, new ToastFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.DAMAGE, new DamageFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.MERCHANT_TRADE, new MerchantTradeFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.REMOVE_ENTITY, new RemoveEntityFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
}
|
||||
|
||||
public static void register(Key key, FunctionFactory<PlayerOptionalContext> factory) {
|
||||
|
||||
@@ -10,6 +10,7 @@ public enum EventTrigger {
|
||||
CONSUME("eat", "consume", "drink"),
|
||||
BREAK("break", "dig"),
|
||||
PLACE("place", "build"),
|
||||
PICK_UP("pick_up", "pick"),
|
||||
STEP("step"),;
|
||||
|
||||
public static final Map<String, EventTrigger> BY_NAME = new HashMap<>();
|
||||
|
||||
@@ -36,4 +36,5 @@ public final class CommonFunctions {
|
||||
public static final Key SET_VARIABLE = Key.of("craftengine:set_variable");
|
||||
public static final Key DAMAGE = Key.of("craftengine:damage");
|
||||
public static final Key MERCHANT_TRADE = Key.of("craftengine:merchant_trade");
|
||||
public static final Key REMOVE_ENTITY = Key.of("craftengine:remove_entity");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
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.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RemoveEntityFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
|
||||
public RemoveEntityFunction(List<Condition<CTX>> predicates) {
|
||||
super(predicates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInternal(CTX ctx) {
|
||||
ctx.getOptionalParameter(DirectContextParameters.ENTITY).ifPresent(Entity::remove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonFunctions.REMOVE_ENTITY;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
|
||||
|
||||
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||
super(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> arguments) {
|
||||
return new RemoveEntityFunction<>(getPredicates(arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,4 +65,5 @@ public final class DirectContextParameters {
|
||||
public static final ContextKey<Boolean> IS_CUSTOM = ContextKey.direct("is_custom");
|
||||
public static final ContextKey<Boolean> IS_BLOCK_ITEM = ContextKey.direct("is_block_item");
|
||||
public static final ContextKey<GameMode> GAMEMODE = ContextKey.direct("gamemode");
|
||||
public static final ContextKey<Integer> COUNT = ContextKey.direct("count");
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ItemParameterProvider implements ChainParameterProvider<Item<?>> {
|
||||
CONTEXT_FUNCTIONS.put(DirectContextParameters.ID, Item::id);
|
||||
CONTEXT_FUNCTIONS.put(DirectContextParameters.CUSTOM_MODEL_DATA, i -> i.customModelData().orElse(null));
|
||||
CONTEXT_FUNCTIONS.put(DirectContextParameters.IS_CUSTOM, Item::isCustomItem);
|
||||
CONTEXT_FUNCTIONS.put(DirectContextParameters.COUNT, Item::count);
|
||||
CONTEXT_FUNCTIONS.put(DirectContextParameters.IS_BLOCK_ITEM, Item::isBlockItem);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user