EntityHorse .java

net.minecraft.entity.passive.EntityHorse (class): members: HORSE_MARKING_TEXTURES_ABBR, HORSE_ARMOR_TEXTURES_ABBR, getHorseArmorIndexSynced, isTame.

net.minecraft.entity.passiveclass1,885 linescommonextends EntityAnimal56.8 KB

Implements

API Surface (93)

boolean apply(Entity p_apply_1_)
void entityInit()
void setHorseType(int type)
int getHorseType()
void setHorseVariant(int variant)
int getHorseVariant()
String getName()
boolean isAdultHorse()
boolean isTame()
boolean func_110253_bW()
String getOwnerId()
void setOwnerId(String id)
float getHorseSize()
void setScaleForAge(boolean p_98054_1_)
boolean isHorseJumping()
void setHorseTamed(boolean tamed)
void setHorseJumping(boolean jumping)
boolean allowLeashing()
void func_142017_o(float p_142017_1_)
boolean isChested()
int getHorseArmorIndexSynced()
boolean isEatingHaystack()
boolean isRearing()
boolean isBreeding()
boolean getHasReproduced()
void setHorseArmorStack(ItemStack itemStackIn)
void setBreeding(boolean breeding)
void setChested(boolean chested)
void setHasReproduced(boolean hasReproducedIn)
void setHorseSaddled(boolean saddled)
int getTemper()
void setTemper(int temperIn)
int increaseTemper(int p_110198_1_)
boolean attackEntityFrom(DamageSource source, float amount)
int getTotalArmorValue()
boolean canBePushed()
boolean prepareChunkForSpawn()
void dropChests()
void fall(float distance, float damageMultiplier)
void onInventoryChanged(InventoryBasic p_76316_1_)
boolean getCanSpawnHere()
EntityHorse getClosestHorse(Entity entityIn, double distance)
double getHorseJumpStrength()
String getDeathSound()
Item getDropItem()
String getHurtSound()
boolean isHorseSaddled()
String getLivingSound()
String getAngrySoundName()
void playStepSound(BlockPos pos, Block blockIn)
void applyEntityAttributes()
int getMaxSpawnedInChunk()
int getMaxTemper()
float getSoundVolume()
int getTalkInterval()
boolean func_110239_cn()
boolean func_175507_cI()
String getHorseTexture()
String[] getVariantTexturePaths()
void openGUI(EntityPlayer playerEntity)
boolean interact(EntityPlayer player)
boolean canWearArmor()
boolean canCarryChest()
boolean isMovementBlocked()
boolean isUndead()
boolean isSterile()
boolean isBreedingItem(ItemStack stack)
void onDeath(DamageSource cause)
void onLivingUpdate()
void onUpdate()
void setEating(boolean eating)
void setEatingHaystack(boolean p_110227_1_)
void setRearing(boolean rearing)
void makeHorseRearWithSound()
void dropChestItems()
boolean setTamedBy(EntityPlayer player)
void moveEntityWithHeading(float strafe, float forward)
void writeEntityToNBT(NBTTagCompound tagCompound)
void readEntityFromNBT(NBTTagCompound tagCompund)
boolean canMateWith(EntityAnimal otherAnimal)
EntityAgeable createChild(EntityAgeable ageable)
IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
float getGrassEatingAmount(float p_110258_1_)
float getRearingAmount(float p_110223_1_)
float getMouthOpennessAngle(float p_110201_1_)
void setJumpPower(int jumpPowerIn)
void spawnHorseParticles(boolean p_110216_1_)
void handleStatusUpdate(byte id)
void updateRiderPosition()
boolean isArmorItem(Item p_146085_0_)
boolean isOnLadder()
float getEyeHeight()
boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)

Fields & Constants (30)

horseBreedingSelector
horseJumpStrength
horseArmorTextures
HORSE_ARMOR_TEXTURES_ABBR
armorValues
horseTextures
HORSE_TEXTURES_ABBR
horseMarkingTextures
HORSE_MARKING_TEXTURES_ABBR
eatingHaystackCounter
openMouthCounter
jumpRearingCounter
field_110278_bp
field_110279_bq
horseJumping
horseChest
hasReproduced
temper
jumpPower
field_110294_bI
headLean
prevHeadLean
rearingAmount
prevRearingAmount
mouthOpenness
prevMouthOpenness
gallopTime
texturePrefix
horseTexturesArray
field_175508_bO

String literals (58)

"horse.jumpStrength"
"Jump Strength"
"textures/entity/horse/armor/horse_armor_iron.png"
"textures/entity/horse/armor/horse_armor_gold.png"
"textures/entity/horse/horse_white.png"
"textures/entity/horse/horse_creamy.png"
"textures/entity/horse/horse_chestnut.png"
"textures/entity/horse/horse_brown.png"
"textures/entity/horse/horse_black.png"
"textures/entity/horse/horse_gray.png"
"textures/entity/horse/horse_darkbrown.png"
"textures/entity/horse/horse_markings_white.png"
"entity.horse.name"
"entity.donkey.name"
"entity.mule.name"
"entity.zombiehorse.name"
"entity.skeletonhorse.name"
"eating"
"mob.horse.land"
"HorseChest"
"mob.horse.armor"
"mob.horse.leather"
"mob.horse.zombie.death"
"mob.horse.skeleton.death"

Full Source

EntityHorse.java1885 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.passive;
2
3
import com.google.common.base.Predicate;
4
import net.minecraft.block.Block;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.entity.Entity;
7
import net.minecraft.entity.EntityAgeable;
8
import net.minecraft.entity.EntityLivingBase;
9
import net.minecraft.entity.IEntityLivingData;
10
import net.minecraft.entity.SharedMonsterAttributes;
11
import net.minecraft.entity.ai.EntityAIFollowParent;
12
import net.minecraft.entity.ai.EntityAILookIdle;
13
import net.minecraft.entity.ai.EntityAIMate;
14
import net.minecraft.entity.ai.EntityAIPanic;
15
import net.minecraft.entity.ai.EntityAIRunAroundLikeCrazy;
16
import net.minecraft.entity.ai.EntityAISwimming;
17
import net.minecraft.entity.ai.EntityAIWander;
18
import net.minecraft.entity.ai.EntityAIWatchClosest;
19
import net.minecraft.entity.ai.attributes.IAttribute;
20
import net.minecraft.entity.ai.attributes.IAttributeInstance;
21
import net.minecraft.entity.ai.attributes.RangedAttribute;
22
import net.minecraft.entity.player.EntityPlayer;
23
import net.minecraft.init.Blocks;
24
import net.minecraft.init.Items;
25
import net.minecraft.inventory.AnimalChest;
26
import net.minecraft.inventory.IInvBasic;
27
import net.minecraft.inventory.InventoryBasic;
28
import net.minecraft.item.Item;
29
import net.minecraft.item.ItemStack;
30
import net.minecraft.nbt.NBTTagCompound;
31
import net.minecraft.nbt.NBTTagList;
32
import net.minecraft.pathfinding.PathNavigateGround;
33
import net.minecraft.potion.Potion;
34
import net.minecraft.server.management.PreYggdrasilConverter;
35
import net.minecraft.util.BlockPos;
36
import net.minecraft.util.DamageSource;
37
import net.minecraft.util.EnumParticleTypes;
38
import net.minecraft.util.MathHelper;
39
import net.minecraft.util.StatCollector;
40
import net.minecraft.world.DifficultyInstance;
41
import net.minecraft.world.World;
42
43
public class EntityHorse extends EntityAnimal implements IInvBasic
44
{
45
    private static final Predicate<Entity> horseBreedingSelector = new Predicate<Entity>()
46
    {
47
        public boolean apply(Entity p_apply_1_)
48
        {
49
            return p_apply_1_ instanceof EntityHorse && ((EntityHorse)p_apply_1_).isBreeding();
50
        }
51
    };
52
    private static final IAttribute horseJumpStrength = (new RangedAttribute((IAttribute)null, "horse.jumpStrength", 0.7D, 0.0D, 2.0D)).setDescription("Jump Strength").setShouldWatch(true);
53
    private static final String[] horseArmorTextures = new String[] {null, "textures/entity/horse/armor/horse_armor_iron.png", "textures/entity/horse/armor/horse_armor_gold.png", "textures/entity/horse/armor/horse_armor_diamond.png"};
54
    private static final String[] HORSE_ARMOR_TEXTURES_ABBR = new String[] {"", "meo", "goo", "dio"};
55
    private static final int[] armorValues = new int[] {0, 5, 7, 11};
56
    private static final String[] horseTextures = new String[] {"textures/entity/horse/horse_white.png", "textures/entity/horse/horse_creamy.png", "textures/entity/horse/horse_chestnut.png", "textures/entity/horse/horse_brown.png", "textures/entity/horse/horse_black.png", "textures/entity/horse/horse_gray.png", "textures/entity/horse/horse_darkbrown.png"};
57
    private static final String[] HORSE_TEXTURES_ABBR = new String[] {"hwh", "hcr", "hch", "hbr", "hbl", "hgr", "hdb"};
58
    private static final String[] horseMarkingTextures = new String[] {null, "textures/entity/horse/horse_markings_white.png", "textures/entity/horse/horse_markings_whitefield.png", "textures/entity/horse/horse_markings_whitedots.png", "textures/entity/horse/horse_markings_blackdots.png"};
59
    private static final String[] HORSE_MARKING_TEXTURES_ABBR = new String[] {"", "wo_", "wmo", "wdo", "bdo"};
60
    private int eatingHaystackCounter;
61
    private int openMouthCounter;
62
    private int jumpRearingCounter;
63
    public int field_110278_bp;
64
    public int field_110279_bq;
65
    protected boolean horseJumping;
66
    private AnimalChest horseChest;
67
    private boolean hasReproduced;
68
69
    /**
70
     * "The higher this value, the more likely the horse is to be tamed next time a player rides it."
71
     */
72
    protected int temper;
73
    protected float jumpPower;
74
    private boolean field_110294_bI;
75
    private float headLean;
76
    private float prevHeadLean;
77
    private float rearingAmount;
78
    private float prevRearingAmount;
79
    private float mouthOpenness;
80
    private float prevMouthOpenness;
81
82
    /** Used to determine the sound that the horse should make when it steps */
83
    private int gallopTime;
84
    private String texturePrefix;
85
    private String[] horseTexturesArray = new String[3];
86
    private boolean field_175508_bO = false;
87
88
    public EntityHorse(World worldIn)
89
    {
90
        super(worldIn);
91
        this.setSize(1.4F, 1.6F);
92
        this.isImmuneToFire = false;
93
        this.setChested(false);
94
        ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
95
        this.tasks.addTask(0, new EntityAISwimming(this));
96
        this.tasks.addTask(1, new EntityAIPanic(this, 1.2D));
97
        this.tasks.addTask(1, new EntityAIRunAroundLikeCrazy(this, 1.2D));
98
        this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
99
        this.tasks.addTask(4, new EntityAIFollowParent(this, 1.0D));
100
        this.tasks.addTask(6, new EntityAIWander(this, 0.7D));
101
        this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
102
        this.tasks.addTask(8, new EntityAILookIdle(this));
103
        this.initHorseChest();
104
    }
105
106
    protected void entityInit()
107
    {
108
        super.entityInit();
109
        this.dataWatcher.addObject(16, Integer.valueOf(0));
110
        this.dataWatcher.addObject(19, Byte.valueOf((byte)0));
111
        this.dataWatcher.addObject(20, Integer.valueOf(0));
112
        this.dataWatcher.addObject(21, String.valueOf((Object)""));
113
        this.dataWatcher.addObject(22, Integer.valueOf(0));
114
    }
115
116
    public void setHorseType(int type)
117
    {
118
        this.dataWatcher.updateObject(19, Byte.valueOf((byte)type));
119
        this.resetTexturePrefix();
120
    }
121
122
    /**
123
     * Returns the horse type. 0 = Normal, 1 = Donkey, 2 = Mule, 3 = Undead Horse, 4 = Skeleton Horse
124
     */
125
    public int getHorseType()
126
    {
127
        return this.dataWatcher.getWatchableObjectByte(19);
128
    }
129
130
    public void setHorseVariant(int variant)
131
    {
132
        this.dataWatcher.updateObject(20, Integer.valueOf(variant));
133
        this.resetTexturePrefix();
134
    }
135
136
    public int getHorseVariant()
137
    {
138
        return this.dataWatcher.getWatchableObjectInt(20);
139
    }
140
141
    /**
142
     * Get the name of this object. For players this returns their username
143
     */
144
    public String getName()
145
    {
146
        if (this.hasCustomName())
147
        {
148
            return this.getCustomNameTag();
149
        }
150
        else
151
        {
152
            int i = this.getHorseType();
153
154
            switch (i)
155
            {
156
                case 0:
157
                default:
158
                    return StatCollector.translateToLocal("entity.horse.name");
159
160
                case 1:
161
                    return StatCollector.translateToLocal("entity.donkey.name");
162
163
                case 2:
164
                    return StatCollector.translateToLocal("entity.mule.name");
165
166
                case 3:
167
                    return StatCollector.translateToLocal("entity.zombiehorse.name");
168
169
                case 4:
170
                    return StatCollector.translateToLocal("entity.skeletonhorse.name");
171
            }
172
        }
173
    }
174
175
    private boolean getHorseWatchableBoolean(int p_110233_1_)
176
    {
177
        return (this.dataWatcher.getWatchableObjectInt(16) & p_110233_1_) != 0;
178
    }
179
180
    private void setHorseWatchableBoolean(int p_110208_1_, boolean p_110208_2_)
181
    {
182
        int i = this.dataWatcher.getWatchableObjectInt(16);
183
184
        if (p_110208_2_)
185
        {
186
            this.dataWatcher.updateObject(16, Integer.valueOf(i | p_110208_1_));
187
        }
188
        else
189
        {
190
            this.dataWatcher.updateObject(16, Integer.valueOf(i & ~p_110208_1_));
191
        }
192
    }
193
194
    public boolean isAdultHorse()
195
    {
196
        return !this.isChild();
197
    }
198
199
    public boolean isTame()
200
    {
201
        return this.getHorseWatchableBoolean(2);
202
    }
203
204
    public boolean func_110253_bW()
205
    {
206
        return this.isAdultHorse();
207
    }
208
209
    /**
210
     * Gets the horse's owner
211
     */
212
    public String getOwnerId()
213
    {
214
        return this.dataWatcher.getWatchableObjectString(21);
215
    }
216
217
    public void setOwnerId(String id)
218
    {
219
        this.dataWatcher.updateObject(21, id);
220
    }
221
222
    public float getHorseSize()
223
    {
224
        return 0.5F;
225
    }
226
227
    /**
228
     * "Sets the scale for an ageable entity according to the boolean parameter, which says if it's a child."
229
     */
230
    public void setScaleForAge(boolean p_98054_1_)
231
    {
232
        if (p_98054_1_)
233
        {
234
            this.setScale(this.getHorseSize());
235
        }
236
        else
237
        {
238
            this.setScale(1.0F);
239
        }
240
    }
241
242
    public boolean isHorseJumping()
243
    {
244
        return this.horseJumping;
245
    }
246
247
    public void setHorseTamed(boolean tamed)
248
    {
249
        this.setHorseWatchableBoolean(2, tamed);
250
    }
251
252
    public void setHorseJumping(boolean jumping)
253
    {
254
        this.horseJumping = jumping;
255
    }
256
257
    public boolean allowLeashing()
258
    {
259
        return !this.isUndead() && super.allowLeashing();
260
    }
261
262
    protected void func_142017_o(float p_142017_1_)
263
    {
264
        if (p_142017_1_ > 6.0F && this.isEatingHaystack())
265
        {
266
            this.setEatingHaystack(false);
267
        }
268
    }
269
270
    public boolean isChested()
271
    {
272
        return this.getHorseWatchableBoolean(8);
273
    }
274
275
    /**
276
     * Returns type of armor from DataWatcher (0 = iron, 1 = gold, 2 = diamond)
277
     */
278
    public int getHorseArmorIndexSynced()
279
    {
280
        return this.dataWatcher.getWatchableObjectInt(22);
281
    }
282
283
    /**
284
     * 0 = iron, 1 = gold, 2 = diamond
285
     */
286
    private int getHorseArmorIndex(ItemStack itemStackIn)
287
    {
288
        if (itemStackIn == null)
289
        {
290
            return 0;
291
        }
292
        else
293
        {
294
            Item item = itemStackIn.getItem();
295
            return item == Items.iron_horse_armor ? 1 : (item == Items.golden_horse_armor ? 2 : (item == Items.diamond_horse_armor ? 3 : 0));
296
        }
297
    }
298
299
    public boolean isEatingHaystack()
300
    {
301
        return this.getHorseWatchableBoolean(32);
302
    }
303
304
    public boolean isRearing()
305
    {
306
        return this.getHorseWatchableBoolean(64);
307
    }
308
309
    public boolean isBreeding()
310
    {
311
        return this.getHorseWatchableBoolean(16);
312
    }
313
314
    public boolean getHasReproduced()
315
    {
316
        return this.hasReproduced;
317
    }
318
319
    /**
320
     * Set horse armor stack (for example: new ItemStack(Items.iron_horse_armor))
321
     */
322
    public void setHorseArmorStack(ItemStack itemStackIn)
323
    {
324
        this.dataWatcher.updateObject(22, Integer.valueOf(this.getHorseArmorIndex(itemStackIn)));
325
        this.resetTexturePrefix();
326
    }
327
328
    public void setBreeding(boolean breeding)
329
    {
330
        this.setHorseWatchableBoolean(16, breeding);
331
    }
332
333
    public void setChested(boolean chested)
334
    {
335
        this.setHorseWatchableBoolean(8, chested);
336
    }
337
338
    public void setHasReproduced(boolean hasReproducedIn)
339
    {
340
        this.hasReproduced = hasReproducedIn;
341
    }
342
343
    public void setHorseSaddled(boolean saddled)
344
    {
345
        this.setHorseWatchableBoolean(4, saddled);
346
    }
347
348
    public int getTemper()
349
    {
350
        return this.temper;
351
    }
352
353
    public void setTemper(int temperIn)
354
    {
355
        this.temper = temperIn;
356
    }
357
358
    public int increaseTemper(int p_110198_1_)
359
    {
360
        int i = MathHelper.clamp_int(this.getTemper() + p_110198_1_, 0, this.getMaxTemper());
361
        this.setTemper(i);
362
        return i;
363
    }
364
365
    /**
366
     * Called when the entity is attacked.
367
     */
368
    public boolean attackEntityFrom(DamageSource source, float amount)
369
    {
370
        Entity entity = source.getEntity();
371
        return this.riddenByEntity != null && this.riddenByEntity.equals(entity) ? false : super.attackEntityFrom(source, amount);
372
    }
373
374
    /**
375
     * Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
376
     */
377
    public int getTotalArmorValue()
378
    {
379
        return armorValues[this.getHorseArmorIndexSynced()];
380
    }
381
382
    /**
383
     * Returns true if this entity should push and be pushed by other entities when colliding.
384
     */
385
    public boolean canBePushed()
386
    {
387
        return this.riddenByEntity == null;
388
    }
389
390
    public boolean prepareChunkForSpawn()
391
    {
392
        int i = MathHelper.floor_double(this.posX);
393
        int j = MathHelper.floor_double(this.posZ);
394
        this.worldObj.getBiomeGenForCoords(new BlockPos(i, 0, j));
395
        return true;
396
    }
397
398
    public void dropChests()
399
    {
400
        if (!this.worldObj.isRemote && this.isChested())
401
        {
402
            this.dropItem(Item.getItemFromBlock(Blocks.chest), 1);
403
            this.setChested(false);
404
        }
405
    }
406
407
    private void func_110266_cB()
408
    {
409
        this.openHorseMouth();
410
411
        if (!this.isSilent())
412
        {
413
            this.worldObj.playSoundAtEntity(this, "eating", 1.0F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
414
        }
415
    }
416
417
    public void fall(float distance, float damageMultiplier)
418
    {
419
        if (distance > 1.0F)
420
        {
421
            this.playSound("mob.horse.land", 0.4F, 1.0F);
422
        }
423
424
        int i = MathHelper.ceiling_float_int((distance * 0.5F - 3.0F) * damageMultiplier);
425
426
        if (i > 0)
427
        {
428
            this.attackEntityFrom(DamageSource.fall, (float)i);
429
430
            if (this.riddenByEntity != null)
431
            {
432
                this.riddenByEntity.attackEntityFrom(DamageSource.fall, (float)i);
433
            }
434
435
            Block block = this.worldObj.getBlockState(new BlockPos(this.posX, this.posY - 0.2D - (double)this.prevRotationYaw, this.posZ)).getBlock();
436
437
            if (block.getMaterial() != Material.air && !this.isSilent())
438
            {
439
                Block.SoundType block$soundtype = block.stepSound;
440
                this.worldObj.playSoundAtEntity(this, block$soundtype.getStepSound(), block$soundtype.getVolume() * 0.5F, block$soundtype.getFrequency() * 0.75F);
441
            }
442
        }
443
    }
444
445
    /**
446
     * Returns number of slots depending horse type
447
     */
448
    private int getChestSize()
449
    {
450
        int i = this.getHorseType();
451
        return !this.isChested() || i != 1 && i != 2 ? 2 : 17;
452
    }
453
454
    private void initHorseChest()
455
    {
456
        AnimalChest animalchest = this.horseChest;
457
        this.horseChest = new AnimalChest("HorseChest", this.getChestSize());
458
        this.horseChest.setCustomName(this.getName());
459
460
        if (animalchest != null)
461
        {
462
            animalchest.removeInventoryChangeListener(this);
463
            int i = Math.min(animalchest.getSizeInventory(), this.horseChest.getSizeInventory());
464
465
            for (int j = 0; j < i; ++j)
466
            {
467
                ItemStack itemstack = animalchest.getStackInSlot(j);
468
469
                if (itemstack != null)
470
                {
471
                    this.horseChest.setInventorySlotContents(j, itemstack.copy());
472
                }
473
            }
474
        }
475
476
        this.horseChest.addInventoryChangeListener(this);
477
        this.updateHorseSlots();
478
    }
479
480
    /**
481
     * Updates the items in the saddle and armor slots of the horse's inventory.
482
     */
483
    private void updateHorseSlots()
484
    {
485
        if (!this.worldObj.isRemote)
486
        {
487
            this.setHorseSaddled(this.horseChest.getStackInSlot(0) != null);
488
489
            if (this.canWearArmor())
490
            {
491
                this.setHorseArmorStack(this.horseChest.getStackInSlot(1));
492
            }
493
        }
494
    }
495
496
    /**
497
     * Called by InventoryBasic.onInventoryChanged() on a array that is never filled.
498
     */
499
    public void onInventoryChanged(InventoryBasic p_76316_1_)
500
    {
501
        int i = this.getHorseArmorIndexSynced();
502
        boolean flag = this.isHorseSaddled();
503
        this.updateHorseSlots();
504
505
        if (this.ticksExisted > 20)
506
        {
507
            if (i == 0 && i != this.getHorseArmorIndexSynced())
508
            {
509
                this.playSound("mob.horse.armor", 0.5F, 1.0F);
510
            }
511
            else if (i != this.getHorseArmorIndexSynced())
512
            {
513
                this.playSound("mob.horse.armor", 0.5F, 1.0F);
514
            }
515
516
            if (!flag && this.isHorseSaddled())
517
            {
518
                this.playSound("mob.horse.leather", 0.5F, 1.0F);
519
            }
520
        }
521
    }
522
523
    /**
524
     * Checks if the entity's current position is a valid location to spawn this entity.
525
     */
526
    public boolean getCanSpawnHere()
527
    {
528
        this.prepareChunkForSpawn();
529
        return super.getCanSpawnHere();
530
    }
531
532
    protected EntityHorse getClosestHorse(Entity entityIn, double distance)
533
    {
534
        double d0 = Double.MAX_VALUE;
535
        Entity entity = null;
536
537
        for (Entity entity1 : this.worldObj.getEntitiesInAABBexcluding(entityIn, entityIn.getEntityBoundingBox().addCoord(distance, distance, distance), horseBreedingSelector))
538
        {
539
            double d1 = entity1.getDistanceSq(entityIn.posX, entityIn.posY, entityIn.posZ);
540
541
            if (d1 < d0)
542
            {
543
                entity = entity1;
544
                d0 = d1;
545
            }
546
        }
547
548
        return (EntityHorse)entity;
549
    }
550
551
    public double getHorseJumpStrength()
552
    {
553
        return this.getEntityAttribute(horseJumpStrength).getAttributeValue();
554
    }
555
556
    /**
557
     * Returns the sound this mob makes on death.
558
     */
559
    protected String getDeathSound()
560
    {
561
        this.openHorseMouth();
562
        int i = this.getHorseType();
563
        return i == 3 ? "mob.horse.zombie.death" : (i == 4 ? "mob.horse.skeleton.death" : (i != 1 && i != 2 ? "mob.horse.death" : "mob.horse.donkey.death"));
564
    }
565
566
    protected Item getDropItem()
567
    {
568
        boolean flag = this.rand.nextInt(4) == 0;
569
        int i = this.getHorseType();
570
        return i == 4 ? Items.bone : (i == 3 ? (flag ? null : Items.rotten_flesh) : Items.leather);
571
    }
572
573
    /**
574
     * Returns the sound this mob makes when it is hurt.
575
     */
576
    protected String getHurtSound()
577
    {
578
        this.openHorseMouth();
579
580
        if (this.rand.nextInt(3) == 0)
581
        {
582
            this.makeHorseRear();
583
        }
584
585
        int i = this.getHorseType();
586
        return i == 3 ? "mob.horse.zombie.hit" : (i == 4 ? "mob.horse.skeleton.hit" : (i != 1 && i != 2 ? "mob.horse.hit" : "mob.horse.donkey.hit"));
587
    }
588
589
    public boolean isHorseSaddled()
590
    {
591
        return this.getHorseWatchableBoolean(4);
592
    }
593
594
    /**
595
     * Returns the sound this mob makes while it's alive.
596
     */
597
    protected String getLivingSound()
598
    {
599
        this.openHorseMouth();
600
601
        if (this.rand.nextInt(10) == 0 && !this.isMovementBlocked())
602
        {
603
            this.makeHorseRear();
604
        }
605
606
        int i = this.getHorseType();
607
        return i == 3 ? "mob.horse.zombie.idle" : (i == 4 ? "mob.horse.skeleton.idle" : (i != 1 && i != 2 ? "mob.horse.idle" : "mob.horse.donkey.idle"));
608
    }
609
610
    protected String getAngrySoundName()
611
    {
612
        this.openHorseMouth();
613
        this.makeHorseRear();
614
        int i = this.getHorseType();
615
        return i != 3 && i != 4 ? (i != 1 && i != 2 ? "mob.horse.angry" : "mob.horse.donkey.angry") : null;
616
    }
617
618
    protected void playStepSound(BlockPos pos, Block blockIn)
619
    {
620
        Block.SoundType block$soundtype = blockIn.stepSound;
621
622
        if (this.worldObj.getBlockState(pos.up()).getBlock() == Blocks.snow_layer)
623
        {
624
            block$soundtype = Blocks.snow_layer.stepSound;
625
        }
626
627
        if (!blockIn.getMaterial().isLiquid())
628
        {
629
            int i = this.getHorseType();
630
631
            if (this.riddenByEntity != null && i != 1 && i != 2)
632
            {
633
                ++this.gallopTime;
634
635
                if (this.gallopTime > 5 && this.gallopTime % 3 == 0)
636
                {
637
                    this.playSound("mob.horse.gallop", block$soundtype.getVolume() * 0.15F, block$soundtype.getFrequency());
638
639
                    if (i == 0 && this.rand.nextInt(10) == 0)
640
                    {
641
                        this.playSound("mob.horse.breathe", block$soundtype.getVolume() * 0.6F, block$soundtype.getFrequency());
642
                    }
643
                }
644
                else if (this.gallopTime <= 5)
645
                {
646
                    this.playSound("mob.horse.wood", block$soundtype.getVolume() * 0.15F, block$soundtype.getFrequency());
647
                }
648
            }
649
            else if (block$soundtype == Block.soundTypeWood)
650
            {
651
                this.playSound("mob.horse.wood", block$soundtype.getVolume() * 0.15F, block$soundtype.getFrequency());
652
            }
653
            else
654
            {
655
                this.playSound("mob.horse.soft", block$soundtype.getVolume() * 0.15F, block$soundtype.getFrequency());
656
            }
657
        }
658
    }
659
660
    protected void applyEntityAttributes()
661
    {
662
        super.applyEntityAttributes();
663
        this.getAttributeMap().registerAttribute(horseJumpStrength);
664
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(53.0D);
665
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.22499999403953552D);
666
    }
667
668
    /**
669
     * Will return how many at most can spawn in a chunk at once.
670
     */
671
    public int getMaxSpawnedInChunk()
672
    {
673
        return 6;
674
    }
675
676
    public int getMaxTemper()
677
    {
678
        return 100;
679
    }
680
681
    /**
682
     * Returns the volume for the sounds this mob makes.
683
     */
684
    protected float getSoundVolume()
685
    {
686
        return 0.8F;
687
    }
688
689
    /**
690
     * Get number of ticks, at least during which the living entity will be silent.
691
     */
692
    public int getTalkInterval()
693
    {
694
        return 400;
695
    }
696
697
    public boolean func_110239_cn()
698
    {
699
        return this.getHorseType() == 0 || this.getHorseArmorIndexSynced() > 0;
700
    }
701
702
    private void resetTexturePrefix()
703
    {
704
        this.texturePrefix = null;
705
    }
706
707
    public boolean func_175507_cI()
708
    {
709
        return this.field_175508_bO;
710
    }
711
712
    private void setHorseTexturePaths()
713
    {
714
        this.texturePrefix = "horse/";
715
        this.horseTexturesArray[0] = null;
716
        this.horseTexturesArray[1] = null;
717
        this.horseTexturesArray[2] = null;
718
        int i = this.getHorseType();
719
        int j = this.getHorseVariant();
720
721
        if (i == 0)
722
        {
723
            int k = j & 255;
724
            int l = (j & 65280) >> 8;
725
726
            if (k >= horseTextures.length)
727
            {
728
                this.field_175508_bO = false;
729
                return;
730
            }
731
732
            this.horseTexturesArray[0] = horseTextures[k];
733
            this.texturePrefix = this.texturePrefix + HORSE_TEXTURES_ABBR[k];
734
735
            if (l >= horseMarkingTextures.length)
736
            {
737
                this.field_175508_bO = false;
738
                return;
739
            }
740
741
            this.horseTexturesArray[1] = horseMarkingTextures[l];
742
            this.texturePrefix = this.texturePrefix + HORSE_MARKING_TEXTURES_ABBR[l];
743
        }
744
        else
745
        {
746
            this.horseTexturesArray[0] = "";
747
            this.texturePrefix = this.texturePrefix + "_" + i + "_";
748
        }
749
750
        int i1 = this.getHorseArmorIndexSynced();
751
752
        if (i1 >= horseArmorTextures.length)
753
        {
754
            this.field_175508_bO = false;
755
        }
756
        else
757
        {
758
            this.horseTexturesArray[2] = horseArmorTextures[i1];
759
            this.texturePrefix = this.texturePrefix + HORSE_ARMOR_TEXTURES_ABBR[i1];
760
            this.field_175508_bO = true;
761
        }
762
    }
763
764
    public String getHorseTexture()
765
    {
766
        if (this.texturePrefix == null)
767
        {
768
            this.setHorseTexturePaths();
769
        }
770
771
        return this.texturePrefix;
772
    }
773
774
    public String[] getVariantTexturePaths()
775
    {
776
        if (this.texturePrefix == null)
777
        {
778
            this.setHorseTexturePaths();
779
        }
780
781
        return this.horseTexturesArray;
782
    }
783
784
    public void openGUI(EntityPlayer playerEntity)
785
    {
786
        if (!this.worldObj.isRemote && (this.riddenByEntity == null || this.riddenByEntity == playerEntity) && this.isTame())
787
        {
788
            this.horseChest.setCustomName(this.getName());
789
            playerEntity.displayGUIHorse(this, this.horseChest);
790
        }
791
    }
792
793
    /**
794
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
795
     */
796
    public boolean interact(EntityPlayer player)
797
    {
798
        ItemStack itemstack = player.inventory.getCurrentItem();
799
800
        if (itemstack != null && itemstack.getItem() == Items.spawn_egg)
801
        {
802
            return super.interact(player);
803
        }
804
        else if (!this.isTame() && this.isUndead())
805
        {
806
            return false;
807
        }
808
        else if (this.isTame() && this.isAdultHorse() && player.isSneaking())
809
        {
810
            this.openGUI(player);
811
            return true;
812
        }
813
        else if (this.func_110253_bW() && this.riddenByEntity != null)
814
        {
815
            return super.interact(player);
816
        }
817
        else
818
        {
819
            if (itemstack != null)
820
            {
821
                boolean flag = false;
822
823
                if (this.canWearArmor())
824
                {
825
                    int i = -1;
826
827
                    if (itemstack.getItem() == Items.iron_horse_armor)
828
                    {
829
                        i = 1;
830
                    }
831
                    else if (itemstack.getItem() == Items.golden_horse_armor)
832
                    {
833
                        i = 2;
834
                    }
835
                    else if (itemstack.getItem() == Items.diamond_horse_armor)
836
                    {
837
                        i = 3;
838
                    }
839
840
                    if (i >= 0)
841
                    {
842
                        if (!this.isTame())
843
                        {
844
                            this.makeHorseRearWithSound();
845
                            return true;
846
                        }
847
848
                        this.openGUI(player);
849
                        return true;
850
                    }
851
                }
852
853
                if (!flag && !this.isUndead())
854
                {
855
                    float f = 0.0F;
856
                    int j = 0;
857
                    int k = 0;
858
859
                    if (itemstack.getItem() == Items.wheat)
860
                    {
861
                        f = 2.0F;
862
                        j = 20;
863
                        k = 3;
864
                    }
865
                    else if (itemstack.getItem() == Items.sugar)
866
                    {
867
                        f = 1.0F;
868
                        j = 30;
869
                        k = 3;
870
                    }
871
                    else if (Block.getBlockFromItem(itemstack.getItem()) == Blocks.hay_block)
872
                    {
873
                        f = 20.0F;
874
                        j = 180;
875
                    }
876
                    else if (itemstack.getItem() == Items.apple)
877
                    {
878
                        f = 3.0F;
879
                        j = 60;
880
                        k = 3;
881
                    }
882
                    else if (itemstack.getItem() == Items.golden_carrot)
883
                    {
884
                        f = 4.0F;
885
                        j = 60;
886
                        k = 5;
887
888
                        if (this.isTame() && this.getGrowingAge() == 0)
889
                        {
890
                            flag = true;
891
                            this.setInLove(player);
892
                        }
893
                    }
894
                    else if (itemstack.getItem() == Items.golden_apple)
895
                    {
896
                        f = 10.0F;
897
                        j = 240;
898
                        k = 10;
899
900
                        if (this.isTame() && this.getGrowingAge() == 0)
901
                        {
902
                            flag = true;
903
                            this.setInLove(player);
904
                        }
905
                    }
906
907
                    if (this.getHealth() < this.getMaxHealth() && f > 0.0F)
908
                    {
909
                        this.heal(f);
910
                        flag = true;
911
                    }
912
913
                    if (!this.isAdultHorse() && j > 0)
914
                    {
915
                        this.addGrowth(j);
916
                        flag = true;
917
                    }
918
919
                    if (k > 0 && (flag || !this.isTame()) && k < this.getMaxTemper())
920
                    {
921
                        flag = true;
922
                        this.increaseTemper(k);
923
                    }
924
925
                    if (flag)
926
                    {
927
                        this.func_110266_cB();
928
                    }
929
                }
930
931
                if (!this.isTame() && !flag)
932
                {
933
                    if (itemstack != null && itemstack.interactWithEntity(player, this))
934
                    {
935
                        return true;
936
                    }
937
938
                    this.makeHorseRearWithSound();
939
                    return true;
940
                }
941
942
                if (!flag && this.canCarryChest() && !this.isChested() && itemstack.getItem() == Item.getItemFromBlock(Blocks.chest))
943
                {
944
                    this.setChested(true);
945
                    this.playSound("mob.chickenplop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
946
                    flag = true;
947
                    this.initHorseChest();
948
                }
949
950
                if (!flag && this.func_110253_bW() && !this.isHorseSaddled() && itemstack.getItem() == Items.saddle)
951
                {
952
                    this.openGUI(player);
953
                    return true;
954
                }
955
956
                if (flag)
957
                {
958
                    if (!player.capabilities.isCreativeMode && --itemstack.stackSize == 0)
959
                    {
960
                        player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
961
                    }
962
963
                    return true;
964
                }
965
            }
966
967
            if (this.func_110253_bW() && this.riddenByEntity == null)
968
            {
969
                if (itemstack != null && itemstack.interactWithEntity(player, this))
970
                {
971
                    return true;
972
                }
973
                else
974
                {
975
                    this.mountTo(player);
976
                    return true;
977
                }
978
            }
979
            else
980
            {
981
                return super.interact(player);
982
            }
983
        }
984
    }
985
986
    private void mountTo(EntityPlayer player)
987
    {
988
        player.rotationYaw = this.rotationYaw;
989
        player.rotationPitch = this.rotationPitch;
990
        this.setEatingHaystack(false);
991
        this.setRearing(false);
992
993
        if (!this.worldObj.isRemote)
994
        {
995
            player.mountEntity(this);
996
        }
997
    }
998
999
    /**
1000
     * Return true if the horse entity can wear an armor
1001
     */
1002
    public boolean canWearArmor()
1003
    {
1004
        return this.getHorseType() == 0;
1005
    }
1006
1007
    /**
1008
     * Return true if the horse entity can carry a chest.
1009
     */
1010
    public boolean canCarryChest()
1011
    {
1012
        int i = this.getHorseType();
1013
        return i == 2 || i == 1;
1014
    }
1015
1016
    /**
1017
     * Dead and sleeping entities cannot move
1018
     */
1019
    protected boolean isMovementBlocked()
1020
    {
1021
        return this.riddenByEntity != null && this.isHorseSaddled() ? true : this.isEatingHaystack() || this.isRearing();
1022
    }
1023
1024
    /**
1025
     * Used to know if the horse can be leashed, if he can mate, or if we can interact with him
1026
     */
1027
    public boolean isUndead()
1028
    {
1029
        int i = this.getHorseType();
1030
        return i == 3 || i == 4;
1031
    }
1032
1033
    /**
1034
     * Return true if the horse entity is sterile (Undead || Mule)
1035
     */
1036
    public boolean isSterile()
1037
    {
1038
        return this.isUndead() || this.getHorseType() == 2;
1039
    }
1040
1041
    /**
1042
     * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
1043
     * the animal type)
1044
     */
1045
    public boolean isBreedingItem(ItemStack stack)
1046
    {
1047
        return false;
1048
    }
1049
1050
    private void func_110210_cH()
1051
    {
1052
        this.field_110278_bp = 1;
1053
    }
1054
1055
    /**
1056
     * Called when the mob's health reaches 0.
1057
     */
1058
    public void onDeath(DamageSource cause)
1059
    {
1060
        super.onDeath(cause);
1061
1062
        if (!this.worldObj.isRemote)
1063
        {
1064
            this.dropChestItems();
1065
        }
1066
    }
1067
1068
    /**
1069
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
1070
     * use this to react to sunlight and start to burn.
1071
     */
1072
    public void onLivingUpdate()
1073
    {
1074
        if (this.rand.nextInt(200) == 0)
1075
        {
1076
            this.func_110210_cH();
1077
        }
1078
1079
        super.onLivingUpdate();
1080
1081
        if (!this.worldObj.isRemote)
1082
        {
1083
            if (this.rand.nextInt(900) == 0 && this.deathTime == 0)
1084
            {
1085
                this.heal(1.0F);
1086
            }
1087
1088
            if (!this.isEatingHaystack() && this.riddenByEntity == null && this.rand.nextInt(300) == 0 && this.worldObj.getBlockState(new BlockPos(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) - 1, MathHelper.floor_double(this.posZ))).getBlock() == Blocks.grass)
1089
            {
1090
                this.setEatingHaystack(true);
1091
            }
1092
1093
            if (this.isEatingHaystack() && ++this.eatingHaystackCounter > 50)
1094
            {
1095
                this.eatingHaystackCounter = 0;
1096
                this.setEatingHaystack(false);
1097
            }
1098
1099
            if (this.isBreeding() && !this.isAdultHorse() && !this.isEatingHaystack())
1100
            {
1101
                EntityHorse entityhorse = this.getClosestHorse(this, 16.0D);
1102
1103
                if (entityhorse != null && this.getDistanceSqToEntity(entityhorse) > 4.0D)
1104
                {
1105
                    this.navigator.getPathToEntityLiving(entityhorse);
1106
                }
1107
            }
1108
        }
1109
    }
1110
1111
    /**
1112
     * Called to update the entity's position/logic.
1113
     */
1114
    public void onUpdate()
1115
    {
1116
        super.onUpdate();
1117
1118
        if (this.worldObj.isRemote && this.dataWatcher.hasObjectChanged())
1119
        {
1120
            this.dataWatcher.func_111144_e();
1121
            this.resetTexturePrefix();
1122
        }
1123
1124
        if (this.openMouthCounter > 0 && ++this.openMouthCounter > 30)
1125
        {
1126
            this.openMouthCounter = 0;
1127
            this.setHorseWatchableBoolean(128, false);
1128
        }
1129
1130
        if (!this.worldObj.isRemote && this.jumpRearingCounter > 0 && ++this.jumpRearingCounter > 20)
1131
        {
1132
            this.jumpRearingCounter = 0;
1133
            this.setRearing(false);
1134
        }
1135
1136
        if (this.field_110278_bp > 0 && ++this.field_110278_bp > 8)
1137
        {
1138
            this.field_110278_bp = 0;
1139
        }
1140
1141
        if (this.field_110279_bq > 0)
1142
        {
1143
            ++this.field_110279_bq;
1144
1145
            if (this.field_110279_bq > 300)
1146
            {
1147
                this.field_110279_bq = 0;
1148
            }
1149
        }
1150
1151
        this.prevHeadLean = this.headLean;
1152
1153
        if (this.isEatingHaystack())
1154
        {
1155
            this.headLean += (1.0F - this.headLean) * 0.4F + 0.05F;
1156
1157
            if (this.headLean > 1.0F)
1158
            {
1159
                this.headLean = 1.0F;
1160
            }
1161
        }
1162
        else
1163
        {
1164
            this.headLean += (0.0F - this.headLean) * 0.4F - 0.05F;
1165
1166
            if (this.headLean < 0.0F)
1167
            {
1168
                this.headLean = 0.0F;
1169
            }
1170
        }
1171
1172
        this.prevRearingAmount = this.rearingAmount;
1173
1174
        if (this.isRearing())
1175
        {
1176
            this.prevHeadLean = this.headLean = 0.0F;
1177
            this.rearingAmount += (1.0F - this.rearingAmount) * 0.4F + 0.05F;
1178
1179
            if (this.rearingAmount > 1.0F)
1180
            {
1181
                this.rearingAmount = 1.0F;
1182
            }
1183
        }
1184
        else
1185
        {
1186
            this.field_110294_bI = false;
1187
            this.rearingAmount += (0.8F * this.rearingAmount * this.rearingAmount * this.rearingAmount - this.rearingAmount) * 0.6F - 0.05F;
1188
1189
            if (this.rearingAmount < 0.0F)
1190
            {
1191
                this.rearingAmount = 0.0F;
1192
            }
1193
        }
1194
1195
        this.prevMouthOpenness = this.mouthOpenness;
1196
1197
        if (this.getHorseWatchableBoolean(128))
1198
        {
1199
            this.mouthOpenness += (1.0F - this.mouthOpenness) * 0.7F + 0.05F;
1200
1201
            if (this.mouthOpenness > 1.0F)
1202
            {
1203
                this.mouthOpenness = 1.0F;
1204
            }
1205
        }
1206
        else
1207
        {
1208
            this.mouthOpenness += (0.0F - this.mouthOpenness) * 0.7F - 0.05F;
1209
1210
            if (this.mouthOpenness < 0.0F)
1211
            {
1212
                this.mouthOpenness = 0.0F;
1213
            }
1214
        }
1215
    }
1216
1217
    private void openHorseMouth()
1218
    {
1219
        if (!this.worldObj.isRemote)
1220
        {
1221
            this.openMouthCounter = 1;
1222
            this.setHorseWatchableBoolean(128, true);
1223
        }
1224
    }
1225
1226
    /**
1227
     * Return true if the horse entity ready to mate. (no rider, not riding, tame, adult, not steril...)
1228
     */
1229
    private boolean canMate()
1230
    {
1231
        return this.riddenByEntity == null && this.ridingEntity == null && this.isTame() && this.isAdultHorse() && !this.isSterile() && this.getHealth() >= this.getMaxHealth() && this.isInLove();
1232
    }
1233
1234
    public void setEating(boolean eating)
1235
    {
1236
        this.setHorseWatchableBoolean(32, eating);
1237
    }
1238
1239
    public void setEatingHaystack(boolean p_110227_1_)
1240
    {
1241
        this.setEating(p_110227_1_);
1242
    }
1243
1244
    public void setRearing(boolean rearing)
1245
    {
1246
        if (rearing)
1247
        {
1248
            this.setEatingHaystack(false);
1249
        }
1250
1251
        this.setHorseWatchableBoolean(64, rearing);
1252
    }
1253
1254
    private void makeHorseRear()
1255
    {
1256
        if (!this.worldObj.isRemote)
1257
        {
1258
            this.jumpRearingCounter = 1;
1259
            this.setRearing(true);
1260
        }
1261
    }
1262
1263
    public void makeHorseRearWithSound()
1264
    {
1265
        this.makeHorseRear();
1266
        String s = this.getAngrySoundName();
1267
1268
        if (s != null)
1269
        {
1270
            this.playSound(s, this.getSoundVolume(), this.getSoundPitch());
1271
        }
1272
    }
1273
1274
    public void dropChestItems()
1275
    {
1276
        this.dropItemsInChest(this, this.horseChest);
1277
        this.dropChests();
1278
    }
1279
1280
    private void dropItemsInChest(Entity entityIn, AnimalChest animalChestIn)
1281
    {
1282
        if (animalChestIn != null && !this.worldObj.isRemote)
1283
        {
1284
            for (int i = 0; i < animalChestIn.getSizeInventory(); ++i)
1285
            {
1286
                ItemStack itemstack = animalChestIn.getStackInSlot(i);
1287
1288
                if (itemstack != null)
1289
                {
1290
                    this.entityDropItem(itemstack, 0.0F);
1291
                }
1292
            }
1293
        }
1294
    }
1295
1296
    public boolean setTamedBy(EntityPlayer player)
1297
    {
1298
        this.setOwnerId(player.getUniqueID().toString());
1299
        this.setHorseTamed(true);
1300
        return true;
1301
    }
1302
1303
    /**
1304
     * Moves the entity based on the specified heading.  Args: strafe, forward
1305
     */
1306
    public void moveEntityWithHeading(float strafe, float forward)
1307
    {
1308
        if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase && this.isHorseSaddled())
1309
        {
1310
            this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
1311
            this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
1312
            this.setRotation(this.rotationYaw, this.rotationPitch);
1313
            this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
1314
            strafe = ((EntityLivingBase)this.riddenByEntity).moveStrafing * 0.5F;
1315
            forward = ((EntityLivingBase)this.riddenByEntity).moveForward;
1316
1317
            if (forward <= 0.0F)
1318
            {
1319
                forward *= 0.25F;
1320
                this.gallopTime = 0;
1321
            }
1322
1323
            if (this.onGround && this.jumpPower == 0.0F && this.isRearing() && !this.field_110294_bI)
1324
            {
1325
                strafe = 0.0F;
1326
                forward = 0.0F;
1327
            }
1328
1329
            if (this.jumpPower > 0.0F && !this.isHorseJumping() && this.onGround)
1330
            {
1331
                this.motionY = this.getHorseJumpStrength() * (double)this.jumpPower;
1332
1333
                if (this.isPotionActive(Potion.jump))
1334
                {
1335
                    this.motionY += (double)((float)(this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
1336
                }
1337
1338
                this.setHorseJumping(true);
1339
                this.isAirBorne = true;
1340
1341
                if (forward > 0.0F)
1342
                {
1343
                    float f = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F);
1344
                    float f1 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F);
1345
                    this.motionX += (double)(-0.4F * f * this.jumpPower);
1346
                    this.motionZ += (double)(0.4F * f1 * this.jumpPower);
1347
                    this.playSound("mob.horse.jump", 0.4F, 1.0F);
1348
                }
1349
1350
                this.jumpPower = 0.0F;
1351
            }
1352
1353
            this.stepHeight = 1.0F;
1354
            this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;
1355
1356
            if (!this.worldObj.isRemote)
1357
            {
1358
                this.setAIMoveSpeed((float)this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
1359
                super.moveEntityWithHeading(strafe, forward);
1360
            }
1361
1362
            if (this.onGround)
1363
            {
1364
                this.jumpPower = 0.0F;
1365
                this.setHorseJumping(false);
1366
            }
1367
1368
            this.prevLimbSwingAmount = this.limbSwingAmount;
1369
            double d1 = this.posX - this.prevPosX;
1370
            double d0 = this.posZ - this.prevPosZ;
1371
            float f2 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;
1372
1373
            if (f2 > 1.0F)
1374
            {
1375
                f2 = 1.0F;
1376
            }
1377
1378
            this.limbSwingAmount += (f2 - this.limbSwingAmount) * 0.4F;
1379
            this.limbSwing += this.limbSwingAmount;
1380
        }
1381
        else
1382
        {
1383
            this.stepHeight = 0.5F;
1384
            this.jumpMovementFactor = 0.02F;
1385
            super.moveEntityWithHeading(strafe, forward);
1386
        }
1387
    }
1388
1389
    /**
1390
     * (abstract) Protected helper method to write subclass entity data to NBT.
1391
     */
1392
    public void writeEntityToNBT(NBTTagCompound tagCompound)
1393
    {
1394
        super.writeEntityToNBT(tagCompound);
1395
        tagCompound.setBoolean("EatingHaystack", this.isEatingHaystack());
1396
        tagCompound.setBoolean("ChestedHorse", this.isChested());
1397
        tagCompound.setBoolean("HasReproduced", this.getHasReproduced());
1398
        tagCompound.setBoolean("Bred", this.isBreeding());
1399
        tagCompound.setInteger("Type", this.getHorseType());
1400
        tagCompound.setInteger("Variant", this.getHorseVariant());
1401
        tagCompound.setInteger("Temper", this.getTemper());
1402
        tagCompound.setBoolean("Tame", this.isTame());
1403
        tagCompound.setString("OwnerUUID", this.getOwnerId());
1404
1405
        if (this.isChested())
1406
        {
1407
            NBTTagList nbttaglist = new NBTTagList();
1408
1409
            for (int i = 2; i < this.horseChest.getSizeInventory(); ++i)
1410
            {
1411
                ItemStack itemstack = this.horseChest.getStackInSlot(i);
1412
1413
                if (itemstack != null)
1414
                {
1415
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
1416
                    nbttagcompound.setByte("Slot", (byte)i);
1417
                    itemstack.writeToNBT(nbttagcompound);
1418
                    nbttaglist.appendTag(nbttagcompound);
1419
                }
1420
            }
1421
1422
            tagCompound.setTag("Items", nbttaglist);
1423
        }
1424
1425
        if (this.horseChest.getStackInSlot(1) != null)
1426
        {
1427
            tagCompound.setTag("ArmorItem", this.horseChest.getStackInSlot(1).writeToNBT(new NBTTagCompound()));
1428
        }
1429
1430
        if (this.horseChest.getStackInSlot(0) != null)
1431
        {
1432
            tagCompound.setTag("SaddleItem", this.horseChest.getStackInSlot(0).writeToNBT(new NBTTagCompound()));
1433
        }
1434
    }
1435
1436
    /**
1437
     * (abstract) Protected helper method to read subclass entity data from NBT.
1438
     */
1439
    public void readEntityFromNBT(NBTTagCompound tagCompund)
1440
    {
1441
        super.readEntityFromNBT(tagCompund);
1442
        this.setEatingHaystack(tagCompund.getBoolean("EatingHaystack"));
1443
        this.setBreeding(tagCompund.getBoolean("Bred"));
1444
        this.setChested(tagCompund.getBoolean("ChestedHorse"));
1445
        this.setHasReproduced(tagCompund.getBoolean("HasReproduced"));
1446
        this.setHorseType(tagCompund.getInteger("Type"));
1447
        this.setHorseVariant(tagCompund.getInteger("Variant"));
1448
        this.setTemper(tagCompund.getInteger("Temper"));
1449
        this.setHorseTamed(tagCompund.getBoolean("Tame"));
1450
        String s = "";
1451
1452
        if (tagCompund.hasKey("OwnerUUID", 8))
1453
        {
1454
            s = tagCompund.getString("OwnerUUID");
1455
        }
1456
        else
1457
        {
1458
            String s1 = tagCompund.getString("Owner");
1459
            s = PreYggdrasilConverter.getStringUUIDFromName(s1);
1460
        }
1461
1462
        if (s.length() > 0)
1463
        {
1464
            this.setOwnerId(s);
1465
        }
1466
1467
        IAttributeInstance iattributeinstance = this.getAttributeMap().getAttributeInstanceByName("Speed");
1468
1469
        if (iattributeinstance != null)
1470
        {
1471
            this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(iattributeinstance.getBaseValue() * 0.25D);
1472
        }
1473
1474
        if (this.isChested())
1475
        {
1476
            NBTTagList nbttaglist = tagCompund.getTagList("Items", 10);
1477
            this.initHorseChest();
1478
1479
            for (int i = 0; i < nbttaglist.tagCount(); ++i)
1480
            {
1481
                NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
1482
                int j = nbttagcompound.getByte("Slot") & 255;
1483
1484
                if (j >= 2 && j < this.horseChest.getSizeInventory())
1485
                {
1486
                    this.horseChest.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound));
1487
                }
1488
            }
1489
        }
1490
1491
        if (tagCompund.hasKey("ArmorItem", 10))
1492
        {
1493
            ItemStack itemstack = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("ArmorItem"));
1494
1495
            if (itemstack != null && isArmorItem(itemstack.getItem()))
1496
            {
1497
                this.horseChest.setInventorySlotContents(1, itemstack);
1498
            }
1499
        }
1500
1501
        if (tagCompund.hasKey("SaddleItem", 10))
1502
        {
1503
            ItemStack itemstack1 = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("SaddleItem"));
1504
1505
            if (itemstack1 != null && itemstack1.getItem() == Items.saddle)
1506
            {
1507
                this.horseChest.setInventorySlotContents(0, itemstack1);
1508
            }
1509
        }
1510
        else if (tagCompund.getBoolean("Saddle"))
1511
        {
1512
            this.horseChest.setInventorySlotContents(0, new ItemStack(Items.saddle));
1513
        }
1514
1515
        this.updateHorseSlots();
1516
    }
1517
1518
    /**
1519
     * Returns true if the mob is currently able to mate with the specified mob.
1520
     */
1521
    public boolean canMateWith(EntityAnimal otherAnimal)
1522
    {
1523
        if (otherAnimal == this)
1524
        {
1525
            return false;
1526
        }
1527
        else if (otherAnimal.getClass() != this.getClass())
1528
        {
1529
            return false;
1530
        }
1531
        else
1532
        {
1533
            EntityHorse entityhorse = (EntityHorse)otherAnimal;
1534
1535
            if (this.canMate() && entityhorse.canMate())
1536
            {
1537
                int i = this.getHorseType();
1538
                int j = entityhorse.getHorseType();
1539
                return i == j || i == 0 && j == 1 || i == 1 && j == 0;
1540
            }
1541
            else
1542
            {
1543
                return false;
1544
            }
1545
        }
1546
    }
1547
1548
    public EntityAgeable createChild(EntityAgeable ageable)
1549
    {
1550
        EntityHorse entityhorse = (EntityHorse)ageable;
1551
        EntityHorse entityhorse1 = new EntityHorse(this.worldObj);
1552
        int i = this.getHorseType();
1553
        int j = entityhorse.getHorseType();
1554
        int k = 0;
1555
1556
        if (i == j)
1557
        {
1558
            k = i;
1559
        }
1560
        else if (i == 0 && j == 1 || i == 1 && j == 0)
1561
        {
1562
            k = 2;
1563
        }
1564
1565
        if (k == 0)
1566
        {
1567
            int i1 = this.rand.nextInt(9);
1568
            int l;
1569
1570
            if (i1 < 4)
1571
            {
1572
                l = this.getHorseVariant() & 255;
1573
            }
1574
            else if (i1 < 8)
1575
            {
1576
                l = entityhorse.getHorseVariant() & 255;
1577
            }
1578
            else
1579
            {
1580
                l = this.rand.nextInt(7);
1581
            }
1582
1583
            int j1 = this.rand.nextInt(5);
1584
1585
            if (j1 < 2)
1586
            {
1587
                l = l | this.getHorseVariant() & 65280;
1588
            }
1589
            else if (j1 < 4)
1590
            {
1591
                l = l | entityhorse.getHorseVariant() & 65280;
1592
            }
1593
            else
1594
            {
1595
                l = l | this.rand.nextInt(5) << 8 & 65280;
1596
            }
1597
1598
            entityhorse1.setHorseVariant(l);
1599
        }
1600
1601
        entityhorse1.setHorseType(k);
1602
        double d1 = this.getEntityAttribute(SharedMonsterAttributes.maxHealth).getBaseValue() + ageable.getEntityAttribute(SharedMonsterAttributes.maxHealth).getBaseValue() + (double)this.getModifiedMaxHealth();
1603
        entityhorse1.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(d1 / 3.0D);
1604
        double d2 = this.getEntityAttribute(horseJumpStrength).getBaseValue() + ageable.getEntityAttribute(horseJumpStrength).getBaseValue() + this.getModifiedJumpStrength();
1605
        entityhorse1.getEntityAttribute(horseJumpStrength).setBaseValue(d2 / 3.0D);
1606
        double d0 = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue() + ageable.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue() + this.getModifiedMovementSpeed();
1607
        entityhorse1.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(d0 / 3.0D);
1608
        return entityhorse1;
1609
    }
1610
1611
    /**
1612
     * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
1613
     * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
1614
     */
1615
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
1616
    {
1617
        livingdata = super.onInitialSpawn(difficulty, livingdata);
1618
        int i = 0;
1619
        int j = 0;
1620
1621
        if (livingdata instanceof EntityHorse.GroupData)
1622
        {
1623
            i = ((EntityHorse.GroupData)livingdata).horseType;
1624
            j = ((EntityHorse.GroupData)livingdata).horseVariant & 255 | this.rand.nextInt(5) << 8;
1625
        }
1626
        else
1627
        {
1628
            if (this.rand.nextInt(10) == 0)
1629
            {
1630
                i = 1;
1631
            }
1632
            else
1633
            {
1634
                int k = this.rand.nextInt(7);
1635
                int l = this.rand.nextInt(5);
1636
                i = 0;
1637
                j = k | l << 8;
1638
            }
1639
1640
            livingdata = new EntityHorse.GroupData(i, j);
1641
        }
1642
1643
        this.setHorseType(i);
1644
        this.setHorseVariant(j);
1645
1646
        if (this.rand.nextInt(5) == 0)
1647
        {
1648
            this.setGrowingAge(-24000);
1649
        }
1650
1651
        if (i != 4 && i != 3)
1652
        {
1653
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue((double)this.getModifiedMaxHealth());
1654
1655
            if (i == 0)
1656
            {
1657
                this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(this.getModifiedMovementSpeed());
1658
            }
1659
            else
1660
            {
1661
                this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.17499999701976776D);
1662
            }
1663
        }
1664
        else
1665
        {
1666
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(15.0D);
1667
            this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D);
1668
        }
1669
1670
        if (i != 2 && i != 1)
1671
        {
1672
            this.getEntityAttribute(horseJumpStrength).setBaseValue(this.getModifiedJumpStrength());
1673
        }
1674
        else
1675
        {
1676
            this.getEntityAttribute(horseJumpStrength).setBaseValue(0.5D);
1677
        }
1678
1679
        this.setHealth(this.getMaxHealth());
1680
        return livingdata;
1681
    }
1682
1683
    public float getGrassEatingAmount(float p_110258_1_)
1684
    {
1685
        return this.prevHeadLean + (this.headLean - this.prevHeadLean) * p_110258_1_;
1686
    }
1687
1688
    public float getRearingAmount(float p_110223_1_)
1689
    {
1690
        return this.prevRearingAmount + (this.rearingAmount - this.prevRearingAmount) * p_110223_1_;
1691
    }
1692
1693
    public float getMouthOpennessAngle(float p_110201_1_)
1694
    {
1695
        return this.prevMouthOpenness + (this.mouthOpenness - this.prevMouthOpenness) * p_110201_1_;
1696
    }
1697
1698
    public void setJumpPower(int jumpPowerIn)
1699
    {
1700
        if (this.isHorseSaddled())
1701
        {
1702
            if (jumpPowerIn < 0)
1703
            {
1704
                jumpPowerIn = 0;
1705
            }
1706
            else
1707
            {
1708
                this.field_110294_bI = true;
1709
                this.makeHorseRear();
1710
            }
1711
1712
            if (jumpPowerIn >= 90)
1713
            {
1714
                this.jumpPower = 1.0F;
1715
            }
1716
            else
1717
            {
1718
                this.jumpPower = 0.4F + 0.4F * (float)jumpPowerIn / 90.0F;
1719
            }
1720
        }
1721
    }
1722
1723
    /**
1724
     * "Spawns particles for the horse entity. par1 tells whether to spawn hearts. If it is false, it spawns smoke."
1725
     */
1726
    protected void spawnHorseParticles(boolean p_110216_1_)
1727
    {
1728
        EnumParticleTypes enumparticletypes = p_110216_1_ ? EnumParticleTypes.HEART : EnumParticleTypes.SMOKE_NORMAL;
1729
1730
        for (int i = 0; i < 7; ++i)
1731
        {
1732
            double d0 = this.rand.nextGaussian() * 0.02D;
1733
            double d1 = this.rand.nextGaussian() * 0.02D;
1734
            double d2 = this.rand.nextGaussian() * 0.02D;
1735
            this.worldObj.spawnParticle(enumparticletypes, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 0.5D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2, new int[0]);
1736
        }
1737
    }
1738
1739
    public void handleStatusUpdate(byte id)
1740
    {
1741
        if (id == 7)
1742
        {
1743
            this.spawnHorseParticles(true);
1744
        }
1745
        else if (id == 6)
1746
        {
1747
            this.spawnHorseParticles(false);
1748
        }
1749
        else
1750
        {
1751
            super.handleStatusUpdate(id);
1752
        }
1753
    }
1754
1755
    public void updateRiderPosition()
1756
    {
1757
        super.updateRiderPosition();
1758
1759
        if (this.prevRearingAmount > 0.0F)
1760
        {
1761
            float f = MathHelper.sin(this.renderYawOffset * (float)Math.PI / 180.0F);
1762
            float f1 = MathHelper.cos(this.renderYawOffset * (float)Math.PI / 180.0F);
1763
            float f2 = 0.7F * this.prevRearingAmount;
1764
            float f3 = 0.15F * this.prevRearingAmount;
1765
            this.riddenByEntity.setPosition(this.posX + (double)(f2 * f), this.posY + this.getMountedYOffset() + this.riddenByEntity.getYOffset() + (double)f3, this.posZ - (double)(f2 * f1));
1766
1767
            if (this.riddenByEntity instanceof EntityLivingBase)
1768
            {
1769
                ((EntityLivingBase)this.riddenByEntity).renderYawOffset = this.renderYawOffset;
1770
            }
1771
        }
1772
    }
1773
1774
    /**
1775
     * Returns randomized max health
1776
     */
1777
    private float getModifiedMaxHealth()
1778
    {
1779
        return 15.0F + (float)this.rand.nextInt(8) + (float)this.rand.nextInt(9);
1780
    }
1781
1782
    /**
1783
     * Returns randomized jump strength
1784
     */
1785
    private double getModifiedJumpStrength()
1786
    {
1787
        return 0.4000000059604645D + this.rand.nextDouble() * 0.2D + this.rand.nextDouble() * 0.2D + this.rand.nextDouble() * 0.2D;
1788
    }
1789
1790
    /**
1791
     * Returns randomized movement speed
1792
     */
1793
    private double getModifiedMovementSpeed()
1794
    {
1795
        return (0.44999998807907104D + this.rand.nextDouble() * 0.3D + this.rand.nextDouble() * 0.3D + this.rand.nextDouble() * 0.3D) * 0.25D;
1796
    }
1797
1798
    /**
1799
     * Returns true if given item is horse armor
1800
     */
1801
    public static boolean isArmorItem(Item p_146085_0_)
1802
    {
1803
        return p_146085_0_ == Items.iron_horse_armor || p_146085_0_ == Items.golden_horse_armor || p_146085_0_ == Items.diamond_horse_armor;
1804
    }
1805
1806
    /**
1807
     * returns true if this entity is by a ladder, false otherwise
1808
     */
1809
    public boolean isOnLadder()
1810
    {
1811
        return false;
1812
    }
1813
1814
    public float getEyeHeight()
1815
    {
1816
        return this.height;
1817
    }
1818
1819
    public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
1820
    {
1821
        if (inventorySlot == 499 && this.canCarryChest())
1822
        {
1823
            if (itemStackIn == null && this.isChested())
1824
            {
1825
                this.setChested(false);
1826
                this.initHorseChest();
1827
                return true;
1828
            }
1829
1830
            if (itemStackIn != null && itemStackIn.getItem() == Item.getItemFromBlock(Blocks.chest) && !this.isChested())
1831
            {
1832
                this.setChested(true);
1833
                this.initHorseChest();
1834
                return true;
1835
            }
1836
        }
1837
1838
        int i = inventorySlot - 400;
1839
1840
        if (i >= 0 && i < 2 && i < this.horseChest.getSizeInventory())
1841
        {
1842
            if (i == 0 && itemStackIn != null && itemStackIn.getItem() != Items.saddle)
1843
            {
1844
                return false;
1845
            }
1846
            else if (i != 1 || (itemStackIn == null || isArmorItem(itemStackIn.getItem())) && this.canWearArmor())
1847
            {
1848
                this.horseChest.setInventorySlotContents(i, itemStackIn);
1849
                this.updateHorseSlots();
1850
                return true;
1851
            }
1852
            else
1853
            {
1854
                return false;
1855
            }
1856
        }
1857
        else
1858
        {
1859
            int j = inventorySlot - 500 + 2;
1860
1861
            if (j >= 2 && j < this.horseChest.getSizeInventory())
1862
            {
1863
                this.horseChest.setInventorySlotContents(j, itemStackIn);
1864
                return true;
1865
            }
1866
            else
1867
            {
1868
                return false;
1869
            }
1870
        }
1871
    }
1872
1873
    public static class GroupData implements IEntityLivingData
1874
    {
1875
        public int horseType;
1876
        public int horseVariant;
1877
1878
        public GroupData(int type, int variant)
1879
        {
1880
            this.horseType = type;
1881
            this.horseVariant = variant;
1882
        }
1883
    }
1884
}
1885

Deobfuscated MCP 1.8.9 source of EntityHorse from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/passive/EntityHorse.java), stored verbatim.