    001package net.minecraft.util;
    002
    003import net.minecraft.entity.Entity;
    004import net.minecraft.entity.EntityLiving;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.entity.projectile.EntityArrow;
    007import net.minecraft.entity.projectile.EntityFireball;
    008import net.minecraft.world.Explosion;
    009
    010public class DamageSource
    011{
    012    public static DamageSource inFire = (new DamageSource("inFire")).setFireDamage();
    013    public static DamageSource onFire = (new DamageSource("onFire")).setDamageBypassesArmor().setFireDamage();
    014    public static DamageSource lava = (new DamageSource("lava")).setFireDamage();
    015    public static DamageSource inWall = (new DamageSource("inWall")).setDamageBypassesArmor();
    016    public static DamageSource drown = (new DamageSource("drown")).setDamageBypassesArmor();
    017    public static DamageSource starve = (new DamageSource("starve")).setDamageBypassesArmor();
    018    public static DamageSource cactus = new DamageSource("cactus");
    019    public static DamageSource fall = (new DamageSource("fall")).setDamageBypassesArmor();
    020    public static DamageSource outOfWorld = (new DamageSource("outOfWorld")).setDamageBypassesArmor().setDamageAllowedInCreativeMode();
    021    public static DamageSource generic = (new DamageSource("generic")).setDamageBypassesArmor();
    022    public static DamageSource magic = (new DamageSource("magic")).setDamageBypassesArmor().setMagicDamage();
    023    public static DamageSource wither = (new DamageSource("wither")).setDamageBypassesArmor();
    024    public static DamageSource anvil = new DamageSource("anvil");
    025    public static DamageSource fallingBlock = new DamageSource("fallingBlock");
    026
    027    /** This kind of damage can be blocked or not. */
    028    private boolean isUnblockable = false;
    029    private boolean isDamageAllowedInCreativeMode = false;
    030    private float hungerDamage = 0.3F;
    031
    032    /** This kind of damage is based on fire or not. */
    033    private boolean fireDamage;
    034
    035    /** This kind of damage is based on a projectile or not. */
    036    private boolean projectile;
    037
    038    /**
    039     * Whether this damage source will have its damage amount scaled based on the current difficulty.
    040     */
    041    private boolean difficultyScaled;
    042    private boolean magicDamage = false;
    043    private boolean explosion = false;
    044    public String damageType;
    045
    046    public static DamageSource causeMobDamage(EntityLiving par0EntityLiving)
    047    {
    048        return new EntityDamageSource("mob", par0EntityLiving);
    049    }
    050
    051    /**
    052     * returns an EntityDamageSource of type player
    053     */
    054    public static DamageSource causePlayerDamage(EntityPlayer par0EntityPlayer)
    055    {
    056        return new EntityDamageSource("player", par0EntityPlayer);
    057    }
    058
    059    /**
    060     * returns EntityDamageSourceIndirect of an arrow
    061     */
    062    public static DamageSource causeArrowDamage(EntityArrow par0EntityArrow, Entity par1Entity)
    063    {
    064        return (new EntityDamageSourceIndirect("arrow", par0EntityArrow, par1Entity)).setProjectile();
    065    }
    066
    067    /**
    068     * returns EntityDamageSourceIndirect of a fireball
    069     */
    070    public static DamageSource causeFireballDamage(EntityFireball par0EntityFireball, Entity par1Entity)
    071    {
    072        return par1Entity == null ? (new EntityDamageSourceIndirect("onFire", par0EntityFireball, par0EntityFireball)).setFireDamage().setProjectile() : (new EntityDamageSourceIndirect("fireball", par0EntityFireball, par1Entity)).setFireDamage().setProjectile();
    073    }
    074
    075    public static DamageSource causeThrownDamage(Entity par0Entity, Entity par1Entity)
    076    {
    077        return (new EntityDamageSourceIndirect("thrown", par0Entity, par1Entity)).setProjectile();
    078    }
    079
    080    public static DamageSource causeIndirectMagicDamage(Entity par0Entity, Entity par1Entity)
    081    {
    082        return (new EntityDamageSourceIndirect("indirectMagic", par0Entity, par1Entity)).setDamageBypassesArmor().setMagicDamage();
    083    }
    084
    085    public static DamageSource func_92087_a(Entity par0Entity)
    086    {
    087        return (new EntityDamageSource("thorns", par0Entity)).setMagicDamage();
    088    }
    089
    090    public static DamageSource func_94539_a(Explosion par0Explosion)
    091    {
    092        return par0Explosion != null && par0Explosion.func_94613_c() != null ? (new EntityDamageSource("explosion.player", par0Explosion.func_94613_c())).setDifficultyScaled().func_94540_d() : (new DamageSource("explosion")).setDifficultyScaled().func_94540_d();
    093    }
    094
    095    /**
    096     * Returns true if the damage is projectile based.
    097     */
    098    public boolean isProjectile()
    099    {
    100        return this.projectile;
    101    }
    102
    103    /**
    104     * Define the damage type as projectile based.
    105     */
    106    public DamageSource setProjectile()
    107    {
    108        this.projectile = true;
    109        return this;
    110    }
    111
    112    public boolean func_94541_c()
    113    {
    114        return this.explosion;
    115    }
    116
    117    public DamageSource func_94540_d()
    118    {
    119        this.explosion = true;
    120        return this;
    121    }
    122
    123    public boolean isUnblockable()
    124    {
    125        return this.isUnblockable;
    126    }
    127
    128    /**
    129     * How much satiate(food) is consumed by this DamageSource
    130     */
    131    public float getHungerDamage()
    132    {
    133        return this.hungerDamage;
    134    }
    135
    136    public boolean canHarmInCreative()
    137    {
    138        return this.isDamageAllowedInCreativeMode;
    139    }
    140
    141    protected DamageSource(String par1Str)
    142    {
    143        this.damageType = par1Str;
    144    }
    145
    146    public Entity getSourceOfDamage()
    147    {
    148        return this.getEntity();
    149    }
    150
    151    public Entity getEntity()
    152    {
    153        return null;
    154    }
    155
    156    protected DamageSource setDamageBypassesArmor()
    157    {
    158        this.isUnblockable = true;
    159        this.hungerDamage = 0.0F;
    160        return this;
    161    }
    162
    163    protected DamageSource setDamageAllowedInCreativeMode()
    164    {
    165        this.isDamageAllowedInCreativeMode = true;
    166        return this;
    167    }
    168
    169    /**
    170     * Define the damage type as fire based.
    171     */
    172    protected DamageSource setFireDamage()
    173    {
    174        this.fireDamage = true;
    175        return this;
    176    }
    177
    178    /**
    179     * Returns the message to be displayed on player death.
    180     */
    181    public String getDeathMessage(EntityLiving par1EntityLiving)
    182    {
    183        EntityLiving entityliving1 = par1EntityLiving.func_94060_bK();
    184        String s = "death.attack." + this.damageType;
    185        String s1 = s + ".player";
    186        return entityliving1 != null && StatCollector.func_94522_b(s1) ? StatCollector.translateToLocalFormatted(s1, new Object[] {par1EntityLiving.func_96090_ax(), entityliving1.func_96090_ax()}): StatCollector.translateToLocalFormatted(s, new Object[] {par1EntityLiving.func_96090_ax()});
    187    }
    188
    189    /**
    190     * Returns true if the damage is fire based.
    191     */
    192    public boolean isFireDamage()
    193    {
    194        return this.fireDamage;
    195    }
    196
    197    /**
    198     * Return the name of damage type.
    199     */
    200    public String getDamageType()
    201    {
    202        return this.damageType;
    203    }
    204
    205    /**
    206     * Set whether this damage source will have its damage amount scaled based on the current difficulty.
    207     */
    208    public DamageSource setDifficultyScaled()
    209    {
    210        this.difficultyScaled = true;
    211        return this;
    212    }
    213
    214    /**
    215     * Return whether this damage source will have its damage amount scaled based on the current difficulty.
    216     */
    217    public boolean isDifficultyScaled()
    218    {
    219        return this.difficultyScaled;
    220    }
    221
    222    /**
    223     * Returns true if the damage is magic based.
    224     */
    225    public boolean isMagicDamage()
    226    {
    227        return this.magicDamage;
    228    }
    229
    230    /**
    231     * Define the damage type as magic based.
    232     */
    233    public DamageSource setMagicDamage()
    234    {
    235        this.magicDamage = true;
    236        return this;
    237    }
    238}