Skip to content

Commit

Permalink
fix: golems not being shy
Browse files Browse the repository at this point in the history
  • Loading branch information
t2pellet committed Jun 25, 2024
1 parent 6409fb7 commit 34c7968
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ public boolean isDamageSourceBlocked(DamageSource source) {
}

@Override
protected void hurtCurrentlyUsedShield(float amount) {
public void hurtCurrentlyUsedShield(float amount) {
int durability = entityData.get(BARREL_HEALTH);
int newDurability = Math.round(Math.max(durability - amount, 0));
entityData.set(BARREL_HEALTH, newDurability);
playSound(newDurability > 0 ? SoundEvents.SHIELD_BLOCK : SoundEvents.SHIELD_BREAK);
playSound(newDurability <= 0 ? SoundEvents.SHIELD_BREAK : SoundEvents.SHIELD_BLOCK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.t2pellet.strawgolem.entity.goals.golem;

import com.t2pellet.strawgolem.entity.StrawGolem;
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;

public class GolemBeShyGoal extends GolemFleeEntityGoal<Player> {

Expand All @@ -11,7 +13,22 @@ public GolemBeShyGoal(StrawGolem golem) {

@Override
public boolean canUse() {
return super.canUse() && !isTempting();
this.toAvoid = this.mob.level.getNearestPlayer(this.mob, this.maxDist);
if (this.toAvoid == null) {
return false;
} else if (isTempting()) {
return false;
} else {
Vec3 vec3 = DefaultRandomPos.getPosAway(this.mob, 16, 7, this.toAvoid.position());
if (vec3 == null) {
return false;
} else if (this.toAvoid.distanceToSqr(vec3.x, vec3.y, vec3.z) < this.toAvoid.distanceToSqr(this.mob)) {
return false;
} else {
this.path = this.pathNav.createPath(vec3.x, vec3.y, vec3.z, 0);
return this.path != null;
}
}
}

@Override
Expand Down

0 comments on commit 34c7968

Please sign in to comment.