| 1 | package net.minecraft.entity.passive;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.BlockCarrot;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 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.EntityAIAttackOnCollide;
|
| 12 | import net.minecraft.entity.ai.EntityAIAvoidEntity;
|
| 13 | import net.minecraft.entity.ai.EntityAIHurtByTarget;
|
| 14 | import net.minecraft.entity.ai.EntityAIMate;
|
| 15 | import net.minecraft.entity.ai.EntityAIMoveToBlock;
|
| 16 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 17 | import net.minecraft.entity.ai.EntityAIPanic;
|
| 18 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 19 | import net.minecraft.entity.ai.EntityAITempt;
|
| 20 | import net.minecraft.entity.ai.EntityAIWander;
|
| 21 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 22 | import net.minecraft.entity.ai.EntityJumpHelper;
|
| 23 | import net.minecraft.entity.ai.EntityMoveHelper;
|
| 24 | import net.minecraft.entity.player.EntityPlayer;
|
| 25 | import net.minecraft.init.Blocks;
|
| 26 | import net.minecraft.init.Items;
|
| 27 | import net.minecraft.item.Item;
|
| 28 | import net.minecraft.item.ItemStack;
|
| 29 | import net.minecraft.nbt.NBTTagCompound;
|
| 30 | import net.minecraft.pathfinding.PathEntity;
|
| 31 | import net.minecraft.pathfinding.PathNavigateGround;
|
| 32 | import net.minecraft.util.BlockPos;
|
| 33 | import net.minecraft.util.DamageSource;
|
| 34 | import net.minecraft.util.EnumParticleTypes;
|
| 35 | import net.minecraft.util.MathHelper;
|
| 36 | import net.minecraft.util.StatCollector;
|
| 37 | import net.minecraft.util.Vec3;
|
| 38 | import net.minecraft.world.DifficultyInstance;
|
| 39 | import net.minecraft.world.World;
|
| 40 |
|
| 41 | public class EntityRabbit extends EntityAnimal
|
| 42 | {
|
| 43 | private EntityRabbit.AIAvoidEntity<EntityWolf> aiAvoidWolves;
|
| 44 | private int field_175540_bm = 0;
|
| 45 | private int field_175535_bn = 0;
|
| 46 | private boolean field_175536_bo = false;
|
| 47 | private boolean field_175537_bp = false;
|
| 48 | private int currentMoveTypeDuration = 0;
|
| 49 | private EntityRabbit.EnumMoveType moveType = EntityRabbit.EnumMoveType.HOP;
|
| 50 | private int carrotTicks = 0;
|
| 51 | private EntityPlayer field_175543_bt = null;
|
| 52 |
|
| 53 | public EntityRabbit(World worldIn)
|
| 54 | {
|
| 55 | super(worldIn);
|
| 56 | this.setSize(0.6F, 0.7F);
|
| 57 | this.jumpHelper = new EntityRabbit.RabbitJumpHelper(this);
|
| 58 | this.moveHelper = new EntityRabbit.RabbitMoveHelper(this);
|
| 59 | ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
|
| 60 | this.navigator.setHeightRequirement(2.5F);
|
| 61 | this.tasks.addTask(1, new EntityAISwimming(this));
|
| 62 | this.tasks.addTask(1, new EntityRabbit.AIPanic(this, 1.33D));
|
| 63 | this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Items.carrot, false));
|
| 64 | this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Items.golden_carrot, false));
|
| 65 | this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Item.getItemFromBlock(Blocks.yellow_flower), false));
|
| 66 | this.tasks.addTask(3, new EntityAIMate(this, 0.8D));
|
| 67 | this.tasks.addTask(5, new EntityRabbit.AIRaidFarm(this));
|
| 68 | this.tasks.addTask(5, new EntityAIWander(this, 0.6D));
|
| 69 | this.tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
|
| 70 | this.aiAvoidWolves = new EntityRabbit.AIAvoidEntity(this, EntityWolf.class, 16.0F, 1.33D, 1.33D);
|
| 71 | this.tasks.addTask(4, this.aiAvoidWolves);
|
| 72 | this.setMovementSpeed(0.0D);
|
| 73 | }
|
| 74 |
|
| 75 | protected float getJumpUpwardsMotion()
|
| 76 | {
|
| 77 | return this.moveHelper.isUpdating() && this.moveHelper.getY() > this.posY + 0.5D ? 0.5F : this.moveType.func_180074_b();
|
| 78 | }
|
| 79 |
|
| 80 | public void setMoveType(EntityRabbit.EnumMoveType type)
|
| 81 | {
|
| 82 | this.moveType = type;
|
| 83 | }
|
| 84 |
|
| 85 | public float func_175521_o(float p_175521_1_)
|
| 86 | {
|
| 87 | return this.field_175535_bn == 0 ? 0.0F : ((float)this.field_175540_bm + p_175521_1_) / (float)this.field_175535_bn;
|
| 88 | }
|
| 89 |
|
| 90 | public void setMovementSpeed(double newSpeed)
|
| 91 | {
|
| 92 | this.getNavigator().setSpeed(newSpeed);
|
| 93 | this.moveHelper.setMoveTo(this.moveHelper.getX(), this.moveHelper.getY(), this.moveHelper.getZ(), newSpeed);
|
| 94 | }
|
| 95 |
|
| 96 | public void setJumping(boolean jump, EntityRabbit.EnumMoveType moveTypeIn)
|
| 97 | {
|
| 98 | super.setJumping(jump);
|
| 99 |
|
| 100 | if (!jump)
|
| 101 | {
|
| 102 | if (this.moveType == EntityRabbit.EnumMoveType.ATTACK)
|
| 103 | {
|
| 104 | this.moveType = EntityRabbit.EnumMoveType.HOP;
|
| 105 | }
|
| 106 | }
|
| 107 | else
|
| 108 | {
|
| 109 | this.setMovementSpeed(1.5D * (double)moveTypeIn.getSpeed());
|
| 110 | this.playSound(this.getJumpingSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F);
|
| 111 | }
|
| 112 |
|
| 113 | this.field_175536_bo = jump;
|
| 114 | }
|
| 115 |
|
| 116 | public void doMovementAction(EntityRabbit.EnumMoveType movetype)
|
| 117 | {
|
| 118 | this.setJumping(true, movetype);
|
| 119 | this.field_175535_bn = movetype.func_180073_d();
|
| 120 | this.field_175540_bm = 0;
|
| 121 | }
|
| 122 |
|
| 123 | public boolean func_175523_cj()
|
| 124 | {
|
| 125 | return this.field_175536_bo;
|
| 126 | }
|
| 127 |
|
| 128 | protected void entityInit()
|
| 129 | {
|
| 130 | super.entityInit();
|
| 131 | this.dataWatcher.addObject(18, Byte.valueOf((byte)0));
|
| 132 | }
|
| 133 |
|
| 134 | public void updateAITasks()
|
| 135 | {
|
| 136 | if (this.moveHelper.getSpeed() > 0.8D)
|
| 137 | {
|
| 138 | this.setMoveType(EntityRabbit.EnumMoveType.SPRINT);
|
| 139 | }
|
| 140 | else if (this.moveType != EntityRabbit.EnumMoveType.ATTACK)
|
| 141 | {
|
| 142 | this.setMoveType(EntityRabbit.EnumMoveType.HOP);
|
| 143 | }
|
| 144 |
|
| 145 | if (this.currentMoveTypeDuration > 0)
|
| 146 | {
|
| 147 | --this.currentMoveTypeDuration;
|
| 148 | }
|
| 149 |
|
| 150 | if (this.carrotTicks > 0)
|
| 151 | {
|
| 152 | this.carrotTicks -= this.rand.nextInt(3);
|
| 153 |
|
| 154 | if (this.carrotTicks < 0)
|
| 155 | {
|
| 156 | this.carrotTicks = 0;
|
| 157 | }
|
| 158 | }
|
| 159 |
|
| 160 | if (this.onGround)
|
| 161 | {
|
| 162 | if (!this.field_175537_bp)
|
| 163 | {
|
| 164 | this.setJumping(false, EntityRabbit.EnumMoveType.NONE);
|
| 165 | this.func_175517_cu();
|
| 166 | }
|
| 167 |
|
| 168 | if (this.getRabbitType() == 99 && this.currentMoveTypeDuration == 0)
|
| 169 | {
|
| 170 | EntityLivingBase entitylivingbase = this.getAttackTarget();
|
| 171 |
|
| 172 | if (entitylivingbase != null && this.getDistanceSqToEntity(entitylivingbase) < 16.0D)
|
| 173 | {
|
| 174 | this.calculateRotationYaw(entitylivingbase.posX, entitylivingbase.posZ);
|
| 175 | this.moveHelper.setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, this.moveHelper.getSpeed());
|
| 176 | this.doMovementAction(EntityRabbit.EnumMoveType.ATTACK);
|
| 177 | this.field_175537_bp = true;
|
| 178 | }
|
| 179 | }
|
| 180 |
|
| 181 | EntityRabbit.RabbitJumpHelper entityrabbit$rabbitjumphelper = (EntityRabbit.RabbitJumpHelper)this.jumpHelper;
|
| 182 |
|
| 183 | if (!entityrabbit$rabbitjumphelper.getIsJumping())
|
| 184 | {
|
| 185 | if (this.moveHelper.isUpdating() && this.currentMoveTypeDuration == 0)
|
| 186 | {
|
| 187 | PathEntity pathentity = this.navigator.getPath();
|
| 188 | Vec3 vec3 = new Vec3(this.moveHelper.getX(), this.moveHelper.getY(), this.moveHelper.getZ());
|
| 189 |
|
| 190 | if (pathentity != null && pathentity.getCurrentPathIndex() < pathentity.getCurrentPathLength())
|
| 191 | {
|
| 192 | vec3 = pathentity.getPosition(this);
|
| 193 | }
|
| 194 |
|
| 195 | this.calculateRotationYaw(vec3.xCoord, vec3.zCoord);
|
| 196 | this.doMovementAction(this.moveType);
|
| 197 | }
|
| 198 | }
|
| 199 | else if (!entityrabbit$rabbitjumphelper.func_180065_d())
|
| 200 | {
|
| 201 | this.func_175518_cr();
|
| 202 | }
|
| 203 | }
|
| 204 |
|
| 205 | this.field_175537_bp = this.onGround;
|
| 206 | }
|
| 207 |
|
| 208 | /**
|
| 209 | * Attempts to create sprinting particles if the entity is sprinting and not in water.
|
| 210 | */
|
| 211 | public void spawnRunningParticles()
|
| 212 | {
|
| 213 | }
|
| 214 |
|
| 215 | private void calculateRotationYaw(double x, double z)
|
| 216 | {
|
| 217 | this.rotationYaw = (float)(MathHelper.atan2(z - this.posZ, x - this.posX) * 180.0D / Math.PI) - 90.0F;
|
| 218 | }
|
| 219 |
|
| 220 | private void func_175518_cr()
|
| 221 | {
|
| 222 | ((EntityRabbit.RabbitJumpHelper)this.jumpHelper).func_180066_a(true);
|
| 223 | }
|
| 224 |
|
| 225 | private void func_175520_cs()
|
| 226 | {
|
| 227 | ((EntityRabbit.RabbitJumpHelper)this.jumpHelper).func_180066_a(false);
|
| 228 | }
|
| 229 |
|
| 230 | private void updateMoveTypeDuration()
|
| 231 | {
|
| 232 | this.currentMoveTypeDuration = this.getMoveTypeDuration();
|
| 233 | }
|
| 234 |
|
| 235 | private void func_175517_cu()
|
| 236 | {
|
| 237 | this.updateMoveTypeDuration();
|
| 238 | this.func_175520_cs();
|
| 239 | }
|
| 240 |
|
| 241 | /**
|
| 242 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 243 | * use this to react to sunlight and start to burn.
|
| 244 | */
|
| 245 | public void onLivingUpdate()
|
| 246 | {
|
| 247 | super.onLivingUpdate();
|
| 248 |
|
| 249 | if (this.field_175540_bm != this.field_175535_bn)
|
| 250 | {
|
| 251 | if (this.field_175540_bm == 0 && !this.worldObj.isRemote)
|
| 252 | {
|
| 253 | this.worldObj.setEntityState(this, (byte)1);
|
| 254 | }
|
| 255 |
|
| 256 | ++this.field_175540_bm;
|
| 257 | }
|
| 258 | else if (this.field_175535_bn != 0)
|
| 259 | {
|
| 260 | this.field_175540_bm = 0;
|
| 261 | this.field_175535_bn = 0;
|
| 262 | }
|
| 263 | }
|
| 264 |
|
| 265 | protected void applyEntityAttributes()
|
| 266 | {
|
| 267 | super.applyEntityAttributes();
|
| 268 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
|
| 269 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
|
| 270 | }
|
| 271 |
|
| 272 | /**
|
| 273 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 274 | */
|
| 275 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 276 | {
|
| 277 | super.writeEntityToNBT(tagCompound);
|
| 278 | tagCompound.setInteger("RabbitType", this.getRabbitType());
|
| 279 | tagCompound.setInteger("MoreCarrotTicks", this.carrotTicks);
|
| 280 | }
|
| 281 |
|
| 282 | /**
|
| 283 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 284 | */
|
| 285 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 286 | {
|
| 287 | super.readEntityFromNBT(tagCompund);
|
| 288 | this.setRabbitType(tagCompund.getInteger("RabbitType"));
|
| 289 | this.carrotTicks = tagCompund.getInteger("MoreCarrotTicks");
|
| 290 | }
|
| 291 |
|
| 292 | protected String getJumpingSound()
|
| 293 | {
|
| 294 | return "mob.rabbit.hop";
|
| 295 | }
|
| 296 |
|
| 297 | /**
|
| 298 | * Returns the sound this mob makes while it's alive.
|
| 299 | */
|
| 300 | protected String getLivingSound()
|
| 301 | {
|
| 302 | return "mob.rabbit.idle";
|
| 303 | }
|
| 304 |
|
| 305 | /**
|
| 306 | * Returns the sound this mob makes when it is hurt.
|
| 307 | */
|
| 308 | protected String getHurtSound()
|
| 309 | {
|
| 310 | return "mob.rabbit.hurt";
|
| 311 | }
|
| 312 |
|
| 313 | /**
|
| 314 | * Returns the sound this mob makes on death.
|
| 315 | */
|
| 316 | protected String getDeathSound()
|
| 317 | {
|
| 318 | return "mob.rabbit.death";
|
| 319 | }
|
| 320 |
|
| 321 | public boolean attackEntityAsMob(Entity entityIn)
|
| 322 | {
|
| 323 | if (this.getRabbitType() == 99)
|
| 324 | {
|
| 325 | this.playSound("mob.attack", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
|
| 326 | return entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), 8.0F);
|
| 327 | }
|
| 328 | else
|
| 329 | {
|
| 330 | return entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F);
|
| 331 | }
|
| 332 | }
|
| 333 |
|
| 334 | /**
|
| 335 | * Returns the current armor value as determined by a call to InventoryPlayer.getTotalArmorValue
|
| 336 | */
|
| 337 | public int getTotalArmorValue()
|
| 338 | {
|
| 339 | return this.getRabbitType() == 99 ? 8 : super.getTotalArmorValue();
|
| 340 | }
|
| 341 |
|
| 342 | /**
|
| 343 | * Called when the entity is attacked.
|
| 344 | */
|
| 345 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 346 | {
|
| 347 | return this.isEntityInvulnerable(source) ? false : super.attackEntityFrom(source, amount);
|
| 348 | }
|
| 349 |
|
| 350 | /**
|
| 351 | * Causes this Entity to drop a random item.
|
| 352 | */
|
| 353 | protected void addRandomDrop()
|
| 354 | {
|
| 355 | this.entityDropItem(new ItemStack(Items.rabbit_foot, 1), 0.0F);
|
| 356 | }
|
| 357 |
|
| 358 | /**
|
| 359 | * Drop 0-2 items of this living's type
|
| 360 | *
|
| 361 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 362 | * or tameable)
|
| 363 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 364 | */
|
| 365 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 366 | {
|
| 367 | int i = this.rand.nextInt(2) + this.rand.nextInt(1 + lootingModifier);
|
| 368 |
|
| 369 | for (int j = 0; j < i; ++j)
|
| 370 | {
|
| 371 | this.dropItem(Items.rabbit_hide, 1);
|
| 372 | }
|
| 373 |
|
| 374 | i = this.rand.nextInt(2);
|
| 375 |
|
| 376 | for (int k = 0; k < i; ++k)
|
| 377 | {
|
| 378 | if (this.isBurning())
|
| 379 | {
|
| 380 | this.dropItem(Items.cooked_rabbit, 1);
|
| 381 | }
|
| 382 | else
|
| 383 | {
|
| 384 | this.dropItem(Items.rabbit, 1);
|
| 385 | }
|
| 386 | }
|
| 387 | }
|
| 388 |
|
| 389 | private boolean isRabbitBreedingItem(Item itemIn)
|
| 390 | {
|
| 391 | return itemIn == Items.carrot || itemIn == Items.golden_carrot || itemIn == Item.getItemFromBlock(Blocks.yellow_flower);
|
| 392 | }
|
| 393 |
|
| 394 | public EntityRabbit createChild(EntityAgeable ageable)
|
| 395 | {
|
| 396 | EntityRabbit entityrabbit = new EntityRabbit(this.worldObj);
|
| 397 |
|
| 398 | if (ageable instanceof EntityRabbit)
|
| 399 | {
|
| 400 | entityrabbit.setRabbitType(this.rand.nextBoolean() ? this.getRabbitType() : ((EntityRabbit)ageable).getRabbitType());
|
| 401 | }
|
| 402 |
|
| 403 | return entityrabbit;
|
| 404 | }
|
| 405 |
|
| 406 | /**
|
| 407 | * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
|
| 408 | * the animal type)
|
| 409 | */
|
| 410 | public boolean isBreedingItem(ItemStack stack)
|
| 411 | {
|
| 412 | return stack != null && this.isRabbitBreedingItem(stack.getItem());
|
| 413 | }
|
| 414 |
|
| 415 | public int getRabbitType()
|
| 416 | {
|
| 417 | return this.dataWatcher.getWatchableObjectByte(18);
|
| 418 | }
|
| 419 |
|
| 420 | public void setRabbitType(int rabbitTypeId)
|
| 421 | {
|
| 422 | if (rabbitTypeId == 99)
|
| 423 | {
|
| 424 | this.tasks.removeTask(this.aiAvoidWolves);
|
| 425 | this.tasks.addTask(4, new EntityRabbit.AIEvilAttack(this));
|
| 426 | this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0]));
|
| 427 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
|
| 428 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityWolf.class, true));
|
| 429 |
|
| 430 | if (!this.hasCustomName())
|
| 431 | {
|
| 432 | this.setCustomNameTag(StatCollector.translateToLocal("entity.KillerBunny.name"));
|
| 433 | }
|
| 434 | }
|
| 435 |
|
| 436 | this.dataWatcher.updateObject(18, Byte.valueOf((byte)rabbitTypeId));
|
| 437 | }
|
| 438 |
|
| 439 | /**
|
| 440 | * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
|
| 441 | * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
|
| 442 | */
|
| 443 | public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
|
| 444 | {
|
| 445 | livingdata = super.onInitialSpawn(difficulty, livingdata);
|
| 446 | int i = this.rand.nextInt(6);
|
| 447 | boolean flag = false;
|
| 448 |
|
| 449 | if (livingdata instanceof EntityRabbit.RabbitTypeData)
|
| 450 | {
|
| 451 | i = ((EntityRabbit.RabbitTypeData)livingdata).typeData;
|
| 452 | flag = true;
|
| 453 | }
|
| 454 | else
|
| 455 | {
|
| 456 | livingdata = new EntityRabbit.RabbitTypeData(i);
|
| 457 | }
|
| 458 |
|
| 459 | this.setRabbitType(i);
|
| 460 |
|
| 461 | if (flag)
|
| 462 | {
|
| 463 | this.setGrowingAge(-24000);
|
| 464 | }
|
| 465 |
|
| 466 | return livingdata;
|
| 467 | }
|
| 468 |
|
| 469 | /**
|
| 470 | * Returns true if {@link net.minecraft.entity.passive.EntityRabbit#carrotTicks carrotTicks} has reached zero
|
| 471 | */
|
| 472 | private boolean isCarrotEaten()
|
| 473 | {
|
| 474 | return this.carrotTicks == 0;
|
| 475 | }
|
| 476 |
|
| 477 | /**
|
| 478 | * Returns duration of the current {@link net.minecraft.entity.passive.EntityRabbit.EnumMoveType move type}
|
| 479 | */
|
| 480 | protected int getMoveTypeDuration()
|
| 481 | {
|
| 482 | return this.moveType.getDuration();
|
| 483 | }
|
| 484 |
|
| 485 | protected void createEatingParticles()
|
| 486 | {
|
| 487 | this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_DUST, 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, 0.0D, 0.0D, 0.0D, new int[] {Block.getStateId(Blocks.carrots.getStateFromMeta(7))});
|
| 488 | this.carrotTicks = 100;
|
| 489 | }
|
| 490 |
|
| 491 | public void handleStatusUpdate(byte id)
|
| 492 | {
|
| 493 | if (id == 1)
|
| 494 | {
|
| 495 | this.createRunningParticles();
|
| 496 | this.field_175535_bn = 10;
|
| 497 | this.field_175540_bm = 0;
|
| 498 | }
|
| 499 | else
|
| 500 | {
|
| 501 | super.handleStatusUpdate(id);
|
| 502 | }
|
| 503 | }
|
| 504 |
|
| 505 | static class AIAvoidEntity<T extends Entity> extends EntityAIAvoidEntity<T>
|
| 506 | {
|
| 507 | private EntityRabbit entityInstance;
|
| 508 |
|
| 509 | public AIAvoidEntity(EntityRabbit rabbit, Class<T> p_i46403_2_, float p_i46403_3_, double p_i46403_4_, double p_i46403_6_)
|
| 510 | {
|
| 511 | super(rabbit, p_i46403_2_, p_i46403_3_, p_i46403_4_, p_i46403_6_);
|
| 512 | this.entityInstance = rabbit;
|
| 513 | }
|
| 514 |
|
| 515 | public void updateTask()
|
| 516 | {
|
| 517 | super.updateTask();
|
| 518 | }
|
| 519 | }
|
| 520 |
|
| 521 | static class AIEvilAttack extends EntityAIAttackOnCollide
|
| 522 | {
|
| 523 | public AIEvilAttack(EntityRabbit rabbit)
|
| 524 | {
|
| 525 | super(rabbit, EntityLivingBase.class, 1.4D, true);
|
| 526 | }
|
| 527 |
|
| 528 | protected double func_179512_a(EntityLivingBase attackTarget)
|
| 529 | {
|
| 530 | return (double)(4.0F + attackTarget.width);
|
| 531 | }
|
| 532 | }
|
| 533 |
|
| 534 | static class AIPanic extends EntityAIPanic
|
| 535 | {
|
| 536 | private EntityRabbit theEntity;
|
| 537 |
|
| 538 | public AIPanic(EntityRabbit rabbit, double speedIn)
|
| 539 | {
|
| 540 | super(rabbit, speedIn);
|
| 541 | this.theEntity = rabbit;
|
| 542 | }
|
| 543 |
|
| 544 | public void updateTask()
|
| 545 | {
|
| 546 | super.updateTask();
|
| 547 | this.theEntity.setMovementSpeed(this.speed);
|
| 548 | }
|
| 549 | }
|
| 550 |
|
| 551 | static class AIRaidFarm extends EntityAIMoveToBlock
|
| 552 | {
|
| 553 | private final EntityRabbit rabbit;
|
| 554 | private boolean field_179498_d;
|
| 555 | private boolean field_179499_e = false;
|
| 556 |
|
| 557 | public AIRaidFarm(EntityRabbit rabbitIn)
|
| 558 | {
|
| 559 | super(rabbitIn, 0.699999988079071D, 16);
|
| 560 | this.rabbit = rabbitIn;
|
| 561 | }
|
| 562 |
|
| 563 | public boolean shouldExecute()
|
| 564 | {
|
| 565 | if (this.runDelay <= 0)
|
| 566 | {
|
| 567 | if (!this.rabbit.worldObj.getGameRules().getBoolean("mobGriefing"))
|
| 568 | {
|
| 569 | return false;
|
| 570 | }
|
| 571 |
|
| 572 | this.field_179499_e = false;
|
| 573 | this.field_179498_d = this.rabbit.isCarrotEaten();
|
| 574 | }
|
| 575 |
|
| 576 | return super.shouldExecute();
|
| 577 | }
|
| 578 |
|
| 579 | public boolean continueExecuting()
|
| 580 | {
|
| 581 | return this.field_179499_e && super.continueExecuting();
|
| 582 | }
|
| 583 |
|
| 584 | public void startExecuting()
|
| 585 | {
|
| 586 | super.startExecuting();
|
| 587 | }
|
| 588 |
|
| 589 | public void resetTask()
|
| 590 | {
|
| 591 | super.resetTask();
|
| 592 | }
|
| 593 |
|
| 594 | public void updateTask()
|
| 595 | {
|
| 596 | super.updateTask();
|
| 597 | this.rabbit.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.rabbit.getVerticalFaceSpeed());
|
| 598 |
|
| 599 | if (this.getIsAboveDestination())
|
| 600 | {
|
| 601 | World world = this.rabbit.worldObj;
|
| 602 | BlockPos blockpos = this.destinationBlock.up();
|
| 603 | IBlockState iblockstate = world.getBlockState(blockpos);
|
| 604 | Block block = iblockstate.getBlock();
|
| 605 |
|
| 606 | if (this.field_179499_e && block instanceof BlockCarrot && ((Integer)iblockstate.getValue(BlockCarrot.AGE)).intValue() == 7)
|
| 607 | {
|
| 608 | world.setBlockState(blockpos, Blocks.air.getDefaultState(), 2);
|
| 609 | world.destroyBlock(blockpos, true);
|
| 610 | this.rabbit.createEatingParticles();
|
| 611 | }
|
| 612 |
|
| 613 | this.field_179499_e = false;
|
| 614 | this.runDelay = 10;
|
| 615 | }
|
| 616 | }
|
| 617 |
|
| 618 | protected boolean shouldMoveTo(World worldIn, BlockPos pos)
|
| 619 | {
|
| 620 | Block block = worldIn.getBlockState(pos).getBlock();
|
| 621 |
|
| 622 | if (block == Blocks.farmland)
|
| 623 | {
|
| 624 | pos = pos.up();
|
| 625 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 626 | block = iblockstate.getBlock();
|
| 627 |
|
| 628 | if (block instanceof BlockCarrot && ((Integer)iblockstate.getValue(BlockCarrot.AGE)).intValue() == 7 && this.field_179498_d && !this.field_179499_e)
|
| 629 | {
|
| 630 | this.field_179499_e = true;
|
| 631 | return true;
|
| 632 | }
|
| 633 | }
|
| 634 |
|
| 635 | return false;
|
| 636 | }
|
| 637 | }
|
| 638 |
|
| 639 | static enum EnumMoveType
|
| 640 | {
|
| 641 | NONE(0.0F, 0.0F, 30, 1),
|
| 642 | HOP(0.8F, 0.2F, 20, 10),
|
| 643 | STEP(1.0F, 0.45F, 14, 14),
|
| 644 | SPRINT(1.75F, 0.4F, 1, 8),
|
| 645 | ATTACK(2.0F, 0.7F, 7, 8);
|
| 646 |
|
| 647 | private final float speed;
|
| 648 | private final float field_180077_g;
|
| 649 | private final int duration;
|
| 650 | private final int field_180085_i;
|
| 651 |
|
| 652 | private EnumMoveType(float typeSpeed, float p_i45866_4_, int typeDuration, int p_i45866_6_)
|
| 653 | {
|
| 654 | this.speed = typeSpeed;
|
| 655 | this.field_180077_g = p_i45866_4_;
|
| 656 | this.duration = typeDuration;
|
| 657 | this.field_180085_i = p_i45866_6_;
|
| 658 | }
|
| 659 |
|
| 660 | public float getSpeed()
|
| 661 | {
|
| 662 | return this.speed;
|
| 663 | }
|
| 664 |
|
| 665 | public float func_180074_b()
|
| 666 | {
|
| 667 | return this.field_180077_g;
|
| 668 | }
|
| 669 |
|
| 670 | public int getDuration()
|
| 671 | {
|
| 672 | return this.duration;
|
| 673 | }
|
| 674 |
|
| 675 | public int func_180073_d()
|
| 676 | {
|
| 677 | return this.field_180085_i;
|
| 678 | }
|
| 679 | }
|
| 680 |
|
| 681 | public class RabbitJumpHelper extends EntityJumpHelper
|
| 682 | {
|
| 683 | private EntityRabbit theEntity;
|
| 684 | private boolean field_180068_d = false;
|
| 685 |
|
| 686 | public RabbitJumpHelper(EntityRabbit rabbit)
|
| 687 | {
|
| 688 | super(rabbit);
|
| 689 | this.theEntity = rabbit;
|
| 690 | }
|
| 691 |
|
| 692 | public boolean getIsJumping()
|
| 693 | {
|
| 694 | return this.isJumping;
|
| 695 | }
|
| 696 |
|
| 697 | public boolean func_180065_d()
|
| 698 | {
|
| 699 | return this.field_180068_d;
|
| 700 | }
|
| 701 |
|
| 702 | public void func_180066_a(boolean p_180066_1_)
|
| 703 | {
|
| 704 | this.field_180068_d = p_180066_1_;
|
| 705 | }
|
| 706 |
|
| 707 | public void doJump()
|
| 708 | {
|
| 709 | if (this.isJumping)
|
| 710 | {
|
| 711 | this.theEntity.doMovementAction(EntityRabbit.EnumMoveType.STEP);
|
| 712 | this.isJumping = false;
|
| 713 | }
|
| 714 | }
|
| 715 | }
|
| 716 |
|
| 717 | static class RabbitMoveHelper extends EntityMoveHelper
|
| 718 | {
|
| 719 | private EntityRabbit theEntity;
|
| 720 |
|
| 721 | public RabbitMoveHelper(EntityRabbit rabbit)
|
| 722 | {
|
| 723 | super(rabbit);
|
| 724 | this.theEntity = rabbit;
|
| 725 | }
|
| 726 |
|
| 727 | public void onUpdateMoveHelper()
|
| 728 | {
|
| 729 | if (this.theEntity.onGround && !this.theEntity.func_175523_cj())
|
| 730 | {
|
| 731 | this.theEntity.setMovementSpeed(0.0D);
|
| 732 | }
|
| 733 |
|
| 734 | super.onUpdateMoveHelper();
|
| 735 | }
|
| 736 | }
|
| 737 |
|
| 738 | public static class RabbitTypeData implements IEntityLivingData
|
| 739 | {
|
| 740 | public int typeData;
|
| 741 |
|
| 742 | public RabbitTypeData(int type)
|
| 743 | {
|
| 744 | this.typeData = type;
|
| 745 | }
|
| 746 | }
|
| 747 | }
|
| 748 |
|