Guest User

EntityRabbit.java

a guest
Jun 28th, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.57 KB | None | 0 0
  1. package uk.co.ijay.earlyfuture.entity;
  2.  
  3. import java.lang.reflect.Field;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockCarrot;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.EntityAgeable;
  9. import net.minecraft.entity.EntityLiving;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.IEntityLivingData;
  12. import net.minecraft.entity.SharedMonsterAttributes;
  13. import net.minecraft.entity.ai.EntityAIAttackOnCollide;
  14. import net.minecraft.entity.ai.EntityAIAvoidEntity;
  15. import net.minecraft.entity.ai.EntityAIHurtByTarget;
  16. import net.minecraft.entity.ai.EntityAIMate;
  17. import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
  18. import net.minecraft.entity.ai.EntityAIPanic;
  19. import net.minecraft.entity.ai.EntityAISwimming;
  20. import net.minecraft.entity.ai.EntityAITempt;
  21. import net.minecraft.entity.ai.EntityAIWander;
  22. import net.minecraft.entity.ai.EntityAIWatchClosest;
  23. import net.minecraft.entity.ai.EntityJumpHelper;
  24. import net.minecraft.entity.ai.EntityMoveHelper;
  25. import net.minecraft.entity.passive.EntityAnimal;
  26. import net.minecraft.entity.passive.EntityWolf;
  27. import net.minecraft.entity.player.EntityPlayer;
  28. import net.minecraft.init.Blocks;
  29. import net.minecraft.init.Items;
  30. import net.minecraft.item.Item;
  31. import net.minecraft.item.ItemStack;
  32. import net.minecraft.nbt.NBTTagCompound;
  33. import net.minecraft.pathfinding.PathEntity;
  34. import net.minecraft.potion.Potion;
  35. import net.minecraft.util.DamageSource;
  36. import net.minecraft.util.MathHelper;
  37. import net.minecraft.util.StatCollector;
  38. import net.minecraft.util.Vec3;
  39. import net.minecraft.world.World;
  40. import net.minecraftforge.common.ForgeHooks;
  41. import uk.co.ijay.earlyfuture.EarlyFuture;
  42. import uk.co.ijay.earlyfuture.ObfMemberException;
  43. import uk.co.ijay.earlyfuture.entity.ai.EntityAIMoveToBlock;
  44. import uk.co.ijay.earlyfuture.init.EarlyFutureItems;
  45.  
  46. import com.google.common.base.Predicate;
  47.  
  48. import cpw.mods.fml.relauncher.Side;
  49. import cpw.mods.fml.relauncher.SideOnly;
  50.  
  51. public class EntityRabbit extends EntityAnimal
  52. {
  53.     private EntityRabbit.AIAvoidEntity  avoidEntityAI;
  54.     private int                         field_175540_bm = 0;
  55.     private int                         field_175535_bn = 0;
  56.     private boolean                     isJumping       = false;
  57.     private boolean                     field_175537_bp = false;
  58.     private int                         field_175538_bq = 0;
  59.     private EntityRabbit.EnumMoveType   moveType;
  60.     private int                         carrotTicks;
  61.     private EntityPlayer                uselessPlayer;
  62.     private static final String         __OBFID         = "CL_00002242";
  63.    
  64.     private static Field                jumpHelperField;
  65.     private static Field                moveHelperField;
  66.     private static Field                moveHelperPosXField;
  67.     private static Field                moveHelperPosYField;
  68.     private static Field                moveHelperPosZField;
  69.     private static Field                entityAIPanicSpeedField;
  70.     private static Field                entityJumpHelperIsJumpingField;
  71.    
  72.     static
  73.     {
  74.         try
  75.         {
  76.             jumpHelperField = EntityLiving.class.getDeclaredField("field_70767_i");
  77.             moveHelperField = EntityLiving.class.getDeclaredField("field_70765_h");
  78.             moveHelperPosXField = EntityMoveHelper.class.getDeclaredField("field_75646_b");
  79.             moveHelperPosYField = EntityMoveHelper.class.getDeclaredField("field_75647_c");
  80.             moveHelperPosZField = EntityMoveHelper.class.getDeclaredField("field_75644_d");
  81.             entityAIPanicSpeedField = EntityAIPanic.class.getDeclaredField("field_75265_b");
  82.             entityJumpHelperIsJumpingField = EntityJumpHelper.class.getDeclaredField("field_75662_b");
  83.         }
  84.         catch (Exception e)
  85.         {
  86.             try
  87.             {
  88.                 jumpHelperField = EntityLiving.class.getDeclaredField("jumpHelper");
  89.                 moveHelperField = EntityLiving.class.getDeclaredField("moveHelper");
  90.                 moveHelperPosXField = EntityMoveHelper.class.getDeclaredField("posX");
  91.                 moveHelperPosYField = EntityMoveHelper.class.getDeclaredField("posY");
  92.                 moveHelperPosZField = EntityMoveHelper.class.getDeclaredField("posZ");
  93.                 entityAIPanicSpeedField = EntityAIPanic.class.getDeclaredField("speed");
  94.                 entityJumpHelperIsJumpingField = EntityJumpHelper.class.getDeclaredField("isJumping");
  95.             }
  96.             catch (Exception e1)
  97.             {
  98.                 throw new ObfMemberException(e, e1);
  99.             }
  100.         }
  101.         jumpHelperField.setAccessible(true);
  102.         moveHelperField.setAccessible(true);
  103.         moveHelperPosXField.setAccessible(true);
  104.         moveHelperPosYField.setAccessible(true);
  105.         moveHelperPosZField.setAccessible(true);
  106.         entityAIPanicSpeedField.setAccessible(true);
  107.         entityJumpHelperIsJumpingField.setAccessible(true);
  108.     }
  109.    
  110.     public EntityRabbit(World worldIn)
  111.     {
  112.         super(worldIn);
  113.         this.moveType = EntityRabbit.EnumMoveType.HOP;
  114.         this.carrotTicks = 0;
  115.         this.uselessPlayer = null;
  116.         this.setSize(0.6F, 0.7F);
  117.         try
  118.         {
  119.             jumpHelperField.set(this, new EntityRabbit.RabbitJumpHelper(this));
  120.             moveHelperField.set(this, new EntityRabbit.RabbitMoveHelper());
  121.         }
  122.         catch (Exception e)
  123.         {
  124.             throw new RuntimeException(e);
  125.         }
  126.         //((PathNavigateGround)this.getNavigator()).func_179690_a(true);
  127.         //      \/  \/
  128.         getNavigator().setAvoidsWater(true);
  129.         //this.getNavigator().func_179678_a(2.5F);
  130.         this.tasks.addTask(1, new EntityAISwimming(this));
  131.         this.tasks.addTask(1, new EntityRabbit.AIPanic(1.33D));
  132.         this.tasks.addTask(2, new EntityAITempt(this, 1.0D, Items.carrot, false));
  133.         this.tasks.addTask(3, new EntityAIMate(this, 0.8D));
  134.         this.tasks.addTask(5, new EntityRabbit.AIRaidFarm());
  135.         this.tasks.addTask(5, new EntityAIWander(this, 0.6D));
  136.         this.tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
  137.         this.avoidEntityAI = new EntityRabbit.AIAvoidEntity(new Predicate() {
  138.             private static final String __OBFID = "CL_00002241";
  139.            
  140.             public boolean apply(Entity p_180086_1_)
  141.             {
  142.                 return p_180086_1_ instanceof EntityWolf;
  143.             }
  144.            
  145.             @Override
  146.             public boolean apply(Object p_apply_1_)
  147.             {
  148.                 return this.apply((Entity) p_apply_1_);
  149.             }
  150.         }, 16.0F, 1.33D, 1.33D);
  151.         this.tasks.addTask(4, this.avoidEntityAI);
  152.         this.setSpeed(0.0D);
  153.     }
  154.    
  155.     @Override
  156.     public boolean isAIEnabled()
  157.     {
  158.         return true;
  159.     }
  160.    
  161.     public float getJumpHeight()
  162.     {
  163.         try
  164.         {
  165.             return ((EntityMoveHelper) moveHelperField.get(this)).isUpdating()
  166.                 && ((Double) moveHelperPosYField.get((EntityMoveHelper) moveHelperField.get(this))) > this.posY + 0.5D ? 0.5F
  167.                 : this.moveType.getJumpHeight();
  168.         }
  169.         catch (Exception e)
  170.         {
  171.             throw new RuntimeException(e);
  172.         }
  173.     }
  174.    
  175.     @Override
  176.     public void jump()
  177.     {
  178.         this.motionY = (double) this.getJumpHeight();
  179.        
  180.         if(this.isPotionActive(Potion.jump))
  181.         {
  182.             this.motionY += (double) ((float) (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
  183.         }
  184.        
  185.         if(this.isSprinting())
  186.         {
  187.             float f = this.rotationYaw * 0.017453292F;
  188.             this.motionX -= (double) (MathHelper.sin(f) * 0.2F);
  189.             this.motionZ += (double) (MathHelper.cos(f) * 0.2F);
  190.         }
  191.        
  192.         this.isAirBorne = true;
  193.         ForgeHooks.onLivingJump(this);
  194.     }
  195.    
  196.     public void setMoveType(EntityRabbit.EnumMoveType moveType)
  197.     {
  198.         this.moveType = moveType;
  199.     }
  200.    
  201.     @SideOnly(Side.CLIENT)
  202.     public float func_175521_o(float p_175521_1_)
  203.     {
  204.         return this.field_175535_bn == 0 ? 0.0F : ((float) this.field_175540_bm + p_175521_1_)
  205.             / (float) this.field_175535_bn;
  206.     }
  207.    
  208.     public void setSpeed(double speed)
  209.     {
  210.         this.getNavigator().setSpeed(speed);
  211.         try
  212.         {
  213.             ((EntityMoveHelper) moveHelperField.get(this)).setMoveTo(
  214.                 (Double) moveHelperPosXField.get((EntityMoveHelper) moveHelperField.get(this)),
  215.                 (Double) moveHelperPosYField.get((EntityMoveHelper) moveHelperField.get(this)),
  216.                 (Double) moveHelperPosZField.get((EntityMoveHelper) moveHelperField.get(this)), speed);
  217.         }
  218.         catch (Exception e)
  219.         {
  220.             throw new RuntimeException(e);
  221.         }
  222.     }
  223.    
  224.     public void applyMoveType(boolean jumping, EntityRabbit.EnumMoveType moveType)
  225.     {
  226.         super.setJumping(jumping);
  227.        
  228.         if(!jumping)
  229.         {
  230.             if(this.moveType == EntityRabbit.EnumMoveType.ATTACK)
  231.             {
  232.                 this.moveType = EntityRabbit.EnumMoveType.HOP;
  233.             }
  234.         }
  235.         else
  236.         {
  237.             this.setSpeed(1.5D * (double) moveType.getSpeedMultiplier());
  238.             this.playSound(this.getHoppingSound(), this.getSoundVolume(),
  239.                 ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F);
  240.         }
  241.        
  242.         this.isJumping = jumping;
  243.     }
  244.    
  245.     public void applyMoveType(EntityRabbit.EnumMoveType moveType)
  246.     {
  247.         this.applyMoveType(true, moveType);
  248.         this.field_175535_bn = moveType.func_180073_d();
  249.         this.field_175540_bm = 0;
  250.     }
  251.    
  252.     public boolean getJumping()
  253.     {
  254.         return this.isJumping;
  255.     }
  256.    
  257.     @Override
  258.     protected void entityInit()
  259.     {
  260.         super.entityInit();
  261.         this.dataWatcher.addObject(18, Byte.valueOf((byte) 0));
  262.     }
  263.    
  264.     @Override
  265.     public void updateAITasks()
  266.     {
  267.         try
  268.         {
  269.             if(((EntityMoveHelper) moveHelperField.get(this)).getSpeed() > 0.8D)
  270.             {
  271.                 this.setMoveType(EntityRabbit.EnumMoveType.SPRINT);
  272.             }
  273.             else if(this.moveType != EntityRabbit.EnumMoveType.ATTACK)
  274.             {
  275.                 this.setMoveType(EntityRabbit.EnumMoveType.HOP);
  276.             }
  277.            
  278.             if(this.field_175538_bq > 0)
  279.             {
  280.                 --this.field_175538_bq;
  281.             }
  282.            
  283.             if(this.carrotTicks > 0)
  284.             {
  285.                 this.carrotTicks -= this.rand.nextInt(3);
  286.                
  287.                 if(this.carrotTicks < 0)
  288.                 {
  289.                     this.carrotTicks = 0;
  290.                 }
  291.             }
  292.            
  293.             if(this.onGround)
  294.             {
  295.                 if(!this.field_175537_bp)
  296.                 {
  297.                     this.applyMoveType(false, EntityRabbit.EnumMoveType.NONE);
  298.                     this.func_175517_cu();
  299.                 }
  300.                
  301.                 if(this.getRabbitType() == 99 && this.field_175538_bq == 0)
  302.                 {
  303.                     EntityLivingBase entitylivingbase = this.getAttackTarget();
  304.                    
  305.                     if(entitylivingbase != null && this.getDistanceSqToEntity(entitylivingbase) < 16.0D)
  306.                     {
  307.                         this.faceXAndZ(entitylivingbase.posX, entitylivingbase.posZ);
  308.                         ((EntityMoveHelper) moveHelperField.get(this)).setMoveTo(entitylivingbase.posX,
  309.                             entitylivingbase.posY, entitylivingbase.posZ,
  310.                             ((EntityMoveHelper) moveHelperField.get(this)).getSpeed());
  311.                         this.applyMoveType(EntityRabbit.EnumMoveType.ATTACK);
  312.                         this.field_175537_bp = true;
  313.                     }
  314.                 }
  315.                
  316.                 EntityRabbit.RabbitJumpHelper rabbitjumphelper = (EntityRabbit.RabbitJumpHelper) jumpHelperField
  317.                     .get(this);
  318.                
  319.                 if(!rabbitjumphelper.getJumping())
  320.                 {
  321.                     if(((EntityMoveHelper) moveHelperField.get(this)).isUpdating() && this.field_175538_bq == 0)
  322.                     {
  323.                         PathEntity pathentity = this.getNavigator().getPath();
  324.                         Vec3 vec3 = Vec3.createVectorHelper(
  325.                             (Double) moveHelperPosXField.get((EntityMoveHelper) moveHelperField.get(this)),
  326.                             (Double) moveHelperPosYField.get((EntityMoveHelper) moveHelperField.get(this)),
  327.                             (Double) moveHelperPosZField.get((EntityMoveHelper) moveHelperField.get(this)));
  328.                        
  329.                         if(pathentity != null && pathentity.getCurrentPathIndex() < pathentity.getCurrentPathLength())
  330.                         {
  331.                             vec3 = pathentity.getPosition(this);
  332.                         }
  333.                        
  334.                         this.faceXAndZ(vec3.xCoord, vec3.zCoord);
  335.                         this.applyMoveType(this.moveType);
  336.                     }
  337.                 }
  338.                 else if(!rabbitjumphelper.func_180065_d())
  339.                 {
  340.                     this.func_175518_cr();
  341.                 }
  342.             }
  343.            
  344.             this.field_175537_bp = this.onGround;
  345.         }
  346.         catch (Exception e)
  347.         {
  348.             throw new RuntimeException(e);
  349.         }
  350.     }
  351.    
  352.     /** Unfortunately there doesn't seem to be a way to stop the rabbit from spawning running particles. Dead code, but
  353.      * left in to remind us that's it's still a minor issue */
  354.     public void spawnRunningParticles()
  355.     {
  356.     }
  357.    
  358.     private void faceXAndZ(double x, double z)
  359.     {
  360.         this.rotationYaw = (float) (Math.atan2(z - this.posZ, x - this.posX) * 180.0D / Math.PI) - 90.0F;
  361.     }
  362.    
  363.     private void func_175518_cr()
  364.     {
  365.         try
  366.         {
  367.             ((EntityRabbit.RabbitJumpHelper) jumpHelperField.get(this)).func_180066_a(true);
  368.         }
  369.         catch (Exception e)
  370.         {
  371.             throw new RuntimeException(e);
  372.         }
  373.     }
  374.    
  375.     private void func_175520_cs()
  376.     {
  377.         try
  378.         {
  379.             ((EntityRabbit.RabbitJumpHelper) jumpHelperField.get(this)).func_180066_a(false);
  380.         }
  381.         catch (Exception e)
  382.         {
  383.             throw new RuntimeException(e);
  384.         }
  385.     }
  386.    
  387.     private void func_175530_ct()
  388.     {
  389.         this.field_175538_bq = this.func_175532_cm();
  390.     }
  391.    
  392.     private void func_175517_cu()
  393.     {
  394.         this.func_175530_ct();
  395.         this.func_175520_cs();
  396.     }
  397.    
  398.     @Override
  399.     public void onLivingUpdate()
  400.     {
  401.         super.onLivingUpdate();
  402.        
  403.         if(this.field_175540_bm != this.field_175535_bn)
  404.         {
  405.             if(this.field_175540_bm == 0 && !this.worldObj.isRemote)
  406.             {
  407.                 this.worldObj.setEntityState(this, (byte) 1);
  408.             }
  409.            
  410.             ++this.field_175540_bm;
  411.         }
  412.         else if(this.field_175535_bn != 0)
  413.         {
  414.             this.field_175540_bm = 0;
  415.             this.field_175535_bn = 0;
  416.         }
  417.     }
  418.    
  419.     @Override
  420.     protected void applyEntityAttributes()
  421.     {
  422.         super.applyEntityAttributes();
  423.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
  424.         this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
  425.     }
  426.    
  427.     @Override
  428.     public void writeEntityToNBT(NBTTagCompound tagCompound)
  429.     {
  430.         super.writeEntityToNBT(tagCompound);
  431.         tagCompound.setInteger("RabbitType", this.getRabbitType());
  432.         tagCompound.setInteger("MoreCarrotTicks", this.carrotTicks);
  433.     }
  434.    
  435.     @Override
  436.     public void readEntityFromNBT(NBTTagCompound tagCompund)
  437.     {
  438.         super.readEntityFromNBT(tagCompund);
  439.         this.setRabbitType(tagCompund.getInteger("RabbitType"));
  440.         this.carrotTicks = tagCompund.getInteger("MoreCarrotTicks");
  441.     }
  442.    
  443.     protected String getHoppingSound()
  444.     {
  445.         return EarlyFuture.ID + ":mob.rabbit.hop";
  446.     }
  447.    
  448.     @Override
  449.     protected String getLivingSound()
  450.     {
  451.         return EarlyFuture.ID + ":mob.rabbit.idle";
  452.     }
  453.    
  454.     @Override
  455.     protected String getHurtSound()
  456.     {
  457.         return EarlyFuture.ID + ":mob.rabbit.hurt";
  458.     }
  459.    
  460.     @Override
  461.     protected String getDeathSound()
  462.     {
  463.         return EarlyFuture.ID + ":mob.rabbit.death";
  464.     }
  465.    
  466.     @Override
  467.     public boolean attackEntityAsMob(Entity p_70652_1_)
  468.     {
  469.         if(this.getRabbitType() == 99)
  470.         {
  471.             this.playSound("mob.attack", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
  472.             return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), 8.0F);
  473.         }
  474.         else
  475.         {
  476.             return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F);
  477.         }
  478.     }
  479.    
  480.     @Override
  481.     public int getTotalArmorValue()
  482.     {
  483.         return this.getRabbitType() == 99 ? 8 : super.getTotalArmorValue();
  484.     }
  485.    
  486.     @Override
  487.     public boolean attackEntityFrom(DamageSource source, float amount)
  488.     {
  489.         return this.isEntityInvulnerable() ? false : super.attackEntityFrom(source, amount);
  490.     }
  491.    
  492.     @Override
  493.     protected void addRandomArmor()
  494.     {
  495.         this.entityDropItem(new ItemStack(EarlyFutureItems.rabbit_foot, 1), 0.0F);
  496.     }
  497.    
  498.     @Override
  499.     protected void dropFewItems(boolean hitByPlayer, int looting)
  500.     {
  501.         int j = this.rand.nextInt(2) + this.rand.nextInt(1 + looting);
  502.         int k;
  503.        
  504.         for(k = 0; k < j; ++k)
  505.         {
  506.             this.dropItem(EarlyFutureItems.rabbit_hide, 1);
  507.         }
  508.        
  509.         j = this.rand.nextInt(2);
  510.        
  511.         for(k = 0; k < j; ++k)
  512.         {
  513.             if(this.isBurning())
  514.             {
  515.                 this.dropItem(EarlyFutureItems.cooked_rabbit, 1);
  516.             }
  517.             else
  518.             {
  519.                 this.dropItem(EarlyFutureItems.raw_rabbit, 1);
  520.             }
  521.         }
  522.     }
  523.    
  524.     private boolean isAttractedTo(Item item)
  525.     {
  526.         return item == Items.carrot || item == Items.golden_carrot
  527.             || item == Item.getItemFromBlock(Blocks.yellow_flower);
  528.     }
  529.    
  530.     public EntityRabbit getChild(EntityAgeable p_175526_1_)
  531.     {
  532.         EntityRabbit entityrabbit = new EntityRabbit(this.worldObj);
  533.        
  534.         if(p_175526_1_ instanceof EntityRabbit)
  535.         {
  536.             entityrabbit.setRabbitType(this.rand.nextBoolean() ? this.getRabbitType() : ((EntityRabbit) p_175526_1_)
  537.                 .getRabbitType());
  538.         }
  539.        
  540.         return entityrabbit;
  541.     }
  542.    
  543.     @Override
  544.     public boolean isBreedingItem(ItemStack stack)
  545.     {
  546.         return stack != null && this.isAttractedTo(stack.getItem());
  547.     }
  548.    
  549.     public int getRabbitType()
  550.     {
  551.         return this.dataWatcher.getWatchableObjectByte(18);
  552.     }
  553.    
  554.     public void setRabbitType(int rabbitTypeId)
  555.     {
  556.         if(rabbitTypeId == 99)
  557.         {
  558.             this.tasks.removeTask(this.avoidEntityAI);
  559.             this.tasks.addTask(4, new EntityRabbit.AIEvilAttack());
  560.             this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
  561.             this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 10, true));
  562.             this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityWolf.class, 10, true));
  563.            
  564.             if(!this.hasCustomNameTag())
  565.             {
  566.                 this.setCustomNameTag(StatCollector.translateToLocal("entity.KillerBunny.name"));
  567.             }
  568.         }
  569.        
  570.         this.dataWatcher.updateObject(18, Byte.valueOf((byte) rabbitTypeId));
  571.     }
  572.    
  573.     @Override
  574.     public IEntityLivingData onSpawnWithEgg(IEntityLivingData livingData)
  575.     {
  576.         Object liningDataObject = livingData;
  577.         int type = this.rand.nextInt(6);
  578.         boolean isRabbitTypeData = false;
  579.        
  580.         if(liningDataObject instanceof EntityRabbit.RabbitTypeData)
  581.         {
  582.             type = ((EntityRabbit.RabbitTypeData) liningDataObject).rabbitType;
  583.             isRabbitTypeData = true;
  584.         }
  585.         else
  586.         {
  587.             liningDataObject = new EntityRabbit.RabbitTypeData(type);
  588.         }
  589.        
  590.         this.setRabbitType(type);
  591.        
  592.         if(isRabbitTypeData)
  593.         {
  594.             this.setGrowingAge(-24000);
  595.         }
  596.        
  597.         return (IEntityLivingData) liningDataObject;
  598.     }
  599.    
  600.     private boolean func_175534_cv()
  601.     {
  602.         return this.carrotTicks == 0;
  603.     }
  604.    
  605.     protected int func_175532_cm()
  606.     {
  607.         return this.moveType.func_180075_c();
  608.     }
  609.    
  610.     protected void func_175528_cn()
  611.     {
  612.         this.worldObj.spawnParticle("blockdust_28813", this.posX + (double) (this.rand.nextFloat() * this.width * 2.0F)
  613.             - (double) this.width, this.posY + 0.5D + (double) (this.rand.nextFloat() * this.height), this.posZ
  614.             + (double) (this.rand.nextFloat() * this.width * 2.0F) - (double) this.width, 0.0D, 0.0D, 0.0D);
  615.         this.carrotTicks = 100;
  616.     }
  617.    
  618.     @Override
  619.     @SideOnly(Side.CLIENT)
  620.     public void handleHealthUpdate(byte p_70103_1_)
  621.     {
  622.         if(p_70103_1_ == 1)
  623.         {
  624.             this.spawnRunningParticles();
  625.             this.field_175535_bn = 10;
  626.             this.field_175540_bm = 0;
  627.         }
  628.         else
  629.         {
  630.             super.handleHealthUpdate(p_70103_1_);
  631.         }
  632.     }
  633.    
  634.     @Override
  635.     public EntityAgeable createChild(EntityAgeable ageable)
  636.     {
  637.         return this.getChild(ageable);
  638.     }
  639.    
  640.     class AIAvoidEntity extends EntityAIAvoidEntity
  641.     {
  642.         private EntityRabbit        entityInstance  = EntityRabbit.this;
  643.         private static final String __OBFID         = "CL_00002238";
  644.        
  645.         public AIAvoidEntity(Predicate avoidPredicate, float p_i45865_3_, double p_i45865_4_, double p_i45865_6_)
  646.         {
  647.             super(EntityRabbit.this, EntityRabbit.class, p_i45865_3_, p_i45865_4_, p_i45865_6_);
  648.         }
  649.        
  650.         @Override
  651.         public void updateTask()
  652.         {
  653.             super.updateTask();
  654.         }
  655.     }
  656.    
  657.     class AIEvilAttack extends EntityAIAttackOnCollide
  658.     {
  659.         private static final String __OBFID = "CL_00002240";
  660.        
  661.         public AIEvilAttack()
  662.         {
  663.             super(EntityRabbit.this, EntityLivingBase.class, 1.4D, true);
  664.         }
  665.        
  666.         /** Unfortunately cannot modify this
  667.          * @param p_179512_1_
  668.          * @return */
  669.         protected double func_179512_a(EntityLivingBase p_179512_1_)
  670.         {
  671.             return (double) (4.0F + p_179512_1_.width);
  672.         }
  673.     }
  674.    
  675.     class AIPanic extends EntityAIPanic
  676.     {
  677.         private EntityRabbit        field_179486_b  = EntityRabbit.this;
  678.         private static final String __OBFID         = "CL_00002234";
  679.        
  680.         public AIPanic(double p_i45861_2_)
  681.         {
  682.             super(EntityRabbit.this, p_i45861_2_);
  683.         }
  684.        
  685.         @Override
  686.         public void updateTask()
  687.         {
  688.             super.updateTask();
  689.             try
  690.             {
  691.                 this.field_179486_b.setSpeed((Double) entityAIPanicSpeedField.get(this));
  692.             }
  693.             catch (Exception e)
  694.             {
  695.                 throw new RuntimeException(e);
  696.             }
  697.         }
  698.     }
  699.    
  700.     static enum EnumMoveType
  701.     {
  702.         NONE(0.0F, 0.0F, 30, 1), HOP(0.8F, 0.2F, 20, 10), STEP(1.0F, 0.45F, 14, 14), SPRINT(1.75F, 0.4F, 1, 8), ATTACK(
  703.             2.0F, 0.7F, 7, 8);
  704.         private final float         speedMultiplier;
  705.         private final float         jumpHeight;
  706.         private final int           field_180084_h;
  707.         private final int           field_180085_i;
  708.        
  709.         private static final String __OBFID = "CL_00002239";
  710.        
  711.         private EnumMoveType(float speedMultiplier, float jumpHeight, int p_i45866_5_, int p_i45866_6_)
  712.         {
  713.             this.speedMultiplier = speedMultiplier;
  714.             this.jumpHeight = jumpHeight;
  715.             this.field_180084_h = p_i45866_5_;
  716.             this.field_180085_i = p_i45866_6_;
  717.         }
  718.        
  719.         public float getSpeedMultiplier()
  720.         {
  721.             return this.speedMultiplier;
  722.         }
  723.        
  724.         public float getJumpHeight()
  725.         {
  726.             return this.jumpHeight;
  727.         }
  728.        
  729.         public int func_180075_c()
  730.         {
  731.             return this.field_180084_h;
  732.         }
  733.        
  734.         public int func_180073_d()
  735.         {
  736.             return this.field_180085_i;
  737.         }
  738.     }
  739.    
  740.     public class RabbitJumpHelper extends EntityJumpHelper
  741.     {
  742.         private EntityRabbit        rabbit;
  743.         private boolean             field_180068_d  = false;
  744.         private static final String __OBFID         = "CL_00002236";
  745.        
  746.         public RabbitJumpHelper(EntityRabbit rabbit)
  747.         {
  748.             super(rabbit);
  749.             this.rabbit = rabbit;
  750.         }
  751.        
  752.         public boolean getJumping()
  753.         {
  754.             try
  755.             {
  756.                 return (Boolean) entityJumpHelperIsJumpingField.get(this);
  757.             }
  758.             catch (Exception e)
  759.             {
  760.                 throw new RuntimeException(e);
  761.             }
  762.         }
  763.        
  764.         public boolean func_180065_d()
  765.         {
  766.             return this.field_180068_d;
  767.         }
  768.        
  769.         public void func_180066_a(boolean p_180066_1_)
  770.         {
  771.             this.field_180068_d = p_180066_1_;
  772.         }
  773.        
  774.         @Override
  775.         public void doJump()
  776.         {
  777.             try
  778.             {
  779.                 if((Boolean) entityJumpHelperIsJumpingField.get(this))
  780.                 {
  781.                     this.rabbit.applyMoveType(EntityRabbit.EnumMoveType.STEP);
  782.                     entityJumpHelperIsJumpingField.set(this, false);
  783.                 }
  784.             }
  785.             catch (Exception e)
  786.             {
  787.                 throw new RuntimeException(e);
  788.             }
  789.         }
  790.     }
  791.    
  792.     class RabbitMoveHelper extends EntityMoveHelper
  793.     {
  794.         private EntityRabbit        rabbit  = EntityRabbit.this;
  795.         private static final String __OBFID = "CL_00002235";
  796.        
  797.         public RabbitMoveHelper()
  798.         {
  799.             super(EntityRabbit.this);
  800.         }
  801.        
  802.         @Override
  803.         public void onUpdateMoveHelper()
  804.         {
  805.             if(this.rabbit.onGround && !this.rabbit.getJumping())
  806.             {
  807.                 this.rabbit.setSpeed(0.0D);
  808.             }
  809.            
  810.             super.onUpdateMoveHelper();
  811.         }
  812.     }
  813.    
  814.     public static class RabbitTypeData implements IEntityLivingData
  815.     {
  816.         public int                  rabbitType;
  817.         private static final String __OBFID = "CL_00002237";
  818.        
  819.         public RabbitTypeData(int rabbitType)
  820.         {
  821.             this.rabbitType = rabbitType;
  822.         }
  823.     }
  824.    
  825.     class AIRaidFarm extends EntityAIMoveToBlock
  826.     {
  827.         private boolean             field_179498_d;
  828.         private boolean             field_179499_e  = false;
  829.         private static final String __OBFID         = "CL_00002233";
  830.        
  831.         public AIRaidFarm()
  832.         {
  833.             super(EntityRabbit.this, 0.699999988079071D, 16);
  834.         }
  835.        
  836.         @Override
  837.         public boolean shouldExecute()
  838.         {
  839.             if(this.field_179496_a <= 0)
  840.             {
  841.                 if(!EntityRabbit.this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")){ return false; }
  842.                
  843.                 this.field_179499_e = false;
  844.                 this.field_179498_d = EntityRabbit.this.func_175534_cv();
  845.             }
  846.            
  847.             return super.shouldExecute();
  848.         }
  849.        
  850.         @Override
  851.         public boolean continueExecuting()
  852.         {
  853.             return this.field_179499_e && super.continueExecuting();
  854.         }
  855.        
  856.         @Override
  857.         public void startExecuting()
  858.         {
  859.             super.startExecuting();
  860.         }
  861.        
  862.         @Override
  863.         public void resetTask()
  864.         {
  865.             super.resetTask();
  866.         }
  867.        
  868.         @Override
  869.         public void updateTask()
  870.         {
  871.             EarlyFuture.LOG.info("Updating task");
  872.             super.updateTask();
  873.             EntityRabbit.this.getLookHelper().setLookPosition((double) this.destinationBlockX + 0.5D,
  874.                 (double) (this.destinationBlockY + 1), (double) this.destinationBlockZ + 0.5D, 10.0F,
  875.                 (float) EntityRabbit.this.getVerticalFaceSpeed());
  876.            
  877.             if(this.func_179487_f())
  878.             {
  879.                 World world = EntityRabbit.this.worldObj;
  880.                 int posY = this.destinationBlockY + 1;
  881.                 Block block = world.getBlock(this.destinationBlockX, posY, this.destinationBlockZ);
  882.                
  883.                 if(this.field_179499_e && block instanceof BlockCarrot
  884.                     && world.getBlockMetadata(this.destinationBlockX, posY, this.destinationBlockZ) == 7)
  885.                 {
  886.                     EarlyFuture.LOG.info("Attempting to destroy block");
  887.                     world.playAuxSFX(2001, this.destinationBlockX, posY, this.destinationBlockZ, 0);
  888.                     block.dropBlockAsItem(world, this.destinationBlockX, posY, this.destinationBlockZ, 7, 0);
  889.                     world.setBlock(this.destinationBlockX, posY, this.destinationBlockZ, Blocks.air, 0, 3);
  890.                     EntityRabbit.this.func_175528_cn();
  891.                 }
  892.                 else EarlyFuture.LOG.info("Not a fully grown carrot, sorry!");
  893.                
  894.                 this.field_179499_e = false;
  895.                 this.field_179496_a = 10;
  896.             }
  897.             else EarlyFuture.LOG.info("Not on the block!");
  898.         }
  899.        
  900.         @Override
  901.         protected boolean isTargetBlock(World worldIn, double posX, double posY, double posZ)
  902.         {
  903.             Block block = worldIn.getBlock((int) posX, (int) posY, (int) posZ);
  904.            
  905.             if(block == Blocks.farmland)
  906.             {
  907.                 block = worldIn.getBlock((int) posX, (int) ++posY, (int) posZ);
  908.                
  909.                 if(block instanceof BlockCarrot && worldIn.getBlockMetadata((int) posX, (int) posY, (int) posZ) == 7
  910.                     && this.field_179498_d && !this.field_179499_e)
  911.                 {
  912.                     this.field_179499_e = true;
  913.                     return true;
  914.                 }
  915.             }
  916.            
  917.             return false;
  918.         }
  919.     }
  920.    
  921. }
Advertisement
Add Comment
Please, Sign In to add comment