Skip to content

Commit

Permalink
fix: fixed #5043 along other issues related to forge hooks potentiall…
Browse files Browse the repository at this point in the history
…y nulling the attack target
  • Loading branch information
TheBv committed Dec 25, 2023
1 parent 954888a commit 7d1567c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ public void aiStep() {
}
if (this.getAnimation() == ANIMATION_KICK && this.getTarget() != null && this.distanceToSqr(this.getTarget()) < 14D && this.getAnimationTick() == 12) {
this.getTarget().hurt(DamageSource.mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
this.getTarget().knockback(2, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
// After calling hurt the target can become null due to forge hooks
if (this.getTarget() != null)
this.getTarget().knockback(2, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());

}
if (this.getAnimation() != ANIMATION_EATPLAYER && this.getTarget() != null && !this.getPassengers().isEmpty() && this.getPassengers().contains(this.getTarget())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public void aiStep() {
this.lookAt(this.getTarget(), 360, 80);
if (this.getAnimation() == ANIMATION_BITE && this.getAnimationTick() == 6) {
this.getTarget().hurt(DamageSource.mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
this.getTarget().knockback(0.25F, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
// After calling hurt the target can become null due to forge hooks
if (this.getTarget() != null)
this.getTarget().knockback(0.25F, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ public void aiStep() {
if (this.getAnimation() == ANIMATION_STING && this.getTarget() != null && this.getAnimationTick() == 6) {
if (this.getAttackBounds().intersects(this.getTarget().getBoundingBox())) {
LivingEntity attackTarget = this.getTarget();
this.getTarget().hurt(DamageSource.mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 200, 2));
this.getTarget().hasImpulse = true;
attackTarget.hurt(DamageSource.mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
attackTarget.addEffect(new MobEffectInstance(MobEffects.POISON, 200, 2));
attackTarget.hasImpulse = true;
float f = Mth.sqrt((float) (0.5 * 0.5 + 0.5 * 0.5));
this.getTarget().hasImpulse = true;
attackTarget.hasImpulse = true;
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().multiply(0.5D, 1, 0.5D));
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().add(-0.5 / f * 4, 1, -0.5 / f * 4));

if (this.getTarget().isOnGround()) {
if (attackTarget.isOnGround()) {
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().add(0, 0.4, 0));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ public void aiStep() {
double dist = this.distanceToSqr(this.getTarget());
if (dist < attackDistance()) {
this.getTarget().hurt(DamageSource.mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 70, 1));
// After calling hurt the target can become null due to forge hooks
if (this.getTarget() != null)
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 70, 1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ public void aiStep() {
this.getTarget().hurt(DamageSource.mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
}
if (this.getAnimation() == ANIMATION_STRIKE_HORIZONTAL && this.getTarget() != null && this.distanceToSqr(this.getTarget()) < 4D && this.getAnimationTick() == 10 && this.deathTime <= 0) {
this.getTarget().hurt(DamageSource.mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
LivingEntity target = this.getTarget();
target.hurt(DamageSource.mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
float f1 = 0.5F;
float f2 = this.getTarget().zza;
float f2 = target.zza;
float f3 = 0.6F;
float f4 = Mth.sqrt(f2 * f2 + f3 * f3);

Expand All @@ -378,7 +379,7 @@ public void aiStep() {
float f6 = Mth.cos(this.getYRot() * 0.017453292F);
// float f7 = f2 * f6 - f3 * f5;
// float f8 = f3 * f6 + f2 * f5;
this.getTarget().setDeltaMovement(f5, f6, 0.4F);
target.setDeltaMovement(f5, f6, 0.4F);
}
if (this.getNavigation().isDone() && this.getTarget() != null && this.distanceToSqr(this.getTarget()) > 3 && this.distanceToSqr(this.getTarget()) < 30 && this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
this.lookAt(this.getTarget(), 30, 30);
Expand Down

0 comments on commit 7d1567c

Please sign in to comment.