Skip to content

Commit

Permalink
Fix hurt sounds and support mob spawning.
Browse files Browse the repository at this point in the history
 * Play hurt sounds only after projectile immunity is considered.
 * Adjust support mob spawn location.
  • Loading branch information
totemo committed May 3, 2020
1 parent d5b357c commit 6ff13f5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/nu/nerd/beastmaster/BeastMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,14 @@ protected void onEntityDamage(EntityDamageEvent event) {
&& (supportPercent == null ||
Math.random() * 100 < supportPercent)) {

// TODO: spawning needs to do better at looking for a
// spawnable location. Really need to do spawn conditions
// argument to spawning functions.
Location supportLocation = mobLocation.clone().add(0, 1, 0);

// Summon support mobs targeting same target as summoner.
DropResults results = new DropResults();
List<LivingEntity> supportMobs = spawnMultipleMobs(mobLocation, supportId, false, results,
List<LivingEntity> supportMobs = spawnMultipleMobs(supportLocation, supportId, false, results,
mobType.getId() + " support-mobs");
if (damagedLiving instanceof Mob) {
for (LivingEntity mob : supportMobs) {
Expand All @@ -569,12 +574,6 @@ protected void onEntityDamage(EntityDamageEvent event) {
}

DamageCause cause = event.getCause();
String propertyName = (cause == DamageCause.PROJECTILE) ? "projectile-hurt-sound" : "melee-hurt-sound";
SoundEffect hurtSound = (SoundEffect) mobType.getDerivedProperty(propertyName).getValue();
if (hurtSound != null) {
Bukkit.getScheduler().runTaskLater(this, () -> hurtSound.play(mobLocation), 1);
}

if (cause == DamageCause.PROJECTILE) {
Double immunityPercent = (Double) mobType.getDerivedProperty("projectile-immunity-percent").getValue();
boolean immuneToProjectile = (immunityPercent != null && Math.random() * 100 < immunityPercent);
Expand All @@ -588,6 +587,13 @@ protected void onEntityDamage(EntityDamageEvent event) {
}
}

// Play hurt sounds after projectile immunity checks.
String propertyName = (cause == DamageCause.PROJECTILE) ? "projectile-hurt-sound" : "melee-hurt-sound";
SoundEffect hurtSound = (SoundEffect) mobType.getDerivedProperty(propertyName).getValue();
if (hurtSound != null) {
Bukkit.getScheduler().runTaskLater(this, () -> hurtSound.play(mobLocation), 1);
}

// Don't teleport if the damage is low to allow for slight falls.
if (event.getFinalDamage() <= 3.0) {
return;
Expand Down

0 comments on commit 6ff13f5

Please sign in to comment.