jokekid

Untitled

Sep 6th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.34 KB | None | 0 0
  1. package net.minecraft.entity.monster;
  2.  
  3. import java.util.Random;
  4. import net.minecraft.entity.EntityFlying;
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.SharedMonsterAttributes;
  7. import net.minecraft.entity.ai.EntityAIBase;
  8. import net.minecraft.entity.ai.EntityAIFindEntityNearestPlayer;
  9. import net.minecraft.entity.ai.EntityMoveHelper;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.entity.projectile.EntityLargeFireball;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.stats.AchievementList;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.util.BlockPos;
  18. import net.minecraft.util.DamageSource;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.util.Vec3;
  21. import net.minecraft.world.EnumDifficulty;
  22. import net.minecraft.world.World;
  23. import net.minecraftforge.fml.relauncher.Side;
  24. import net.minecraftforge.fml.relauncher.SideOnly;
  25.  
  26. public class EntityGhast extends EntityFlying implements IMob
  27. {
  28.     /** The explosion radius of spawned fireballs. */
  29.     private int explosionStrength = 1;
  30.     private static final String __OBFID = "CL_00001689";
  31.  
  32.     public EntityGhast(World worldIn)
  33.     {
  34.         super(worldIn);
  35.         this.setSize(4.0F, 4.0F);
  36.         this.isImmuneToFire = true;
  37.         this.experienceValue = 5;
  38.         this.moveHelper = new EntityGhast.GhastMoveHelper();
  39.         this.tasks.addTask(5, new EntityGhast.AIRandomFly());
  40.         this.tasks.addTask(7, new EntityGhast.AILookAround());
  41.         this.tasks.addTask(7, new EntityGhast.AIFireballAttack());
  42.         this.targetTasks.addTask(1, new EntityAIFindEntityNearestPlayer(this));
  43.     }
  44.  
  45.     @SideOnly(Side.CLIENT)
  46.     public boolean func_110182_bF()
  47.     {
  48.         return this.dataWatcher.getWatchableObjectByte(16) != 0;
  49.     }
  50.  
  51.     public void func_175454_a(boolean p_175454_1_)
  52.     {
  53.         this.dataWatcher.updateObject(16, Byte.valueOf((byte)(p_175454_1_ ? 1 : 0)));
  54.     }
  55.  
  56.     public int func_175453_cd()
  57.     {
  58.         return this.explosionStrength;
  59.     }
  60.  
  61.     /**
  62.      * Called to update the entity's position/logic.
  63.      */
  64.     public void onUpdate()
  65.     {
  66.         super.onUpdate();
  67.  
  68.         if (!this.worldObj.isRemote && this.worldObj.getDifficulty() == EnumDifficulty.PEACEFUL)
  69.         {
  70.             this.setDead();
  71.         }
  72.     }
  73.  
  74.     /**
  75.      * Called when the entity is attacked.
  76.      */
  77.     public boolean attackEntityFrom(DamageSource source, float amount)
  78.     {
  79.         if (this.isEntityInvulnerable(source))
  80.         {
  81.             return false;
  82.         }
  83.         else if ("fireball".equals(source.getDamageType()) && source.getEntity() instanceof EntityPlayer)
  84.         {
  85.             super.attackEntityFrom(source, 1000.0F);
  86.             ((EntityPlayer)source.getEntity()).triggerAchievement(AchievementList.ghast);
  87.             return true;
  88.         }
  89.         else
  90.         {
  91.             return super.attackEntityFrom(source, amount);
  92.         }
  93.     }
  94.  
  95.     protected void entityInit()
  96.     {
  97.         super.entityInit();
  98.         this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
  99.     }
  100.  
  101.     protected void applyEntityAttributes()
  102.     {
  103.         super.applyEntityAttributes();
  104.         this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);
  105.         this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(100.0D);
  106.     }
  107.  
  108.     /**
  109.      * Returns the sound this mob makes while it's alive.
  110.      */
  111.     protected String getLivingSound()
  112.     {
  113.         return "mob.ghast.moan";
  114.     }
  115.  
  116.     /**
  117.      * Returns the sound this mob makes when it is hurt.
  118.      */
  119.     protected String getHurtSound()
  120.     {
  121.         return "mob.ghast.scream";
  122.     }
  123.  
  124.     /**
  125.      * Returns the sound this mob makes on death.
  126.      */
  127.     protected String getDeathSound()
  128.     {
  129.         return "mob.ghast.death";
  130.     }
  131.  
  132.     protected Item getDropItem()
  133.     {
  134.         return Items.gunpowder;
  135.     }
  136.  
  137.     /**
  138.      * Drop 0-2 items of this living's type
  139.      */
  140.     protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)
  141.     {
  142.         int j = this.rand.nextInt(2) + this.rand.nextInt(1 + p_70628_2_);
  143.         int k;
  144.  
  145.         for (k = 0; k < j; ++k)
  146.         {
  147.             this.dropItem(Items.ghast_tear, 1);
  148.         }
  149.  
  150.         j = this.rand.nextInt(3) + this.rand.nextInt(1 + p_70628_2_);
  151.  
  152.         for (k = 0; k < j; ++k)
  153.         {
  154.             this.dropItem(Items.gunpowder, 1);
  155.         }
  156.     }
  157.  
  158.     /**
  159.      * Returns the volume for the sounds this mob makes.
  160.      */
  161.     protected float getSoundVolume()
  162.     {
  163.         return 10.0F;
  164.     }
  165.  
  166.     /**
  167.      * Checks if the entity's current position is a valid location to spawn this entity.
  168.      */
  169.     public boolean getCanSpawnHere()
  170.     {
  171.         return this.rand.nextInt(20) == 0 && super.getCanSpawnHere() && this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL;
  172.     }
  173.  
  174.     /**
  175.      * Will return how many at most can spawn in a chunk at once.
  176.      */
  177.     public int getMaxSpawnedInChunk()
  178.     {
  179.         return 1;
  180.     }
  181.  
  182.     /**
  183.      * (abstract) Protected helper method to write subclass entity data to NBT.
  184.      */
  185.     public void writeEntityToNBT(NBTTagCompound tagCompound)
  186.     {
  187.         super.writeEntityToNBT(tagCompound);
  188.         tagCompound.setInteger("ExplosionPower", this.explosionStrength);
  189.     }
  190.  
  191.     /**
  192.      * (abstract) Protected helper method to read subclass entity data from NBT.
  193.      */
  194.     public void readEntityFromNBT(NBTTagCompound tagCompund)
  195.     {
  196.         super.readEntityFromNBT(tagCompund);
  197.  
  198.         if (tagCompund.hasKey("ExplosionPower", 99))
  199.         {
  200.             this.explosionStrength = tagCompund.getInteger("ExplosionPower");
  201.         }
  202.     }
  203.  
  204.     public float getEyeHeight()
  205.     {
  206.         return 2.6F;
  207.     }
  208.  
  209.     class AIFireballAttack extends EntityAIBase
  210.     {
  211.         private EntityGhast field_179470_b = EntityGhast.this;
  212.         public int field_179471_a;
  213.         private static final String __OBFID = "CL_00002215";
  214.  
  215.         /**
  216.          * Returns whether the EntityAIBase should begin execution.
  217.          */
  218.         public boolean shouldExecute()
  219.         {
  220.             return this.field_179470_b.getAttackTarget() != null;
  221.         }
  222.  
  223.         /**
  224.          * Execute a one shot task or start executing a continuous task
  225.          */
  226.         public void startExecuting()
  227.         {
  228.             this.field_179471_a = 0;
  229.         }
  230.  
  231.         /**
  232.          * Resets the task
  233.          */
  234.         public void resetTask()
  235.         {
  236.             this.field_179470_b.func_175454_a(false);
  237.         }
  238.  
  239.         /**
  240.          * Updates the task
  241.          */
  242.         public void updateTask()
  243.         {
  244.             EntityLivingBase entitylivingbase = this.field_179470_b.getAttackTarget();
  245.             double d0 = 64.0D;
  246.  
  247.             if (entitylivingbase.getDistanceSqToEntity(this.field_179470_b) < d0 * d0 && this.field_179470_b.canEntityBeSeen(entitylivingbase))
  248.             {
  249.                 World world = this.field_179470_b.worldObj;
  250.                 ++this.field_179471_a;
  251.  
  252.                 if (this.field_179471_a == 10)
  253.                 {
  254.                     world.playAuxSFXAtEntity((EntityPlayer)null, 1007, new BlockPos(this.field_179470_b), 0);
  255.                 }
  256.  
  257.                 if (this.field_179471_a == 20)
  258.                 {
  259.                     double d1 = 4.0D;
  260.                     Vec3 vec3 = this.field_179470_b.getLook(1.0F);
  261.                     double d2 = entitylivingbase.posX - (this.field_179470_b.posX + vec3.xCoord * d1);
  262.                     double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.field_179470_b.posY + (double)(this.field_179470_b.height / 2.0F));
  263.                     double d4 = entitylivingbase.posZ - (this.field_179470_b.posZ + vec3.zCoord * d1);
  264.                     world.playAuxSFXAtEntity((EntityPlayer)null, 1008, new BlockPos(this.field_179470_b), 0);
  265.                     EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.field_179470_b, d2, d3, d4);
  266.                     entitylargefireball.explosionPower = this.field_179470_b.func_175453_cd();
  267.                     entitylargefireball.posX = this.field_179470_b.posX + vec3.xCoord * d1;
  268.                     entitylargefireball.posY = this.field_179470_b.posY + (double)(this.field_179470_b.height / 2.0F) + 0.5D;
  269.                     entitylargefireball.posZ = this.field_179470_b.posZ + vec3.zCoord * d1;
  270.                     world.spawnEntityInWorld(entitylargefireball);
  271.                     this.field_179471_a = -40;
  272.                 }
  273.             }
  274.             else if (this.field_179471_a > 0)
  275.             {
  276.                 --this.field_179471_a;
  277.             }
  278.  
  279.             this.field_179470_b.func_175454_a(this.field_179471_a > 10);
  280.         }
  281.     }
  282.  
  283.     class AILookAround extends EntityAIBase
  284.     {
  285.         private EntityGhast field_179472_a = EntityGhast.this;
  286.         private static final String __OBFID = "CL_00002217";
  287.  
  288.         public AILookAround()
  289.         {
  290.             this.setMutexBits(2);
  291.         }
  292.  
  293.         /**
  294.          * Returns whether the EntityAIBase should begin execution.
  295.          */
  296.         public boolean shouldExecute()
  297.         {
  298.             return true;
  299.         }
  300.  
  301.         /**
  302.          * Updates the task
  303.          */
  304.         public void updateTask()
  305.         {
  306.             if (this.field_179472_a.getAttackTarget() == null)
  307.             {
  308.                 this.field_179472_a.renderYawOffset = this.field_179472_a.rotationYaw = -((float)Math.atan2(this.field_179472_a.motionX, this.field_179472_a.motionZ)) * 180.0F / (float)Math.PI;
  309.             }
  310.             else
  311.             {
  312.                 EntityLivingBase entitylivingbase = this.field_179472_a.getAttackTarget();
  313.                 double d0 = 64.0D;
  314.  
  315.                 if (entitylivingbase.getDistanceSqToEntity(this.field_179472_a) < d0 * d0)
  316.                 {
  317.                     double d1 = entitylivingbase.posX - this.field_179472_a.posX;
  318.                     double d2 = entitylivingbase.posZ - this.field_179472_a.posZ;
  319.                     this.field_179472_a.renderYawOffset = this.field_179472_a.rotationYaw = -((float)Math.atan2(d1, d2)) * 180.0F / (float)Math.PI;
  320.                 }
  321.             }
  322.         }
  323.     }
  324.  
  325.     class AIRandomFly extends EntityAIBase
  326.     {
  327.         private EntityGhast field_179454_a = EntityGhast.this;
  328.         private static final String __OBFID = "CL_00002214";
  329.  
  330.         public AIRandomFly()
  331.         {
  332.             this.setMutexBits(1);
  333.         }
  334.  
  335.         /**
  336.          * Returns whether the EntityAIBase should begin execution.
  337.          */
  338.         public boolean shouldExecute()
  339.         {
  340.             EntityMoveHelper entitymovehelper = this.field_179454_a.getMoveHelper();
  341.  
  342.             if (!entitymovehelper.isUpdating())
  343.             {
  344.                 return true;
  345.             }
  346.             else
  347.             {
  348.                 double d0 = entitymovehelper.func_179917_d() - this.field_179454_a.posX;
  349.                 double d1 = entitymovehelper.func_179919_e() - this.field_179454_a.posY;
  350.                 double d2 = entitymovehelper.func_179918_f() - this.field_179454_a.posZ;
  351.                 double d3 = d0 * d0 + d1 * d1 + d2 * d2;
  352.                 return d3 < 1.0D || d3 > 3600.0D;
  353.             }
  354.         }
  355.  
  356.         /**
  357.          * Returns whether an in-progress EntityAIBase should continue executing
  358.          */
  359.         public boolean continueExecuting()
  360.         {
  361.             return false;
  362.         }
  363.  
  364.         /**
  365.          * Execute a one shot task or start executing a continuous task
  366.          */
  367.         public void startExecuting()
  368.         {
  369.             Random random = this.field_179454_a.getRNG();
  370.             double d0 = this.field_179454_a.posX + (double)((random.nextFloat() * 2.0F - 1.0F) * 16.0F);
  371.             double d1 = this.field_179454_a.posY + (double)((random.nextFloat() * 2.0F - 1.0F) * 16.0F);
  372.             double d2 = this.field_179454_a.posZ + (double)((random.nextFloat() * 2.0F - 1.0F) * 16.0F);
  373.             this.field_179454_a.getMoveHelper().setMoveTo(d0, d1, d2, 1.0D);
  374.         }
  375.     }
  376.  
  377.     class GhastMoveHelper extends EntityMoveHelper
  378.     {
  379.         private EntityGhast field_179927_g = EntityGhast.this;
  380.         private int field_179928_h;
  381.         private static final String __OBFID = "CL_00002216";
  382.  
  383.         public GhastMoveHelper()
  384.         {
  385.             super(EntityGhast.this);
  386.         }
  387.  
  388.         public void onUpdateMoveHelper()
  389.         {
  390.             if (this.update)
  391.             {
  392.                 double d0 = this.posX - this.field_179927_g.posX;
  393.                 double d1 = this.posY - this.field_179927_g.posY;
  394.                 double d2 = this.posZ - this.field_179927_g.posZ;
  395.                 double d3 = d0 * d0 + d1 * d1 + d2 * d2;
  396.  
  397.                 if (this.field_179928_h-- <= 0)
  398.                 {
  399.                     this.field_179928_h += this.field_179927_g.getRNG().nextInt(5) + 2;
  400.                     d3 = (double)MathHelper.sqrt_double(d3);
  401.  
  402.                     if (this.func_179926_b(this.posX, this.posY, this.posZ, d3))
  403.                     {
  404.                         this.field_179927_g.motionX += d0 / d3 * 0.1D;
  405.                         this.field_179927_g.motionY += d1 / d3 * 0.1D;
  406.                         this.field_179927_g.motionZ += d2 / d3 * 0.1D;
  407.                     }
  408.                     else
  409.                     {
  410.                         this.update = false;
  411.                     }
  412.                 }
  413.             }
  414.         }
  415.  
  416.         private boolean func_179926_b(double p_179926_1_, double p_179926_3_, double p_179926_5_, double p_179926_7_)
  417.         {
  418.             double d4 = (p_179926_1_ - this.field_179927_g.posX) / p_179926_7_;
  419.             double d5 = (p_179926_3_ - this.field_179927_g.posY) / p_179926_7_;
  420.             double d6 = (p_179926_5_ - this.field_179927_g.posZ) / p_179926_7_;
  421.             AxisAlignedBB axisalignedbb = this.field_179927_g.getEntityBoundingBox();
  422.  
  423.             for (int i = 1; (double)i < p_179926_7_; ++i)
  424.             {
  425.                 axisalignedbb = axisalignedbb.offset(d4, d5, d6);
  426.  
  427.                 if (!this.field_179927_g.worldObj.getCollidingBoundingBoxes(this.field_179927_g, axisalignedbb).isEmpty())
  428.                 {
  429.                     return false;
  430.                 }
  431.             }
  432.  
  433.             return true;
  434.         }
  435.     }
  436. }
Advertisement
Add Comment
Please, Sign In to add comment