Upstream: Add ArrowBodyCountChangeEvent

This commit is contained in:
IzzelAliz 2020-09-03 14:20:15 +08:00
parent a401ef3111
commit 56547dd0ca
2 changed files with 22 additions and 1 deletions

View File

@ -170,6 +170,8 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
@Shadow protected abstract void damageArmor(DamageSource damageSource, float damage); @Shadow protected abstract void damageArmor(DamageSource damageSource, float damage);
@Shadow protected abstract void playEquipSound(ItemStack stack); @Shadow protected abstract void playEquipSound(ItemStack stack);
@Shadow public abstract boolean getShouldBeDead(); @Shadow public abstract boolean getShouldBeDead();
@Shadow public abstract int getArrowCountInEntity();
@Shadow @Final private static DataParameter<Integer> ARROW_COUNT_IN_ENTITY;
// @formatter:on // @formatter:on
public int expToDrop; public int expToDrop;
@ -1055,4 +1057,22 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt
arclight$cause = null; arclight$cause = null;
} }
} }
@Inject(method = "setArrowCountInEntity", cancellable = true, at = @At("HEAD"))
private void arclight$onArrowChange(int count, CallbackInfo ci) {
if (arclight$callArrowCountChange(count, false)) {
ci.cancel();
}
}
public final void setArrowCount(int count, boolean reset) {
if (arclight$callArrowCountChange(count, reset)) {
return;
}
this.dataManager.set(ARROW_COUNT_IN_ENTITY, count);
}
private boolean arclight$callArrowCountChange(int newCount, boolean reset) {
return CraftEventFactory.callArrowBodyCountChangeEvent((LivingEntity) (Object) this, this.getArrowCountInEntity(), newCount, reset).isCancelled();
}
} }

View File

@ -891,7 +891,8 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
this.experienceLevel = this.newLevel; this.experienceLevel = this.newLevel;
this.experienceTotal = this.newTotalExp; this.experienceTotal = this.newTotalExp;
this.experience = 0.0f; this.experience = 0.0f;
this.setArrowCountInEntity(this.deathTime = 0); this.deathTime = 0;
this.setArrowCount(0, true);
this.removeAllEffects(EntityPotionEffectEvent.Cause.DEATH); this.removeAllEffects(EntityPotionEffectEvent.Cause.DEATH);
this.potionsNeedUpdate = true; this.potionsNeedUpdate = true;
this.openContainer = this.container; this.openContainer = this.container;