Advertisement
Guest User

EntityDuck

a guest
Jun 13th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.73 KB | None | 0 0
  1. package net.codepixl.whatevermod.entity;
  2.  
  3. import java.util.Calendar;
  4.  
  5. import net.codepixl.whatevermod.WhateverMod;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.EntityAgeable;
  9. import net.minecraft.entity.EntityCreature;
  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.EntityAISwimming;
  16. import net.minecraft.entity.ai.EntityAITempt;
  17. import net.minecraft.entity.ai.EntityAIWander;
  18. import net.minecraft.entity.ai.EntityAIWatchClosest;
  19. import net.minecraft.entity.boss.EntityDragon;
  20. import net.minecraft.entity.passive.EntityAnimal;
  21. import net.minecraft.entity.passive.EntityChicken;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.init.Items;
  24. import net.minecraft.item.ItemStack;
  25. import net.minecraft.nbt.NBTTagCompound;
  26. import net.minecraft.util.BlockPos;
  27. import net.minecraft.util.DamageSource;
  28. import net.minecraft.util.EnumFacing;
  29. import net.minecraft.util.MathHelper;
  30. import net.minecraft.world.World;
  31.  
  32. public class EntityDuck extends EntityAnimal
  33. {
  34.     /** Coordinates of where the bat spawned. */
  35.     private BlockPos spawnPosition;
  36.     public float field_70886_e;
  37.     public float destPos;
  38.     public float field_70884_g;
  39.     public float field_70888_h;
  40.     public float field_70889_i = 1.0F;
  41.     private static final String __OBFID = "CL_00001637";
  42.  
  43.     public EntityDuck(World worldIn)
  44.     {
  45.         super(worldIn);
  46.         this.setSize(0.4F, 0.7F);
  47.         this.setIsDuckSwimming(true);
  48.         this.tasks.addTask(0, new EntityAISwimming(this));
  49.         this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
  50.         this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.bread, false));
  51.         this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
  52.         this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
  53.         this.tasks.addTask(7, new EntityAILookIdle(this));
  54.         this.tasks.addTask(8, new EntityAIMate(this, 1.0D));
  55.         this.tasks.addTask(9, new EntityAIFollowParent(this, 1.1D));
  56.     }
  57.  
  58.     protected void entityInit()
  59.     {
  60.         super.entityInit();
  61.         this.dataWatcher.addObject(16, new Byte((byte)0));
  62.     }
  63.    
  64.     protected void applyEntityAttributes()
  65.     {
  66.         super.applyEntityAttributes();
  67.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(4.0D);
  68.         this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
  69.     }
  70.    
  71.     public boolean isBreedingItem(ItemStack stack)
  72.     {
  73.         return stack != null && stack.getItem() == Items.bread;
  74.     }
  75.  
  76.     /**
  77.      * Returns the volume for the sounds this mob makes.
  78.      */
  79.     protected float getSoundVolume()
  80.     {
  81.         return 1F;
  82.     }
  83.  
  84.     /**
  85.      * Gets the pitch of living sounds in living entities.
  86.      */
  87.     protected float getSoundPitch()
  88.     {
  89.         return super.getSoundPitch() * 0.95F;
  90.     }
  91.    
  92.     @Override
  93.     public int getTalkInterval(){
  94.         return 200;
  95.     }
  96.  
  97.     /**
  98.      * Returns the sound this mob makes while it's alive.
  99.      */
  100.     protected String getLivingSound()
  101.     {
  102.         switch(rand.nextInt(2)){
  103.         case 0:
  104.             return WhateverMod.MODID+":ducksayA";
  105.         case 1:
  106.             return WhateverMod.MODID+":ducksayB";
  107.         case 3:
  108.             return WhateverMod.MODID+":ducksayC";
  109.         default:
  110.             return WhateverMod.MODID+":ducksayA";
  111.         }
  112.     }
  113.  
  114.     /**
  115.      * Returns the sound this mob makes when it is hurt.
  116.      */
  117.     protected String getHurtSound()
  118.     {
  119.         switch(rand.nextInt(2)){
  120.         case 0:
  121.             return WhateverMod.MODID+":ducksayA";
  122.         case 1:
  123.             return WhateverMod.MODID+":ducksayB";
  124.         case 3:
  125.             return WhateverMod.MODID+":ducksayC";
  126.         default:
  127.             return WhateverMod.MODID+":ducksayA";
  128.         }
  129.     }
  130.  
  131.     /**
  132.      * Returns the sound this mob makes on death.
  133.      */
  134.     protected String getDeathSound()
  135.     {
  136.         switch(rand.nextInt(2)){
  137.         case 0:
  138.             return WhateverMod.MODID+":ducksayA";
  139.         case 1:
  140.             return WhateverMod.MODID+":ducksayB";
  141.         case 3:
  142.             return WhateverMod.MODID+":ducksayC";
  143.         default:
  144.             return WhateverMod.MODID+":ducksayA";
  145.         }
  146.     }
  147.  
  148.     /**
  149.      * Returns true if this entity should push and be pushed by other entities when colliding.
  150.      */
  151.     public boolean canBePushed()
  152.     {
  153.         return true;
  154.     }
  155.  
  156.     protected void collideWithEntity(Entity p_82167_1_) {}
  157.  
  158.     protected void collideWithNearbyEntities() {}
  159.  
  160.     public boolean getIsDuckSwimming()
  161.     {
  162.         return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
  163.     }
  164.  
  165.     public void setIsDuckSwimming(boolean p_82236_1_)
  166.     {
  167.         byte var2 = this.dataWatcher.getWatchableObjectByte(16);
  168.  
  169.         if (p_82236_1_)
  170.         {
  171.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 1)));
  172.         }
  173.         else
  174.         {
  175.             this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -2)));
  176.         }
  177.     }
  178.  
  179.     /**
  180.      * Called to update the entity's position/logic.
  181.      */
  182.     public void onLivingUpdate()
  183.     {
  184.         super.onLivingUpdate();
  185.  
  186.         this.field_70888_h = this.field_70886_e;
  187.         this.field_70884_g = this.destPos;
  188.         this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
  189.         this.destPos = MathHelper.clamp_float(this.destPos, 0.0F, 1.0F);
  190.  
  191.         if (!this.onGround && this.field_70889_i < 1.0F)
  192.         {
  193.             this.field_70889_i = 1.0F;
  194.         }
  195.  
  196.         this.field_70889_i = (float)((double)this.field_70889_i * 0.9D);
  197.  
  198.         if (!this.onGround && this.motionY < 0.0D && !this.getIsDuckSwimming())
  199.         {
  200.             this.motionY *= 0.8D;
  201.         }
  202.  
  203.         this.field_70886_e += this.field_70889_i * 2.0F;
  204.        
  205.         if (this.getIsDuckSwimming())
  206.         {
  207.            
  208.         }
  209.         else
  210.         {
  211.             this.motionY *= 0.6000000238418579D;
  212.         }
  213.     }
  214.  
  215.     protected void updateAITasks()
  216.     {
  217.         super.updateAITasks();
  218.         if(this.isInLove()){
  219.             this.setIsDuckSwimming(true);
  220.         }
  221.        
  222.         if (this.getIsDuckSwimming())
  223.         {
  224.             if(rand.nextInt(200) == 0){
  225.                 if(this.onGround || this.inWater){
  226.                     this.setIsDuckSwimming(false);
  227.                 }
  228.             }
  229.         }
  230.         else
  231.         {
  232.             if (this.spawnPosition != null && (!this.worldObj.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1))
  233.             {
  234.                 this.spawnPosition = null;
  235.             }
  236.  
  237.             if (this.spawnPosition == null || this.rand.nextInt(30) == 0 || this.spawnPosition.distanceSq((double)((int)this.posX), (double)((int)this.posY), (double)((int)this.posZ)) < 4.0D)
  238.             {
  239.                 this.spawnPosition = new BlockPos((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(6) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
  240.             }
  241.  
  242.             double var3 = (double)this.spawnPosition.getX() + 0.5D - this.posX;
  243.             double var5 = (double)this.spawnPosition.getY() + 0.1D - this.posY;
  244.             double var7 = (double)this.spawnPosition.getZ() + 0.5D - this.posZ;
  245.             this.motionX += (Math.signum(var3) * 0.5D - this.motionX) * 0.10000000149011612D;
  246.             this.motionY += (Math.signum(var5) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
  247.             this.motionZ += (Math.signum(var7) * 0.5D - this.motionZ) * 0.10000000149011612D;
  248.             float var9 = (float)(Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) - 90.0F;
  249.             float var10 = MathHelper.wrapAngleTo180_float(var9 - this.rotationYaw);
  250.             this.moveForward = 2.0F;
  251.             this.rotationYaw += var10;
  252.  
  253.             if (this.rand.nextInt(200) == 0)
  254.             {
  255.                 this.setIsDuckSwimming(true);
  256.             }
  257.         }
  258.     }
  259.  
  260.     /**
  261.      * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  262.      * prevent them from trampling crops
  263.      */
  264.     protected boolean canTriggerWalking()
  265.     {
  266.         return false;
  267.     }
  268.  
  269.     public void fall(float distance, float damageMultiplier) {}
  270.  
  271.     protected void func_180433_a(double p_180433_1_, boolean p_180433_3_, Block p_180433_4_, BlockPos p_180433_5_) {}
  272.  
  273.     /**
  274.      * Return whether this entity should NOT trigger a pressure plate or a tripwire.
  275.      */
  276.     public boolean doesEntityNotTriggerPressurePlate()
  277.     {
  278.         return true;
  279.     }
  280.  
  281.     /**
  282.      * Called when the entity is attacked.
  283.      */
  284.     public boolean attackEntityFrom(DamageSource source, float amount)
  285.     {
  286.         return super.attackEntityFrom(source, amount);
  287.     }
  288.  
  289.     /**
  290.      * (abstract) Protected helper method to read subclass entity data from NBT.
  291.      */
  292.     public void readEntityFromNBT(NBTTagCompound tagCompund)
  293.     {
  294.         super.readEntityFromNBT(tagCompund);
  295.         this.dataWatcher.updateObject(16, Byte.valueOf(tagCompund.getByte("BatFlags")));
  296.     }
  297.  
  298.     /**
  299.      * (abstract) Protected helper method to write subclass entity data to NBT.
  300.      */
  301.     public void writeEntityToNBT(NBTTagCompound tagCompound)
  302.     {
  303.         super.writeEntityToNBT(tagCompound);
  304.         tagCompound.setByte("BatFlags", this.dataWatcher.getWatchableObjectByte(16));
  305.     }
  306.  
  307.     /**
  308.      * Checks if the entity's current position is a valid location to spawn this entity.
  309.      */
  310.     public boolean getCanSpawnHere()
  311.     {
  312.         BlockPos var1 = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
  313.  
  314.         if (var1.getY() >= 63)
  315.         {
  316.             return false;
  317.         }
  318.         else
  319.         {
  320.             int var2 = this.worldObj.getLightFromNeighbors(var1);
  321.             byte var3 = 4;
  322.  
  323.             if (this.func_175569_a(this.worldObj.getCurrentDate()))
  324.             {
  325.                 var3 = 7;
  326.             }
  327.             else if (this.rand.nextBoolean())
  328.             {
  329.                 return false;
  330.             }
  331.  
  332.             return var2 > this.rand.nextInt(var3) ? false : super.getCanSpawnHere();
  333.         }
  334.     }
  335.  
  336.     private boolean func_175569_a(Calendar p_175569_1_)
  337.     {
  338.         return p_175569_1_.get(2) + 1 == 10 && p_175569_1_.get(5) >= 20 || p_175569_1_.get(2) + 1 == 11 && p_175569_1_.get(5) <= 3;
  339.     }
  340.  
  341.     public float getEyeHeight()
  342.     {
  343.         return this.height / 2.0F;
  344.     }
  345.  
  346.     @Override
  347.     public EntityAgeable createChild(EntityAgeable ageable) {
  348.         return new EntityDuck(this.worldObj);
  349.     }
  350. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement