| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.block.Block;
|
| 6 | import net.minecraft.entity.Entity;
|
| 7 | import net.minecraft.entity.EntityLivingBase;
|
| 8 | import net.minecraft.entity.player.EntityPlayer;
|
| 9 | import net.minecraft.init.Blocks;
|
| 10 | import net.minecraft.item.ItemStack;
|
| 11 |
|
| 12 | public class CombatTracker
|
| 13 | {
|
| 14 | private final List<CombatEntry> combatEntries = Lists.<CombatEntry>newArrayList();
|
| 15 |
|
| 16 | /** The entity tracked. */
|
| 17 | private final EntityLivingBase fighter;
|
| 18 | private int field_94555_c;
|
| 19 | private int field_152775_d;
|
| 20 | private int field_152776_e;
|
| 21 | private boolean field_94552_d;
|
| 22 | private boolean field_94553_e;
|
| 23 | private String field_94551_f;
|
| 24 |
|
| 25 | public CombatTracker(EntityLivingBase fighterIn)
|
| 26 | {
|
| 27 | this.fighter = fighterIn;
|
| 28 | }
|
| 29 |
|
| 30 | public void func_94545_a()
|
| 31 | {
|
| 32 | this.func_94542_g();
|
| 33 |
|
| 34 | if (this.fighter.isOnLadder())
|
| 35 | {
|
| 36 | Block block = this.fighter.worldObj.getBlockState(new BlockPos(this.fighter.posX, this.fighter.getEntityBoundingBox().minY, this.fighter.posZ)).getBlock();
|
| 37 |
|
| 38 | if (block == Blocks.ladder)
|
| 39 | {
|
| 40 | this.field_94551_f = "ladder";
|
| 41 | }
|
| 42 | else if (block == Blocks.vine)
|
| 43 | {
|
| 44 | this.field_94551_f = "vines";
|
| 45 | }
|
| 46 | }
|
| 47 | else if (this.fighter.isInWater())
|
| 48 | {
|
| 49 | this.field_94551_f = "water";
|
| 50 | }
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Adds an entry for the combat tracker
|
| 55 | */
|
| 56 | public void trackDamage(DamageSource damageSrc, float healthIn, float damageAmount)
|
| 57 | {
|
| 58 | this.reset();
|
| 59 | this.func_94545_a();
|
| 60 | CombatEntry combatentry = new CombatEntry(damageSrc, this.fighter.ticksExisted, healthIn, damageAmount, this.field_94551_f, this.fighter.fallDistance);
|
| 61 | this.combatEntries.add(combatentry);
|
| 62 | this.field_94555_c = this.fighter.ticksExisted;
|
| 63 | this.field_94553_e = true;
|
| 64 |
|
| 65 | if (combatentry.isLivingDamageSrc() && !this.field_94552_d && this.fighter.isEntityAlive())
|
| 66 | {
|
| 67 | this.field_94552_d = true;
|
| 68 | this.field_152775_d = this.fighter.ticksExisted;
|
| 69 | this.field_152776_e = this.field_152775_d;
|
| 70 | this.fighter.sendEnterCombat();
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | public IChatComponent getDeathMessage()
|
| 75 | {
|
| 76 | if (this.combatEntries.size() == 0)
|
| 77 | {
|
| 78 | return new ChatComponentTranslation("death.attack.generic", new Object[] {this.fighter.getDisplayName()});
|
| 79 | }
|
| 80 | else
|
| 81 | {
|
| 82 | CombatEntry combatentry = this.func_94544_f();
|
| 83 | CombatEntry combatentry1 = (CombatEntry)this.combatEntries.get(this.combatEntries.size() - 1);
|
| 84 | IChatComponent ichatcomponent1 = combatentry1.getDamageSrcDisplayName();
|
| 85 | Entity entity = combatentry1.getDamageSrc().getEntity();
|
| 86 | IChatComponent ichatcomponent;
|
| 87 |
|
| 88 | if (combatentry != null && combatentry1.getDamageSrc() == DamageSource.fall)
|
| 89 | {
|
| 90 | IChatComponent ichatcomponent2 = combatentry.getDamageSrcDisplayName();
|
| 91 |
|
| 92 | if (combatentry.getDamageSrc() != DamageSource.fall && combatentry.getDamageSrc() != DamageSource.outOfWorld)
|
| 93 | {
|
| 94 | if (ichatcomponent2 != null && (ichatcomponent1 == null || !ichatcomponent2.equals(ichatcomponent1)))
|
| 95 | {
|
| 96 | Entity entity1 = combatentry.getDamageSrc().getEntity();
|
| 97 | ItemStack itemstack1 = entity1 instanceof EntityLivingBase ? ((EntityLivingBase)entity1).getHeldItem() : null;
|
| 98 |
|
| 99 | if (itemstack1 != null && itemstack1.hasDisplayName())
|
| 100 | {
|
| 101 | ichatcomponent = new ChatComponentTranslation("death.fell.assist.item", new Object[] {this.fighter.getDisplayName(), ichatcomponent2, itemstack1.getChatComponent()});
|
| 102 | }
|
| 103 | else
|
| 104 | {
|
| 105 | ichatcomponent = new ChatComponentTranslation("death.fell.assist", new Object[] {this.fighter.getDisplayName(), ichatcomponent2});
|
| 106 | }
|
| 107 | }
|
| 108 | else if (ichatcomponent1 != null)
|
| 109 | {
|
| 110 | ItemStack itemstack = entity instanceof EntityLivingBase ? ((EntityLivingBase)entity).getHeldItem() : null;
|
| 111 |
|
| 112 | if (itemstack != null && itemstack.hasDisplayName())
|
| 113 | {
|
| 114 | ichatcomponent = new ChatComponentTranslation("death.fell.finish.item", new Object[] {this.fighter.getDisplayName(), ichatcomponent1, itemstack.getChatComponent()});
|
| 115 | }
|
| 116 | else
|
| 117 | {
|
| 118 | ichatcomponent = new ChatComponentTranslation("death.fell.finish", new Object[] {this.fighter.getDisplayName(), ichatcomponent1});
|
| 119 | }
|
| 120 | }
|
| 121 | else
|
| 122 | {
|
| 123 | ichatcomponent = new ChatComponentTranslation("death.fell.killer", new Object[] {this.fighter.getDisplayName()});
|
| 124 | }
|
| 125 | }
|
| 126 | else
|
| 127 | {
|
| 128 | ichatcomponent = new ChatComponentTranslation("death.fell.accident." + this.func_94548_b(combatentry), new Object[] {this.fighter.getDisplayName()});
|
| 129 | }
|
| 130 | }
|
| 131 | else
|
| 132 | {
|
| 133 | ichatcomponent = combatentry1.getDamageSrc().getDeathMessage(this.fighter);
|
| 134 | }
|
| 135 |
|
| 136 | return ichatcomponent;
|
| 137 | }
|
| 138 | }
|
| 139 |
|
| 140 | public EntityLivingBase func_94550_c()
|
| 141 | {
|
| 142 | EntityLivingBase entitylivingbase = null;
|
| 143 | EntityPlayer entityplayer = null;
|
| 144 | float f = 0.0F;
|
| 145 | float f1 = 0.0F;
|
| 146 |
|
| 147 | for (CombatEntry combatentry : this.combatEntries)
|
| 148 | {
|
| 149 | if (combatentry.getDamageSrc().getEntity() instanceof EntityPlayer && (entityplayer == null || combatentry.func_94563_c() > f1))
|
| 150 | {
|
| 151 | f1 = combatentry.func_94563_c();
|
| 152 | entityplayer = (EntityPlayer)combatentry.getDamageSrc().getEntity();
|
| 153 | }
|
| 154 |
|
| 155 | if (combatentry.getDamageSrc().getEntity() instanceof EntityLivingBase && (entitylivingbase == null || combatentry.func_94563_c() > f))
|
| 156 | {
|
| 157 | f = combatentry.func_94563_c();
|
| 158 | entitylivingbase = (EntityLivingBase)combatentry.getDamageSrc().getEntity();
|
| 159 | }
|
| 160 | }
|
| 161 |
|
| 162 | if (entityplayer != null && f1 >= f / 3.0F)
|
| 163 | {
|
| 164 | return entityplayer;
|
| 165 | }
|
| 166 | else
|
| 167 | {
|
| 168 | return entitylivingbase;
|
| 169 | }
|
| 170 | }
|
| 171 |
|
| 172 | private CombatEntry func_94544_f()
|
| 173 | {
|
| 174 | CombatEntry combatentry = null;
|
| 175 | CombatEntry combatentry1 = null;
|
| 176 | int i = 0;
|
| 177 | float f = 0.0F;
|
| 178 |
|
| 179 | for (int j = 0; j < this.combatEntries.size(); ++j)
|
| 180 | {
|
| 181 | CombatEntry combatentry2 = (CombatEntry)this.combatEntries.get(j);
|
| 182 | CombatEntry combatentry3 = j > 0 ? (CombatEntry)this.combatEntries.get(j - 1) : null;
|
| 183 |
|
| 184 | if ((combatentry2.getDamageSrc() == DamageSource.fall || combatentry2.getDamageSrc() == DamageSource.outOfWorld) && combatentry2.getDamageAmount() > 0.0F && (combatentry == null || combatentry2.getDamageAmount() > f))
|
| 185 | {
|
| 186 | if (j > 0)
|
| 187 | {
|
| 188 | combatentry = combatentry3;
|
| 189 | }
|
| 190 | else
|
| 191 | {
|
| 192 | combatentry = combatentry2;
|
| 193 | }
|
| 194 |
|
| 195 | f = combatentry2.getDamageAmount();
|
| 196 | }
|
| 197 |
|
| 198 | if (combatentry2.func_94562_g() != null && (combatentry1 == null || combatentry2.func_94563_c() > (float)i))
|
| 199 | {
|
| 200 | combatentry1 = combatentry2;
|
| 201 | }
|
| 202 | }
|
| 203 |
|
| 204 | if (f > 5.0F && combatentry != null)
|
| 205 | {
|
| 206 | return combatentry;
|
| 207 | }
|
| 208 | else if (i > 5 && combatentry1 != null)
|
| 209 | {
|
| 210 | return combatentry1;
|
| 211 | }
|
| 212 | else
|
| 213 | {
|
| 214 | return null;
|
| 215 | }
|
| 216 | }
|
| 217 |
|
| 218 | private String func_94548_b(CombatEntry p_94548_1_)
|
| 219 | {
|
| 220 | return p_94548_1_.func_94562_g() == null ? "generic" : p_94548_1_.func_94562_g();
|
| 221 | }
|
| 222 |
|
| 223 | public int func_180134_f()
|
| 224 | {
|
| 225 | return this.field_94552_d ? this.fighter.ticksExisted - this.field_152775_d : this.field_152776_e - this.field_152775_d;
|
| 226 | }
|
| 227 |
|
| 228 | private void func_94542_g()
|
| 229 | {
|
| 230 | this.field_94551_f = null;
|
| 231 | }
|
| 232 |
|
| 233 | /**
|
| 234 | * Resets this trackers list of combat entries
|
| 235 | */
|
| 236 | public void reset()
|
| 237 | {
|
| 238 | int i = this.field_94552_d ? 300 : 100;
|
| 239 |
|
| 240 | if (this.field_94553_e && (!this.fighter.isEntityAlive() || this.fighter.ticksExisted - this.field_94555_c > i))
|
| 241 | {
|
| 242 | boolean flag = this.field_94552_d;
|
| 243 | this.field_94553_e = false;
|
| 244 | this.field_94552_d = false;
|
| 245 | this.field_152776_e = this.fighter.ticksExisted;
|
| 246 |
|
| 247 | if (flag)
|
| 248 | {
|
| 249 | this.fighter.sendEndCombat();
|
| 250 | }
|
| 251 |
|
| 252 | this.combatEntries.clear();
|
| 253 | }
|
| 254 | }
|
| 255 |
|
| 256 | /**
|
| 257 | * Returns EntityLivingBase assigned for this CombatTracker
|
| 258 | */
|
| 259 | public EntityLivingBase getFighter()
|
| 260 | {
|
| 261 | return this.fighter;
|
| 262 | }
|
| 263 | }
|
| 264 |
|