Skip to content

Commit def2898

Browse files
committed
fix: fixed #5043 along other issues related to forge hooks potentially nulling the attack target
1 parent c160a8e commit def2898

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ public void aiStep() {
286286
}
287287
if (this.getAnimation() == ANIMATION_KICK && this.getTarget() != null && this.distanceToSqr(this.getTarget()) < 14D && this.getAnimationTick() == 12) {
288288
this.getTarget().hurt(this.level().damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
289-
this.getTarget().knockback(2, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
289+
if (this.getTarget() != null)
290+
this.getTarget().knockback(2, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
290291

291292
}
292293
if (this.getAnimation() != ANIMATION_EATPLAYER && this.getTarget() != null && !this.getPassengers().isEmpty() && this.getPassengers().contains(this.getTarget())) {

src/main/java/com/github/alexthe666/iceandfire/entity/EntityDreadBeast.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public void aiStep() {
139139
this.lookAt(this.getTarget(), 360, 80);
140140
if (this.getAnimation() == ANIMATION_BITE && this.getAnimationTick() == 6) {
141141
this.getTarget().hurt(level().damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
142-
this.getTarget().knockback(0.25F, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
142+
if (this.getTarget() != null)
143+
this.getTarget().knockback(0.25F, this.getX() - this.getTarget().getX(), this.getZ() - this.getTarget().getZ());
143144
}
144145
}
145146

src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexQueen.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,14 @@ public void aiStep() {
203203
if (this.getAnimation() == ANIMATION_STING && this.getTarget() != null && this.getAnimationTick() == 6) {
204204
if (this.getAttackBounds().intersects(this.getTarget().getBoundingBox())) {
205205
LivingEntity attackTarget = this.getTarget();
206-
this.getTarget().hurt(this.level().damageSources().mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
207-
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 200, 2));
208-
this.getTarget().hasImpulse = true;
206+
attackTarget.hurt(this.level().damageSources().mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
207+
attackTarget.addEffect(new MobEffectInstance(MobEffects.POISON, 200, 2));
208+
attackTarget.hasImpulse = true;
209209
float f = Mth.sqrt((float) (0.5 * 0.5 + 0.5 * 0.5));
210-
this.getTarget().hasImpulse = true;
211210
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().multiply(0.5D, 1, 0.5D));
212211
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().add(-0.5 / f * 4, 1, -0.5 / f * 4));
213212

214-
if (this.getTarget().onGround()) {
213+
if (attackTarget.onGround()) {
215214
attackTarget.setDeltaMovement(attackTarget.getDeltaMovement().add(0, 0.4, 0));
216215
}
217216
}

src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexSwarmer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ public void aiStep() {
209209
double dist = this.distanceToSqr(this.getTarget());
210210
if (dist < attackDistance()) {
211211
this.getTarget().hurt(level().damageSources().mobAttack(this), ((int) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue() * 2));
212-
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 70, 1));
212+
// After calling hurt the target can become null due to forge hooks
213+
if (this.getTarget() != null)
214+
this.getTarget().addEffect(new MobEffectInstance(MobEffects.POISON, 70, 1));
213215
}
214216
}
215217
}

src/main/java/com/github/alexthe666/iceandfire/entity/EntityTroll.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ public void aiStep() {
360360
this.getTarget().hurt(this.level().damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
361361
}
362362
if (this.getAnimation() == ANIMATION_STRIKE_HORIZONTAL && this.getTarget() != null && this.distanceToSqr(this.getTarget()) < 4D && this.getAnimationTick() == 10 && this.deathTime <= 0) {
363-
this.getTarget().hurt(this.level().damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
363+
LivingEntity target = this.getTarget();
364+
target.hurt(this.level().damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
364365
float f1 = 0.5F;
365-
float f2 = this.getTarget().zza;
366+
float f2 = target.zza;
366367
float f3 = 0.6F;
367368
float f4 = Mth.sqrt(f2 * f2 + f3 * f3);
368369

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

0 commit comments

Comments
 (0)