| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import net.minecraft.block.material.Material;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.entity.EntityLivingBase;
|
| 7 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 8 | import net.minecraft.entity.ai.EntityAIBase;
|
| 9 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 10 | import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
|
| 11 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 12 | import net.minecraft.entity.ai.EntityAIWander;
|
| 13 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 14 | import net.minecraft.entity.ai.EntityLookHelper;
|
| 15 | import net.minecraft.entity.ai.EntityMoveHelper;
|
| 16 | import net.minecraft.entity.passive.EntitySquid;
|
| 17 | import net.minecraft.entity.player.EntityPlayer;
|
| 18 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 19 | import net.minecraft.entity.projectile.EntityFishHook;
|
| 20 | import net.minecraft.init.Blocks;
|
| 21 | import net.minecraft.init.Items;
|
| 22 | import net.minecraft.item.ItemFishFood;
|
| 23 | import net.minecraft.item.ItemStack;
|
| 24 | import net.minecraft.nbt.NBTTagCompound;
|
| 25 | import net.minecraft.network.play.server.S2BPacketChangeGameState;
|
| 26 | import net.minecraft.pathfinding.PathNavigate;
|
| 27 | import net.minecraft.pathfinding.PathNavigateSwimmer;
|
| 28 | import net.minecraft.potion.Potion;
|
| 29 | import net.minecraft.potion.PotionEffect;
|
| 30 | import net.minecraft.util.BlockPos;
|
| 31 | import net.minecraft.util.DamageSource;
|
| 32 | import net.minecraft.util.EnumParticleTypes;
|
| 33 | import net.minecraft.util.MathHelper;
|
| 34 | import net.minecraft.util.Vec3;
|
| 35 | import net.minecraft.util.WeightedRandom;
|
| 36 | import net.minecraft.util.WeightedRandomFishable;
|
| 37 | import net.minecraft.world.EnumDifficulty;
|
| 38 | import net.minecraft.world.World;
|
| 39 |
|
| 40 | public class EntityGuardian extends EntityMob
|
| 41 | {
|
| 42 | private float field_175482_b;
|
| 43 | private float field_175484_c;
|
| 44 | private float field_175483_bk;
|
| 45 | private float field_175485_bl;
|
| 46 | private float field_175486_bm;
|
| 47 | private EntityLivingBase targetedEntity;
|
| 48 | private int field_175479_bo;
|
| 49 | private boolean field_175480_bp;
|
| 50 | private EntityAIWander wander;
|
| 51 |
|
| 52 | public EntityGuardian(World worldIn)
|
| 53 | {
|
| 54 | super(worldIn);
|
| 55 | this.experienceValue = 10;
|
| 56 | this.setSize(0.85F, 0.85F);
|
| 57 | this.tasks.addTask(4, new EntityGuardian.AIGuardianAttack(this));
|
| 58 | EntityAIMoveTowardsRestriction entityaimovetowardsrestriction;
|
| 59 | this.tasks.addTask(5, entityaimovetowardsrestriction = new EntityAIMoveTowardsRestriction(this, 1.0D));
|
| 60 | this.tasks.addTask(7, this.wander = new EntityAIWander(this, 1.0D, 80));
|
| 61 | this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
| 62 | this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityGuardian.class, 12.0F, 0.01F));
|
| 63 | this.tasks.addTask(9, new EntityAILookIdle(this));
|
| 64 | this.wander.setMutexBits(3);
|
| 65 | entityaimovetowardsrestriction.setMutexBits(3);
|
| 66 | this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityLivingBase.class, 10, true, false, new EntityGuardian.GuardianTargetSelector(this)));
|
| 67 | this.moveHelper = new EntityGuardian.GuardianMoveHelper(this);
|
| 68 | this.field_175484_c = this.field_175482_b = this.rand.nextFloat();
|
| 69 | }
|
| 70 |
|
| 71 | protected void applyEntityAttributes()
|
| 72 | {
|
| 73 | super.applyEntityAttributes();
|
| 74 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D);
|
| 75 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
|
| 76 | this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(16.0D);
|
| 77 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(30.0D);
|
| 78 | }
|
| 79 |
|
| 80 | /**
|
| 81 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 82 | */
|
| 83 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 84 | {
|
| 85 | super.readEntityFromNBT(tagCompund);
|
| 86 | this.setElder(tagCompund.getBoolean("Elder"));
|
| 87 | }
|
| 88 |
|
| 89 | /**
|
| 90 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 91 | */
|
| 92 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 93 | {
|
| 94 | super.writeEntityToNBT(tagCompound);
|
| 95 | tagCompound.setBoolean("Elder", this.isElder());
|
| 96 | }
|
| 97 |
|
| 98 | /**
|
| 99 | * Returns new PathNavigateGround instance
|
| 100 | */
|
| 101 | protected PathNavigate getNewNavigator(World worldIn)
|
| 102 | {
|
| 103 | return new PathNavigateSwimmer(this, worldIn);
|
| 104 | }
|
| 105 |
|
| 106 | protected void entityInit()
|
| 107 | {
|
| 108 | super.entityInit();
|
| 109 | this.dataWatcher.addObject(16, Integer.valueOf(0));
|
| 110 | this.dataWatcher.addObject(17, Integer.valueOf(0));
|
| 111 | }
|
| 112 |
|
| 113 | /**
|
| 114 | * Returns true if given flag is set
|
| 115 | */
|
| 116 | private boolean isSyncedFlagSet(int flagId)
|
| 117 | {
|
| 118 | return (this.dataWatcher.getWatchableObjectInt(16) & flagId) != 0;
|
| 119 | }
|
| 120 |
|
| 121 | /**
|
| 122 | * Sets a flag state "on/off" on both sides (client/server) by using DataWatcher
|
| 123 | */
|
| 124 | private void setSyncedFlag(int flagId, boolean state)
|
| 125 | {
|
| 126 | int i = this.dataWatcher.getWatchableObjectInt(16);
|
| 127 |
|
| 128 | if (state)
|
| 129 | {
|
| 130 | this.dataWatcher.updateObject(16, Integer.valueOf(i | flagId));
|
| 131 | }
|
| 132 | else
|
| 133 | {
|
| 134 | this.dataWatcher.updateObject(16, Integer.valueOf(i & ~flagId));
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | public boolean func_175472_n()
|
| 139 | {
|
| 140 | return this.isSyncedFlagSet(2);
|
| 141 | }
|
| 142 |
|
| 143 | private void func_175476_l(boolean p_175476_1_)
|
| 144 | {
|
| 145 | this.setSyncedFlag(2, p_175476_1_);
|
| 146 | }
|
| 147 |
|
| 148 | public int func_175464_ck()
|
| 149 | {
|
| 150 | return this.isElder() ? 60 : 80;
|
| 151 | }
|
| 152 |
|
| 153 | public boolean isElder()
|
| 154 | {
|
| 155 | return this.isSyncedFlagSet(4);
|
| 156 | }
|
| 157 |
|
| 158 | /**
|
| 159 | * Sets this Guardian to be an elder or not.
|
| 160 | */
|
| 161 | public void setElder(boolean elder)
|
| 162 | {
|
| 163 | this.setSyncedFlag(4, elder);
|
| 164 |
|
| 165 | if (elder)
|
| 166 | {
|
| 167 | this.setSize(1.9975F, 1.9975F);
|
| 168 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
|
| 169 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(8.0D);
|
| 170 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(80.0D);
|
| 171 | this.enablePersistence();
|
| 172 | this.wander.setExecutionChance(400);
|
| 173 | }
|
| 174 | }
|
| 175 |
|
| 176 | public void setElder()
|
| 177 | {
|
| 178 | this.setElder(true);
|
| 179 | this.field_175486_bm = this.field_175485_bl = 1.0F;
|
| 180 | }
|
| 181 |
|
| 182 | private void setTargetedEntity(int entityId)
|
| 183 | {
|
| 184 | this.dataWatcher.updateObject(17, Integer.valueOf(entityId));
|
| 185 | }
|
| 186 |
|
| 187 | public boolean hasTargetedEntity()
|
| 188 | {
|
| 189 | return this.dataWatcher.getWatchableObjectInt(17) != 0;
|
| 190 | }
|
| 191 |
|
| 192 | public EntityLivingBase getTargetedEntity()
|
| 193 | {
|
| 194 | if (!this.hasTargetedEntity())
|
| 195 | {
|
| 196 | return null;
|
| 197 | }
|
| 198 | else if (this.worldObj.isRemote)
|
| 199 | {
|
| 200 | if (this.targetedEntity != null)
|
| 201 | {
|
| 202 | return this.targetedEntity;
|
| 203 | }
|
| 204 | else
|
| 205 | {
|
| 206 | Entity entity = this.worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(17));
|
| 207 |
|
| 208 | if (entity instanceof EntityLivingBase)
|
| 209 | {
|
| 210 | this.targetedEntity = (EntityLivingBase)entity;
|
| 211 | return this.targetedEntity;
|
| 212 | }
|
| 213 | else
|
| 214 | {
|
| 215 | return null;
|
| 216 | }
|
| 217 | }
|
| 218 | }
|
| 219 | else
|
| 220 | {
|
| 221 | return this.getAttackTarget();
|
| 222 | }
|
| 223 | }
|
| 224 |
|
| 225 | public void onDataWatcherUpdate(int dataID)
|
| 226 | {
|
| 227 | super.onDataWatcherUpdate(dataID);
|
| 228 |
|
| 229 | if (dataID == 16)
|
| 230 | {
|
| 231 | if (this.isElder() && this.width < 1.0F)
|
| 232 | {
|
| 233 | this.setSize(1.9975F, 1.9975F);
|
| 234 | }
|
| 235 | }
|
| 236 | else if (dataID == 17)
|
| 237 | {
|
| 238 | this.field_175479_bo = 0;
|
| 239 | this.targetedEntity = null;
|
| 240 | }
|
| 241 | }
|
| 242 |
|
| 243 | /**
|
| 244 | * Get number of ticks, at least during which the living entity will be silent.
|
| 245 | */
|
| 246 | public int getTalkInterval()
|
| 247 | {
|
| 248 | return 160;
|
| 249 | }
|
| 250 |
|
| 251 | /**
|
| 252 | * Returns the sound this mob makes while it's alive.
|
| 253 | */
|
| 254 | protected String getLivingSound()
|
| 255 | {
|
| 256 | return !this.isInWater() ? "mob.guardian.land.idle" : (this.isElder() ? "mob.guardian.elder.idle" : "mob.guardian.idle");
|
| 257 | }
|
| 258 |
|
| 259 | /**
|
| 260 | * Returns the sound this mob makes when it is hurt.
|
| 261 | */
|
| 262 | protected String getHurtSound()
|
| 263 | {
|
| 264 | return !this.isInWater() ? "mob.guardian.land.hit" : (this.isElder() ? "mob.guardian.elder.hit" : "mob.guardian.hit");
|
| 265 | }
|
| 266 |
|
| 267 | /**
|
| 268 | * Returns the sound this mob makes on death.
|
| 269 | */
|
| 270 | protected String getDeathSound()
|
| 271 | {
|
| 272 | return !this.isInWater() ? "mob.guardian.land.death" : (this.isElder() ? "mob.guardian.elder.death" : "mob.guardian.death");
|
| 273 | }
|
| 274 |
|
| 275 | /**
|
| 276 | * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
|
| 277 | * prevent them from trampling crops
|
| 278 | */
|
| 279 | protected boolean canTriggerWalking()
|
| 280 | {
|
| 281 | return false;
|
| 282 | }
|
| 283 |
|
| 284 | public float getEyeHeight()
|
| 285 | {
|
| 286 | return this.height * 0.5F;
|
| 287 | }
|
| 288 |
|
| 289 | public float getBlockPathWeight(BlockPos pos)
|
| 290 | {
|
| 291 | return this.worldObj.getBlockState(pos).getBlock().getMaterial() == Material.water ? 10.0F + this.worldObj.getLightBrightness(pos) - 0.5F : super.getBlockPathWeight(pos);
|
| 292 | }
|
| 293 |
|
| 294 | /**
|
| 295 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 296 | * use this to react to sunlight and start to burn.
|
| 297 | */
|
| 298 | public void onLivingUpdate()
|
| 299 | {
|
| 300 | if (this.worldObj.isRemote)
|
| 301 | {
|
| 302 | this.field_175484_c = this.field_175482_b;
|
| 303 |
|
| 304 | if (!this.isInWater())
|
| 305 | {
|
| 306 | this.field_175483_bk = 2.0F;
|
| 307 |
|
| 308 | if (this.motionY > 0.0D && this.field_175480_bp && !this.isSilent())
|
| 309 | {
|
| 310 | this.worldObj.playSound(this.posX, this.posY, this.posZ, "mob.guardian.flop", 1.0F, 1.0F, false);
|
| 311 | }
|
| 312 |
|
| 313 | this.field_175480_bp = this.motionY < 0.0D && this.worldObj.isBlockNormalCube((new BlockPos(this)).down(), false);
|
| 314 | }
|
| 315 | else if (this.func_175472_n())
|
| 316 | {
|
| 317 | if (this.field_175483_bk < 0.5F)
|
| 318 | {
|
| 319 | this.field_175483_bk = 4.0F;
|
| 320 | }
|
| 321 | else
|
| 322 | {
|
| 323 | this.field_175483_bk += (0.5F - this.field_175483_bk) * 0.1F;
|
| 324 | }
|
| 325 | }
|
| 326 | else
|
| 327 | {
|
| 328 | this.field_175483_bk += (0.125F - this.field_175483_bk) * 0.2F;
|
| 329 | }
|
| 330 |
|
| 331 | this.field_175482_b += this.field_175483_bk;
|
| 332 | this.field_175486_bm = this.field_175485_bl;
|
| 333 |
|
| 334 | if (!this.isInWater())
|
| 335 | {
|
| 336 | this.field_175485_bl = this.rand.nextFloat();
|
| 337 | }
|
| 338 | else if (this.func_175472_n())
|
| 339 | {
|
| 340 | this.field_175485_bl += (0.0F - this.field_175485_bl) * 0.25F;
|
| 341 | }
|
| 342 | else
|
| 343 | {
|
| 344 | this.field_175485_bl += (1.0F - this.field_175485_bl) * 0.06F;
|
| 345 | }
|
| 346 |
|
| 347 | if (this.func_175472_n() && this.isInWater())
|
| 348 | {
|
| 349 | Vec3 vec3 = this.getLook(0.0F);
|
| 350 |
|
| 351 | for (int i = 0; i < 2; ++i)
|
| 352 | {
|
| 353 | this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3.xCoord * 1.5D, this.posY + this.rand.nextDouble() * (double)this.height - vec3.yCoord * 1.5D, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3.zCoord * 1.5D, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 354 | }
|
| 355 | }
|
| 356 |
|
| 357 | if (this.hasTargetedEntity())
|
| 358 | {
|
| 359 | if (this.field_175479_bo < this.func_175464_ck())
|
| 360 | {
|
| 361 | ++this.field_175479_bo;
|
| 362 | }
|
| 363 |
|
| 364 | EntityLivingBase entitylivingbase = this.getTargetedEntity();
|
| 365 |
|
| 366 | if (entitylivingbase != null)
|
| 367 | {
|
| 368 | this.getLookHelper().setLookPositionWithEntity(entitylivingbase, 90.0F, 90.0F);
|
| 369 | this.getLookHelper().onUpdateLook();
|
| 370 | double d5 = (double)this.func_175477_p(0.0F);
|
| 371 | double d0 = entitylivingbase.posX - this.posX;
|
| 372 | double d1 = entitylivingbase.posY + (double)(entitylivingbase.height * 0.5F) - (this.posY + (double)this.getEyeHeight());
|
| 373 | double d2 = entitylivingbase.posZ - this.posZ;
|
| 374 | double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
|
| 375 | d0 = d0 / d3;
|
| 376 | d1 = d1 / d3;
|
| 377 | d2 = d2 / d3;
|
| 378 | double d4 = this.rand.nextDouble();
|
| 379 |
|
| 380 | while (d4 < d3)
|
| 381 | {
|
| 382 | d4 += 1.8D - d5 + this.rand.nextDouble() * (1.7D - d5);
|
| 383 | this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + d0 * d4, this.posY + d1 * d4 + (double)this.getEyeHeight(), this.posZ + d2 * d4, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 384 | }
|
| 385 | }
|
| 386 | }
|
| 387 | }
|
| 388 |
|
| 389 | if (this.inWater)
|
| 390 | {
|
| 391 | this.setAir(300);
|
| 392 | }
|
| 393 | else if (this.onGround)
|
| 394 | {
|
| 395 | this.motionY += 0.5D;
|
| 396 | this.motionX += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F);
|
| 397 | this.motionZ += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F);
|
| 398 | this.rotationYaw = this.rand.nextFloat() * 360.0F;
|
| 399 | this.onGround = false;
|
| 400 | this.isAirBorne = true;
|
| 401 | }
|
| 402 |
|
| 403 | if (this.hasTargetedEntity())
|
| 404 | {
|
| 405 | this.rotationYaw = this.rotationYawHead;
|
| 406 | }
|
| 407 |
|
| 408 | super.onLivingUpdate();
|
| 409 | }
|
| 410 |
|
| 411 | public float func_175471_a(float p_175471_1_)
|
| 412 | {
|
| 413 | return this.field_175484_c + (this.field_175482_b - this.field_175484_c) * p_175471_1_;
|
| 414 | }
|
| 415 |
|
| 416 | public float func_175469_o(float p_175469_1_)
|
| 417 | {
|
| 418 | return this.field_175486_bm + (this.field_175485_bl - this.field_175486_bm) * p_175469_1_;
|
| 419 | }
|
| 420 |
|
| 421 | public float func_175477_p(float p_175477_1_)
|
| 422 | {
|
| 423 | return ((float)this.field_175479_bo + p_175477_1_) / (float)this.func_175464_ck();
|
| 424 | }
|
| 425 |
|
| 426 | protected void updateAITasks()
|
| 427 | {
|
| 428 | super.updateAITasks();
|
| 429 |
|
| 430 | if (this.isElder())
|
| 431 | {
|
| 432 | int i = 1200;
|
| 433 | int j = 1200;
|
| 434 | int k = 6000;
|
| 435 | int l = 2;
|
| 436 |
|
| 437 | if ((this.ticksExisted + this.getEntityId()) % 1200 == 0)
|
| 438 | {
|
| 439 | Potion potion = Potion.digSlowdown;
|
| 440 |
|
| 441 | for (EntityPlayerMP entityplayermp : this.worldObj.getPlayers(EntityPlayerMP.class, new Predicate<EntityPlayerMP>()
|
| 442 | {
|
| 443 | public boolean apply(EntityPlayerMP p_apply_1_)
|
| 444 | {
|
| 445 | return EntityGuardian.this.getDistanceSqToEntity(p_apply_1_) < 2500.0D && p_apply_1_.theItemInWorldManager.survivalOrAdventure();
|
| 446 | }
|
| 447 | }))
|
| 448 | {
|
| 449 | if (!entityplayermp.isPotionActive(potion) || entityplayermp.getActivePotionEffect(potion).getAmplifier() < 2 || entityplayermp.getActivePotionEffect(potion).getDuration() < 1200)
|
| 450 | {
|
| 451 | entityplayermp.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(10, 0.0F));
|
| 452 | entityplayermp.addPotionEffect(new PotionEffect(potion.id, 6000, 2));
|
| 453 | }
|
| 454 | }
|
| 455 | }
|
| 456 |
|
| 457 | if (!this.hasHome())
|
| 458 | {
|
| 459 | this.setHomePosAndDistance(new BlockPos(this), 16);
|
| 460 | }
|
| 461 | }
|
| 462 | }
|
| 463 |
|
| 464 | /**
|
| 465 | * Drop 0-2 items of this living's type
|
| 466 | *
|
| 467 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 468 | * or tameable)
|
| 469 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 470 | */
|
| 471 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 472 | {
|
| 473 | int i = this.rand.nextInt(3) + this.rand.nextInt(lootingModifier + 1);
|
| 474 |
|
| 475 | if (i > 0)
|
| 476 | {
|
| 477 | this.entityDropItem(new ItemStack(Items.prismarine_shard, i, 0), 1.0F);
|
| 478 | }
|
| 479 |
|
| 480 | if (this.rand.nextInt(3 + lootingModifier) > 1)
|
| 481 | {
|
| 482 | this.entityDropItem(new ItemStack(Items.fish, 1, ItemFishFood.FishType.COD.getMetadata()), 1.0F);
|
| 483 | }
|
| 484 | else if (this.rand.nextInt(3 + lootingModifier) > 1)
|
| 485 | {
|
| 486 | this.entityDropItem(new ItemStack(Items.prismarine_crystals, 1, 0), 1.0F);
|
| 487 | }
|
| 488 |
|
| 489 | if (wasRecentlyHit && this.isElder())
|
| 490 | {
|
| 491 | this.entityDropItem(new ItemStack(Blocks.sponge, 1, 1), 1.0F);
|
| 492 | }
|
| 493 | }
|
| 494 |
|
| 495 | /**
|
| 496 | * Causes this Entity to drop a random item.
|
| 497 | */
|
| 498 | protected void addRandomDrop()
|
| 499 | {
|
| 500 | ItemStack itemstack = ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, EntityFishHook.func_174855_j())).getItemStack(this.rand);
|
| 501 | this.entityDropItem(itemstack, 1.0F);
|
| 502 | }
|
| 503 |
|
| 504 | /**
|
| 505 | * Checks to make sure the light is not too bright where the mob is spawning
|
| 506 | */
|
| 507 | protected boolean isValidLightLevel()
|
| 508 | {
|
| 509 | return true;
|
| 510 | }
|
| 511 |
|
| 512 | /**
|
| 513 | * Checks that the entity is not colliding with any blocks / liquids
|
| 514 | */
|
| 515 | public boolean isNotColliding()
|
| 516 | {
|
| 517 | return this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty();
|
| 518 | }
|
| 519 |
|
| 520 | /**
|
| 521 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 522 | */
|
| 523 | public boolean getCanSpawnHere()
|
| 524 | {
|
| 525 | return (this.rand.nextInt(20) == 0 || !this.worldObj.canBlockSeeSky(new BlockPos(this))) && super.getCanSpawnHere();
|
| 526 | }
|
| 527 |
|
| 528 | /**
|
| 529 | * Called when the entity is attacked.
|
| 530 | */
|
| 531 | public boolean attackEntityFrom(DamageSource source, float amount)
|
| 532 | {
|
| 533 | if (!this.func_175472_n() && !source.isMagicDamage() && source.getSourceOfDamage() instanceof EntityLivingBase)
|
| 534 | {
|
| 535 | EntityLivingBase entitylivingbase = (EntityLivingBase)source.getSourceOfDamage();
|
| 536 |
|
| 537 | if (!source.isExplosion())
|
| 538 | {
|
| 539 | entitylivingbase.attackEntityFrom(DamageSource.causeThornsDamage(this), 2.0F);
|
| 540 | entitylivingbase.playSound("damage.thorns", 0.5F, 1.0F);
|
| 541 | }
|
| 542 | }
|
| 543 |
|
| 544 | this.wander.makeUpdate();
|
| 545 | return super.attackEntityFrom(source, amount);
|
| 546 | }
|
| 547 |
|
| 548 | /**
|
| 549 | * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently
|
| 550 | * use in wolves.
|
| 551 | */
|
| 552 | public int getVerticalFaceSpeed()
|
| 553 | {
|
| 554 | return 180;
|
| 555 | }
|
| 556 |
|
| 557 | /**
|
| 558 | * Moves the entity based on the specified heading. Args: strafe, forward
|
| 559 | */
|
| 560 | public void moveEntityWithHeading(float strafe, float forward)
|
| 561 | {
|
| 562 | if (this.isServerWorld())
|
| 563 | {
|
| 564 | if (this.isInWater())
|
| 565 | {
|
| 566 | this.moveFlying(strafe, forward, 0.1F);
|
| 567 | this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
| 568 | this.motionX *= 0.8999999761581421D;
|
| 569 | this.motionY *= 0.8999999761581421D;
|
| 570 | this.motionZ *= 0.8999999761581421D;
|
| 571 |
|
| 572 | if (!this.func_175472_n() && this.getAttackTarget() == null)
|
| 573 | {
|
| 574 | this.motionY -= 0.005D;
|
| 575 | }
|
| 576 | }
|
| 577 | else
|
| 578 | {
|
| 579 | super.moveEntityWithHeading(strafe, forward);
|
| 580 | }
|
| 581 | }
|
| 582 | else
|
| 583 | {
|
| 584 | super.moveEntityWithHeading(strafe, forward);
|
| 585 | }
|
| 586 | }
|
| 587 |
|
| 588 | static class AIGuardianAttack extends EntityAIBase
|
| 589 | {
|
| 590 | private EntityGuardian theEntity;
|
| 591 | private int tickCounter;
|
| 592 |
|
| 593 | public AIGuardianAttack(EntityGuardian guardian)
|
| 594 | {
|
| 595 | this.theEntity = guardian;
|
| 596 | this.setMutexBits(3);
|
| 597 | }
|
| 598 |
|
| 599 | public boolean shouldExecute()
|
| 600 | {
|
| 601 | EntityLivingBase entitylivingbase = this.theEntity.getAttackTarget();
|
| 602 | return entitylivingbase != null && entitylivingbase.isEntityAlive();
|
| 603 | }
|
| 604 |
|
| 605 | public boolean continueExecuting()
|
| 606 | {
|
| 607 | return super.continueExecuting() && (this.theEntity.isElder() || this.theEntity.getDistanceSqToEntity(this.theEntity.getAttackTarget()) > 9.0D);
|
| 608 | }
|
| 609 |
|
| 610 | public void startExecuting()
|
| 611 | {
|
| 612 | this.tickCounter = -10;
|
| 613 | this.theEntity.getNavigator().clearPathEntity();
|
| 614 | this.theEntity.getLookHelper().setLookPositionWithEntity(this.theEntity.getAttackTarget(), 90.0F, 90.0F);
|
| 615 | this.theEntity.isAirBorne = true;
|
| 616 | }
|
| 617 |
|
| 618 | public void resetTask()
|
| 619 | {
|
| 620 | this.theEntity.setTargetedEntity(0);
|
| 621 | this.theEntity.setAttackTarget((EntityLivingBase)null);
|
| 622 | this.theEntity.wander.makeUpdate();
|
| 623 | }
|
| 624 |
|
| 625 | public void updateTask()
|
| 626 | {
|
| 627 | EntityLivingBase entitylivingbase = this.theEntity.getAttackTarget();
|
| 628 | this.theEntity.getNavigator().clearPathEntity();
|
| 629 | this.theEntity.getLookHelper().setLookPositionWithEntity(entitylivingbase, 90.0F, 90.0F);
|
| 630 |
|
| 631 | if (!this.theEntity.canEntityBeSeen(entitylivingbase))
|
| 632 | {
|
| 633 | this.theEntity.setAttackTarget((EntityLivingBase)null);
|
| 634 | }
|
| 635 | else
|
| 636 | {
|
| 637 | ++this.tickCounter;
|
| 638 |
|
| 639 | if (this.tickCounter == 0)
|
| 640 | {
|
| 641 | this.theEntity.setTargetedEntity(this.theEntity.getAttackTarget().getEntityId());
|
| 642 | this.theEntity.worldObj.setEntityState(this.theEntity, (byte)21);
|
| 643 | }
|
| 644 | else if (this.tickCounter >= this.theEntity.func_175464_ck())
|
| 645 | {
|
| 646 | float f = 1.0F;
|
| 647 |
|
| 648 | if (this.theEntity.worldObj.getDifficulty() == EnumDifficulty.HARD)
|
| 649 | {
|
| 650 | f += 2.0F;
|
| 651 | }
|
| 652 |
|
| 653 | if (this.theEntity.isElder())
|
| 654 | {
|
| 655 | f += 2.0F;
|
| 656 | }
|
| 657 |
|
| 658 | entitylivingbase.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this.theEntity, this.theEntity), f);
|
| 659 | entitylivingbase.attackEntityFrom(DamageSource.causeMobDamage(this.theEntity), (float)this.theEntity.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue());
|
| 660 | this.theEntity.setAttackTarget((EntityLivingBase)null);
|
| 661 | }
|
| 662 | else if (this.tickCounter >= 60 && this.tickCounter % 20 == 0)
|
| 663 | {
|
| 664 | ;
|
| 665 | }
|
| 666 |
|
| 667 | super.updateTask();
|
| 668 | }
|
| 669 | }
|
| 670 | }
|
| 671 |
|
| 672 | static class GuardianMoveHelper extends EntityMoveHelper
|
| 673 | {
|
| 674 | private EntityGuardian entityGuardian;
|
| 675 |
|
| 676 | public GuardianMoveHelper(EntityGuardian guardian)
|
| 677 | {
|
| 678 | super(guardian);
|
| 679 | this.entityGuardian = guardian;
|
| 680 | }
|
| 681 |
|
| 682 | public void onUpdateMoveHelper()
|
| 683 | {
|
| 684 | if (this.update && !this.entityGuardian.getNavigator().noPath())
|
| 685 | {
|
| 686 | double d0 = this.posX - this.entityGuardian.posX;
|
| 687 | double d1 = this.posY - this.entityGuardian.posY;
|
| 688 | double d2 = this.posZ - this.entityGuardian.posZ;
|
| 689 | double d3 = d0 * d0 + d1 * d1 + d2 * d2;
|
| 690 | d3 = (double)MathHelper.sqrt_double(d3);
|
| 691 | d1 = d1 / d3;
|
| 692 | float f = (float)(MathHelper.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
|
| 693 | this.entityGuardian.rotationYaw = this.limitAngle(this.entityGuardian.rotationYaw, f, 30.0F);
|
| 694 | this.entityGuardian.renderYawOffset = this.entityGuardian.rotationYaw;
|
| 695 | float f1 = (float)(this.speed * this.entityGuardian.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
|
| 696 | this.entityGuardian.setAIMoveSpeed(this.entityGuardian.getAIMoveSpeed() + (f1 - this.entityGuardian.getAIMoveSpeed()) * 0.125F);
|
| 697 | double d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.5D) * 0.05D;
|
| 698 | double d5 = Math.cos((double)(this.entityGuardian.rotationYaw * (float)Math.PI / 180.0F));
|
| 699 | double d6 = Math.sin((double)(this.entityGuardian.rotationYaw * (float)Math.PI / 180.0F));
|
| 700 | this.entityGuardian.motionX += d4 * d5;
|
| 701 | this.entityGuardian.motionZ += d4 * d6;
|
| 702 | d4 = Math.sin((double)(this.entityGuardian.ticksExisted + this.entityGuardian.getEntityId()) * 0.75D) * 0.05D;
|
| 703 | this.entityGuardian.motionY += d4 * (d6 + d5) * 0.25D;
|
| 704 | this.entityGuardian.motionY += (double)this.entityGuardian.getAIMoveSpeed() * d1 * 0.1D;
|
| 705 | EntityLookHelper entitylookhelper = this.entityGuardian.getLookHelper();
|
| 706 | double d7 = this.entityGuardian.posX + d0 / d3 * 2.0D;
|
| 707 | double d8 = (double)this.entityGuardian.getEyeHeight() + this.entityGuardian.posY + d1 / d3 * 1.0D;
|
| 708 | double d9 = this.entityGuardian.posZ + d2 / d3 * 2.0D;
|
| 709 | double d10 = entitylookhelper.getLookPosX();
|
| 710 | double d11 = entitylookhelper.getLookPosY();
|
| 711 | double d12 = entitylookhelper.getLookPosZ();
|
| 712 |
|
| 713 | if (!entitylookhelper.getIsLooking())
|
| 714 | {
|
| 715 | d10 = d7;
|
| 716 | d11 = d8;
|
| 717 | d12 = d9;
|
| 718 | }
|
| 719 |
|
| 720 | this.entityGuardian.getLookHelper().setLookPosition(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F);
|
| 721 | this.entityGuardian.func_175476_l(true);
|
| 722 | }
|
| 723 | else
|
| 724 | {
|
| 725 | this.entityGuardian.setAIMoveSpeed(0.0F);
|
| 726 | this.entityGuardian.func_175476_l(false);
|
| 727 | }
|
| 728 | }
|
| 729 | }
|
| 730 |
|
| 731 | static class GuardianTargetSelector implements Predicate<EntityLivingBase>
|
| 732 | {
|
| 733 | private EntityGuardian parentEntity;
|
| 734 |
|
| 735 | public GuardianTargetSelector(EntityGuardian guardian)
|
| 736 | {
|
| 737 | this.parentEntity = guardian;
|
| 738 | }
|
| 739 |
|
| 740 | public boolean apply(EntityLivingBase p_apply_1_)
|
| 741 | {
|
| 742 | return (p_apply_1_ instanceof EntityPlayer || p_apply_1_ instanceof EntitySquid) && p_apply_1_.getDistanceSqToEntity(this.parentEntity) > 9.0D;
|
| 743 | }
|
| 744 | }
|
| 745 | }
|
| 746 |
|