| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import net.minecraft.entity.Entity;
|
| 4 | import net.minecraft.entity.EntityLivingBase;
|
| 5 | import net.minecraft.entity.player.EntityPlayer;
|
| 6 | import net.minecraft.item.ItemStack;
|
| 7 |
|
| 8 | public class EntityDamageSource extends DamageSource
|
| 9 | {
|
| 10 | protected Entity damageSourceEntity;
|
| 11 |
|
| 12 | /**
|
| 13 | * Whether this EntityDamageSource is from an entity wearing Thorns-enchanted armor.
|
| 14 | */
|
| 15 | private boolean isThornsDamage = false;
|
| 16 |
|
| 17 | public EntityDamageSource(String damageTypeIn, Entity damageSourceEntityIn)
|
| 18 | {
|
| 19 | super(damageTypeIn);
|
| 20 | this.damageSourceEntity = damageSourceEntityIn;
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Sets this EntityDamageSource as originating from Thorns armor
|
| 25 | */
|
| 26 | public EntityDamageSource setIsThornsDamage()
|
| 27 | {
|
| 28 | this.isThornsDamage = true;
|
| 29 | return this;
|
| 30 | }
|
| 31 |
|
| 32 | public boolean getIsThornsDamage()
|
| 33 | {
|
| 34 | return this.isThornsDamage;
|
| 35 | }
|
| 36 |
|
| 37 | public Entity getEntity()
|
| 38 | {
|
| 39 | return this.damageSourceEntity;
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Gets the death message that is displayed when the player dies
|
| 44 | *
|
| 45 | * @param entityLivingBaseIn The EntityLivingBase that died
|
| 46 | */
|
| 47 | public IChatComponent getDeathMessage(EntityLivingBase entityLivingBaseIn)
|
| 48 | {
|
| 49 | ItemStack itemstack = this.damageSourceEntity instanceof EntityLivingBase ? ((EntityLivingBase)this.damageSourceEntity).getHeldItem() : null;
|
| 50 | String s = "death.attack." + this.damageType;
|
| 51 | String s1 = s + ".item";
|
| 52 | return itemstack != null && itemstack.hasDisplayName() && StatCollector.canTranslate(s1) ? new ChatComponentTranslation(s1, new Object[] {entityLivingBaseIn.getDisplayName(), this.damageSourceEntity.getDisplayName(), itemstack.getChatComponent()}): new ChatComponentTranslation(s, new Object[] {entityLivingBaseIn.getDisplayName(), this.damageSourceEntity.getDisplayName()});
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Return whether this damage source will have its damage amount scaled based on the current difficulty.
|
| 57 | */
|
| 58 | public boolean isDifficultyScaled()
|
| 59 | {
|
| 60 | return this.damageSourceEntity != null && this.damageSourceEntity instanceof EntityLivingBase && !(this.damageSourceEntity instanceof EntityPlayer);
|
| 61 | }
|
| 62 | }
|
| 63 |
|