    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;
    008
    009public class DamageSource
    010{
    011    public static DamageSource inFire = (new DamageSource("inFire")).setFireDamage();
    012    public static DamageSource onFire = (new DamageSource("onFire")).setDamageBypassesArmor().setFireDamage();
    013    public static DamageSource lava = (new DamageSource("lava")).setFireDamage();
    014    public static DamageSource inWall = (new DamageSource("inWall")).setDamageBypassesArmor();
    015    public static DamageSource drown = (new DamageSource("drown")).setDamageBypassesArmor();
    016    public static DamageSource starve = (new DamageSource("starve")).setDamageBypassesArmor();
    017    public static DamageSource cactus = new DamageSource("cactus");
    018    public static DamageSource fall = (new DamageSource("fall")).setDamageBypassesArmor();
    019    public static DamageSource outOfWorld = (new DamageSource("outOfWorld")).setDamageBypassesArmor().setDamageAllowedInCreativeMode();
    020    public static DamageSource generic = (new DamageSource("generic")).setDamageBypassesArmor();
    021    public static DamageSource explosion = (new DamageSource("explosion")).setDifficultyScaled();
    022    public static DamageSource explosion2 = new DamageSource("explosion");
    023    public static DamageSource magic = (new DamageSource("magic")).setDamageBypassesArmor().setMagicDamage();
    024    public static DamageSource wither = (new DamageSource("wither")).setDamageBypassesArmor();
    025    public static DamageSource anvil = new DamageSource("anvil");
    026    public static DamageSource fallingBlock = new DamageSource("fallingBlock");
    027
    028    /** This kind of damage can be blocked or not. */
    029    private boolean isUnblockable = false;
    030    private boolean isDamageAllowedInCreativeMode = false;
    031    private float hungerDamage = 0.3F;
    032
    033    /** This kind of damage is based on fire or not. */
    034    private boolean fireDamage;
    035
    036    /** This kind of damage is based on a projectile or not. */
    037    private boolean projectile;
    038
    039    /**
    040     * Whether this damage source will have its damage amount scaled based on the current difficulty.
    041     */
    042    private boolean difficultyScaled;
    043    private boolean magicDamage = 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    /**
    091     * Returns true if the damage is projectile based.
    092     */
    093    public boolean isProjectile()
    094    {
    095        return this.projectile;
    096    }
    097
    098    /**
    099     * Define the damage type as projectile based.
    100     */
    101    public DamageSource setProjectile()
    102    {
    103        this.projectile = true;
    104        return this;
    105    }
    106
    107    public boolean isUnblockable()
    108    {
    109        return this.isUnblockable;
    110    }
    111
    112    /**
    113     * How much satiate(food) is consumed by this DamageSource
    114     */
    115    public float getHungerDamage()
    116    {
    117        return this.hungerDamage;
    118    }
    119
    120    public boolean canHarmInCreative()
    121    {
    122        return this.isDamageAllowedInCreativeMode;
    123    }
    124
    125    protected DamageSource(String par1Str)
    126    {
    127        this.damageType = par1Str;
    128    }
    129
    130    public Entity getSourceOfDamage()
    131    {
    132        return this.getEntity();
    133    }
    134
    135    public Entity getEntity()
    136    {
    137        return null;
    138    }
    139
    140    protected DamageSource setDamageBypassesArmor()
    141    {
    142        this.isUnblockable = true;
    143        this.hungerDamage = 0.0F;
    144        return this;
    145    }
    146
    147    protected DamageSource setDamageAllowedInCreativeMode()
    148    {
    149        this.isDamageAllowedInCreativeMode = true;
    150        return this;
    151    }
    152
    153    /**
    154     * Define the damage type as fire based.
    155     */
    156    protected DamageSource setFireDamage()
    157    {
    158        this.fireDamage = true;
    159        return this;
    160    }
    161
    162    /**
    163     * Returns the message to be displayed on player death.
    164     */
    165    public String getDeathMessage(EntityPlayer par1EntityPlayer)
    166    {
    167        return StatCollector.translateToLocalFormatted("death." + this.damageType, new Object[] {par1EntityPlayer.username});
    168    }
    169
    170    /**
    171     * Returns true if the damage is fire based.
    172     */
    173    public boolean isFireDamage()
    174    {
    175        return this.fireDamage;
    176    }
    177
    178    /**
    179     * Return the name of damage type.
    180     */
    181    public String getDamageType()
    182    {
    183        return this.damageType;
    184    }
    185
    186    /**
    187     * Set whether this damage source will have its damage amount scaled based on the current difficulty.
    188     */
    189    public DamageSource setDifficultyScaled()
    190    {
    191        this.difficultyScaled = true;
    192        return this;
    193    }
    194
    195    /**
    196     * Return whether this damage source will have its damage amount scaled based on the current difficulty.
    197     */
    198    public boolean isDifficultyScaled()
    199    {
    200        return this.difficultyScaled;
    201    }
    202
    203    /**
    204     * Returns true if the damage is magic based.
    205     */
    206    public boolean isMagicDamage()
    207    {
    208        return this.magicDamage;
    209    }
    210
    211    /**
    212     * Define the damage type as magic based.
    213     */
    214    public DamageSource setMagicDamage()
    215    {
    216        this.magicDamage = true;
    217        return this;
    218    }
    219}