重生无敌 (Spawn Protection)
基本信息
| 属性 | 值 |
|---|---|
| 类型 | 事件系统(配置 + 事件订阅) |
| 触发条件 | 玩家加入世界 / 切换维度(EntityJoinWorldEvent / PlayerChangedDimensionEvent) |
| 配置类 | com.github.namikon.angermod.config.SpawnProtectionConfig |
| 事件类 | com.github.namikon.angermod.events.PlayerSpawnProtection |
| 默认启用 | false |
| 配置分类 | spawn-protection |
行为
新玩家 / 刚重生 / 刚切换维度的玩家获得一段保护期,期间 capabilities.disableDamage = true(免伤),并向其发送 yamcore.char.protection.give 暗绿色聊天提示。保护期可因以下任一动作提前解除:
- 玩家主动攻击生物(
AttackEntityEvent)→ 立即unprotectPlayer - 玩家右键方块(
PlayerInteractEvent且 action ≠RIGHT_CLICK_AIR且 ≠LEFT_CLICK_BLOCK) - 每 tick 检查超时:
- 玩家距离保护起始点 >
moveTolerance方块 → 距离超时 - 已超过
maxDuration * 20tick → 时间超时
- 玩家距离保护起始点 >
解除时发送 yamcore.char.protection.remove 暗紫色聊天提示。
安全跳过
isInvalidPlayer(player) 返回 true 时不会修改 disableDamage 状态,避免与其它机制冲突:
capabilities.isCreativeMode创造模式- 旁观模式:
theItemInWorldManager.getGameType().getID() == 3 BaublesApi中含有SpawnProtectionConfig.WhitelistedProtectionBaubles列表中的物品(默认EMT:BaseBaubles)
数值
| 数值名 | 默认值 | 范围 | 说明 |
|---|---|---|---|
enabled |
false |
bool | 是否启用整个模块 |
maxDuration |
10 | 1 - 2048 | 保护时长(秒),实际 tick = *20 |
moveTolerance |
5 | 1 - 2048 | 玩家可偏离初始点的最远距离(方块) |
protectionAffectingItems |
["EMT:BaseBaubles"] |
字符串数组 | 自动跳过无敌修改的玩家物品(饰品槽),格式 [modid]:[item] 或 [modid]:[item]:[meta] |
数据结构
PlayerSpawnProtection 内部维护 HashMap<UUID, ProtectionData>,记录玩家无敌起始坐标 (x, y, z) 和创建时间(worldObj.getTotalWorldTime())。
class ProtectionData {
final double x, y, z;
final long creationTime;
boolean isExpired(player) // 距离或时间超时判断
}
死亡 / 离开服务器时,UUID 不会被主动清理(HashMap 自然增长)。
旧版配置迁移
LegacyAngerModConfig.loadLegacyConfig 读取:
ProtectionEnabled(ModuleControl)→enabledSpawnProtectionTimeout(Limits)→maxDurationSpawnProtectionMoveTolerance(Limits)→moveToleranceWhitelistedProtectionItems(Whitelist)→protectionAffectingItems
依赖
- Baubles (
baubles-api):扫描玩家饰品栏 - gtnhlib:
@Config注解解析