Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.codepixl.whatevermod.entity;
- import java.util.Calendar;
- import net.codepixl.whatevermod.WhateverMod;
- import net.minecraft.block.Block;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityAgeable;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.EntityAIFollowParent;
- import net.minecraft.entity.ai.EntityAILookIdle;
- import net.minecraft.entity.ai.EntityAIMate;
- import net.minecraft.entity.ai.EntityAIPanic;
- import net.minecraft.entity.ai.EntityAISwimming;
- import net.minecraft.entity.ai.EntityAITempt;
- import net.minecraft.entity.ai.EntityAIWander;
- import net.minecraft.entity.ai.EntityAIWatchClosest;
- import net.minecraft.entity.boss.EntityDragon;
- import net.minecraft.entity.passive.EntityAnimal;
- import net.minecraft.entity.passive.EntityChicken;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- public class EntityDuck extends EntityAnimal
- {
- /** Coordinates of where the bat spawned. */
- private BlockPos spawnPosition;
- public float field_70886_e;
- public float destPos;
- public float field_70884_g;
- public float field_70888_h;
- public float field_70889_i = 1.0F;
- private static final String __OBFID = "CL_00001637";
- public EntityDuck(World worldIn)
- {
- super(worldIn);
- this.setSize(0.4F, 0.7F);
- this.setIsDuckSwimming(true);
- this.tasks.addTask(0, new EntityAISwimming(this));
- this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
- this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.bread, false));
- this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
- this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
- this.tasks.addTask(7, new EntityAILookIdle(this));
- this.tasks.addTask(8, new EntityAIMate(this, 1.0D));
- this.tasks.addTask(9, new EntityAIFollowParent(this, 1.1D));
- }
- protected void entityInit()
- {
- super.entityInit();
- this.dataWatcher.addObject(16, new Byte((byte)0));
- }
- protected void applyEntityAttributes()
- {
- super.applyEntityAttributes();
- this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(4.0D);
- this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
- }
- public boolean isBreedingItem(ItemStack stack)
- {
- return stack != null && stack.getItem() == Items.bread;
- }
- /**
- * Returns the volume for the sounds this mob makes.
- */
- protected float getSoundVolume()
- {
- return 1F;
- }
- /**
- * Gets the pitch of living sounds in living entities.
- */
- protected float getSoundPitch()
- {
- return super.getSoundPitch() * 0.95F;
- }
- @Override
- public int getTalkInterval(){
- return 200;
- }
- /**
- * Returns the sound this mob makes while it's alive.
- */
- protected String getLivingSound()
- {
- switch(rand.nextInt(2)){
- case 0:
- return WhateverMod.MODID+":ducksayA";
- case 1:
- return WhateverMod.MODID+":ducksayB";
- case 3:
- return WhateverMod.MODID+":ducksayC";
- default:
- return WhateverMod.MODID+":ducksayA";
- }
- }
- /**
- * Returns the sound this mob makes when it is hurt.
- */
- protected String getHurtSound()
- {
- switch(rand.nextInt(2)){
- case 0:
- return WhateverMod.MODID+":ducksayA";
- case 1:
- return WhateverMod.MODID+":ducksayB";
- case 3:
- return WhateverMod.MODID+":ducksayC";
- default:
- return WhateverMod.MODID+":ducksayA";
- }
- }
- /**
- * Returns the sound this mob makes on death.
- */
- protected String getDeathSound()
- {
- switch(rand.nextInt(2)){
- case 0:
- return WhateverMod.MODID+":ducksayA";
- case 1:
- return WhateverMod.MODID+":ducksayB";
- case 3:
- return WhateverMod.MODID+":ducksayC";
- default:
- return WhateverMod.MODID+":ducksayA";
- }
- }
- /**
- * Returns true if this entity should push and be pushed by other entities when colliding.
- */
- public boolean canBePushed()
- {
- return true;
- }
- protected void collideWithEntity(Entity p_82167_1_) {}
- protected void collideWithNearbyEntities() {}
- public boolean getIsDuckSwimming()
- {
- return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
- }
- public void setIsDuckSwimming(boolean p_82236_1_)
- {
- byte var2 = this.dataWatcher.getWatchableObjectByte(16);
- if (p_82236_1_)
- {
- this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 | 1)));
- }
- else
- {
- this.dataWatcher.updateObject(16, Byte.valueOf((byte)(var2 & -2)));
- }
- }
- /**
- * Called to update the entity's position/logic.
- */
- public void onLivingUpdate()
- {
- super.onLivingUpdate();
- this.field_70888_h = this.field_70886_e;
- this.field_70884_g = this.destPos;
- this.destPos = (float)((double)this.destPos + (double)(this.onGround ? -1 : 4) * 0.3D);
- this.destPos = MathHelper.clamp_float(this.destPos, 0.0F, 1.0F);
- if (!this.onGround && this.field_70889_i < 1.0F)
- {
- this.field_70889_i = 1.0F;
- }
- this.field_70889_i = (float)((double)this.field_70889_i * 0.9D);
- if (!this.onGround && this.motionY < 0.0D && !this.getIsDuckSwimming())
- {
- this.motionY *= 0.8D;
- }
- this.field_70886_e += this.field_70889_i * 2.0F;
- if (this.getIsDuckSwimming())
- {
- }
- else
- {
- this.motionY *= 0.6000000238418579D;
- }
- }
- protected void updateAITasks()
- {
- super.updateAITasks();
- if(this.isInLove()){
- this.setIsDuckSwimming(true);
- }
- if (this.getIsDuckSwimming())
- {
- if(rand.nextInt(200) == 0){
- if(this.onGround || this.inWater){
- this.setIsDuckSwimming(false);
- }
- }
- }
- else
- {
- if (this.spawnPosition != null && (!this.worldObj.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1))
- {
- this.spawnPosition = null;
- }
- 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)
- {
- 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));
- }
- double var3 = (double)this.spawnPosition.getX() + 0.5D - this.posX;
- double var5 = (double)this.spawnPosition.getY() + 0.1D - this.posY;
- double var7 = (double)this.spawnPosition.getZ() + 0.5D - this.posZ;
- this.motionX += (Math.signum(var3) * 0.5D - this.motionX) * 0.10000000149011612D;
- this.motionY += (Math.signum(var5) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
- this.motionZ += (Math.signum(var7) * 0.5D - this.motionZ) * 0.10000000149011612D;
- float var9 = (float)(Math.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) - 90.0F;
- float var10 = MathHelper.wrapAngleTo180_float(var9 - this.rotationYaw);
- this.moveForward = 2.0F;
- this.rotationYaw += var10;
- if (this.rand.nextInt(200) == 0)
- {
- this.setIsDuckSwimming(true);
- }
- }
- }
- /**
- * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
- * prevent them from trampling crops
- */
- protected boolean canTriggerWalking()
- {
- return false;
- }
- public void fall(float distance, float damageMultiplier) {}
- protected void func_180433_a(double p_180433_1_, boolean p_180433_3_, Block p_180433_4_, BlockPos p_180433_5_) {}
- /**
- * Return whether this entity should NOT trigger a pressure plate or a tripwire.
- */
- public boolean doesEntityNotTriggerPressurePlate()
- {
- return true;
- }
- /**
- * Called when the entity is attacked.
- */
- public boolean attackEntityFrom(DamageSource source, float amount)
- {
- return super.attackEntityFrom(source, amount);
- }
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- public void readEntityFromNBT(NBTTagCompound tagCompund)
- {
- super.readEntityFromNBT(tagCompund);
- this.dataWatcher.updateObject(16, Byte.valueOf(tagCompund.getByte("BatFlags")));
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- public void writeEntityToNBT(NBTTagCompound tagCompound)
- {
- super.writeEntityToNBT(tagCompound);
- tagCompound.setByte("BatFlags", this.dataWatcher.getWatchableObjectByte(16));
- }
- /**
- * Checks if the entity's current position is a valid location to spawn this entity.
- */
- public boolean getCanSpawnHere()
- {
- BlockPos var1 = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
- if (var1.getY() >= 63)
- {
- return false;
- }
- else
- {
- int var2 = this.worldObj.getLightFromNeighbors(var1);
- byte var3 = 4;
- if (this.func_175569_a(this.worldObj.getCurrentDate()))
- {
- var3 = 7;
- }
- else if (this.rand.nextBoolean())
- {
- return false;
- }
- return var2 > this.rand.nextInt(var3) ? false : super.getCanSpawnHere();
- }
- }
- private boolean func_175569_a(Calendar p_175569_1_)
- {
- 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;
- }
- public float getEyeHeight()
- {
- return this.height / 2.0F;
- }
- @Override
- public EntityAgeable createChild(EntityAgeable ageable) {
- return new EntityDuck(this.worldObj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement