diff --git a/src/main/java/net/glowstone/block/blocktype/BlockMagma.java b/src/main/java/net/glowstone/block/blocktype/BlockMagma.java index ab972ee592..e2c398a0b6 100644 --- a/src/main/java/net/glowstone/block/blocktype/BlockMagma.java +++ b/src/main/java/net/glowstone/block/blocktype/BlockMagma.java @@ -1,6 +1,7 @@ package net.glowstone.block.blocktype; import net.glowstone.block.GlowBlock; +import net.glowstone.entity.GlowEntity; import net.glowstone.inventory.ToolType; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; @@ -14,6 +15,10 @@ public BlockMagma() { @Override public void onEntityStep(GlowBlock block, LivingEntity entity) { - entity.damage(1.0, EntityDamageEvent.DamageCause.FIRE); + if (entity instanceof GlowEntity) { + ((GlowEntity) entity).damage(1, block, EntityDamageEvent.DamageCause.FIRE); + } else { + entity.damage(1.0, EntityDamageEvent.DamageCause.FIRE); + } } } diff --git a/src/main/java/net/glowstone/entity/GlowEntity.java b/src/main/java/net/glowstone/entity/GlowEntity.java index fb1be1353c..7daa37d5ab 100644 --- a/src/main/java/net/glowstone/entity/GlowEntity.java +++ b/src/main/java/net/glowstone/entity/GlowEntity.java @@ -982,22 +982,42 @@ public boolean isTouchingMaterial(Material material) { } } } else { - // bounding box-based calculation - Vector min = boundingBox.minCorner; - Vector max = boundingBox.maxCorner; - for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { - for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { - for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - if (world.getBlockTypeIdAt(x, y, z) == material.getId()) { - return true; - } - } + for (Block touchingBlock : getTouchingBlocks()) { + if (touchingBlock.getType().getId() == material.getId()) { + return true; } } } return false; } + /** + * Gets a list containing all the blocks a player is touching + * + *
If the entity has not a defined bounding box, the list will be empty.
+ *
+ * @return the list of blocks a player is touching
+ */
+ public List Usually used to check environmental sources such as drowning.
+ *
+ * @return whether this entity can take damage
+ */
+ public boolean canTakeDamage() {
+ return noDamageTicks == 0 && health > 0 && !isInvulnerable();
+ }
+
/**
* Get whether of not this entity is an arthropod.
*
@@ -936,10 +960,64 @@ public void setHealth(double health) {
}
}
+ private boolean callDamageEvent(EntityDamageEvent event) {
+ if (event.isCancelled()) {
+ return true;
+ }
+ // apply damage
+ lastDamage = event.getFinalDamage();
+ return false;
+ }
+
+ private double getEffectiveDamage(double amount) {
+ // armor damage protection
+ // formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
+ double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
+ double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
+ return amount * (1 - Math.min(20.0,
+ Math.max(defensePoints / 5.0,
+ defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
+ }
+
+ @Override
+ public void damage(double amount, Block block, DamageCause cause) {
+ if (noDamageTicks > 0 || health <= 0 || isInvulnerable() || !canTakeDamage(cause)) {
+ return;
+ } else {
+ noDamageTicks = maximumNoDamageTicks;
+ }
+
+ amount = getEffectiveDamage(amount);
+
+
+ // fire event
+ EntityDamageByBlockEvent event = EventFactory.getInstance().onEntityDamage(
+ new EntityDamageByBlockEvent(block, this, cause, amount));
+
+ if (callDamageEvent(event)) {
+ return;
+ }
+
+ // apply damage
+ amount = event.getFinalDamage();
+ lastDamage = amount;
+
+ setHealth(health - amount);
+ playEffectKnownAndSelf(EntityEffect.HURT);
+
+ // play sounds, handle death
+ if (health > 0) {
+ Sound hurtSound = getHurtSound();
+ if (hurtSound != null && !isSilent()) {
+ world.playSound(location, hurtSound, getSoundVolume(), getSoundPitch());
+ }
+ }
+ }
+
@Override
public void damage(double amount, Entity source, DamageCause cause) {
// invincibility timer
- if (noDamageTicks > 0 || health <= 0 || !canTakeDamage(cause) || isInvulnerable()) {
+ if (noDamageTicks > 0 || health <= 0 || isInvulnerable() || !canTakeDamage(cause)) {
return;
} else {
noDamageTicks = maximumNoDamageTicks;
@@ -962,13 +1040,7 @@ public void damage(double amount, Entity source, DamageCause cause) {
}
}
- // armor damage protection
- // formula source: http://minecraft.gamepedia.com/Armor#Damage_Protection
- double defensePoints = getAttributeManager().getPropertyValue(Key.KEY_ARMOR);
- double toughness = getAttributeManager().getPropertyValue(Key.KEY_ARMOR_TOUGHNESS);
- amount = amount * (1 - Math.min(20.0,
- Math.max(defensePoints / 5.0,
- defensePoints - amount / (2.0 + toughness / 4.0))) / 25);
+ amount = getEffectiveDamage(amount);
// fire event
EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null