EntityPlayerMixin

基本信息

属性 值
目标类 net.minecraft.entity.player.EntityPlayer
Mixin 阶段 EARLY
注入数 5
注入方法 <init>、setItemInUse、getItemInUseDuration、onLivingUpdate、damageEntity
注册于 Mixins.MINECRAFT(common mixin)
启用版本 Minecraft 1.7.10

功能

本 mod 注入最多的 Mixin。承担三件事:接入 EntityPlayerExt duck 接口、派发和平难度回血事件、把受伤改走消耗值通道。

注入方法 作用
<init> 构造末尾调用 AppleCoreAPI.registry / accessor 初始化相关逻辑
setItemInUse 使用物品状态变化时维护使用时长
getItemInUseDuration 实现 duck 接口的 getItemInUseMaxDuration()
onLivingUpdate 派发 HealthRegenEvent.PeacefulRegen
damageEntity 派发 ExhaustionEvent.ExhaustFromHurt

实现要点

  • onLivingUpdate 注入中构造 PeacefulRegen 事件, 读取其可写的 deltaHealth(初值 1f)作为回血量, 并按 isCanceled() 决定是否跳过——这是实现「和平难度也能回血」 或「和平难度禁止回血」的唯一入口。
  • damageEntity 注入中构造 ExhaustFromHurt 事件, 其 source 与 damage 两个字段非 final,监听器可改写; 之后按 isCanceled() 决定是否继续扣血。
  • getItemInUseDuration 注入实现 EntityPlayerExt 的 getItemInUseMaxDuration(),供外部读取使用中物品的最大持续时间。
  • 该 Mixin 同时挂载了 duck 接口,因此类上除注入外还有接口声明。

相关条目