Attack Condition (Entity / Player)

基本信息

属性 值
父类 AttackConditionHandler(抽象)
子类 ID attack.entity, attack.player
事件订阅 Forge MinecraftForge.EVENT_BUS(net.minecraftforge.event.entity.living.LivingAttackEvent)
优先级 LOWEST

两个子 handler 共享同一套配置(damage + damageTypes + isDamageTypesAllowList + entities + isEntitiesAllowList),仅目标维度不同——攻击者视角 vs 受伤者视角。

配置字段(共享)

字段 类型 默认 含义
damage 浮点 0.0 最小伤害阈值(event.ammount >= damage)
damageTypes 字符串或字符串数组 [] 伤害源类型过滤器(event.source.getDamageType(),例如 "player"、"mob"、"fall")
isDamageTypesAllowList 布尔 false damageTypes 是否为白名单;为 true 时仅命中集合内类型触发
entities 字符串或字符串数组 [] 实体类名过滤器(原版 entity 名优先,回退 Class.forName)
isEntitiesAllowList 布尔 false entities 是否为白名单;为 true 时仅命中集合内实体类触发

子变体差异

子类 ID getPlayer(event) getEntityClass(event) 适用场景
attack.entity 攻击源 instanceof EntityPlayer 时返回该玩家 event.entityLiving.getClass()(被攻击生物类) “玩家攻击某生物时”
attack.player event.entityLiving instanceof EntityPlayer(被攻击的玩家) 攻击源 instanceof EntityLivingBase 时返回该类 “玩家被打(或攻击某实体的玩家)时”

两者都通过 XOR 校验 allow-list 与集合命中:

sources.contains(damageType) ^ isDamageTypesAllowList    // 命中则进入下一步
entities.contains(targetClass) ^ isEntitiesAllowList

注册流程

  • AchievementConditionHandler.parse() 在这里被复用于两条 attack.* 注册项(见 AmazingTrophies.registerConditionHandlers)。
  • Entity 子类实例:AttackConditionHandler.Entity::new
  • Player 子类实例:AttackConditionHandler.Player::new

JSON 示例

玩家攻击末影龙 ≥ 20 伤害:

{
  "id": "dragon_slayer",
  "x": 5, "y": 1,
  "icon": { "registryName": "minecraft:diamond_sword" },
  "condition": {
    "type": "attack.entity",
    "damage": 20.0,
    "entities": ["EnderDragon"],
    "isEntitiesAllowList": true
  }
}

相关条目

源码

src/main/java/glowredman/amazingtrophies/condition/AttackConditionHandler.java