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