@Override public void doAttack(int ticks, EntityFinalBoss boss, World w, Random rand) { if (ticks % 5 == 0) { Vec3 start = Vec3.createVectorHelper(boss.posX, boss.posY + 0.5, boss.posZ); AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox( start.xCoord - 50, start.yCoord - 50, start.zCoord - 50, start.xCoord + 50, start.yCoord + 50, start.zCoord + 50); for (Object o : w.getEntitiesWithinAABB(EntityPlayer.class, bounds)) { EntityPlayer pl = (EntityPlayer) o; // For some reason, the server's position is normal, but // the client's position is 1.62 higher Vec3 end = Vec3.createVectorHelper(pl.posX, pl.posY + (w.isRemote ? 0 : 1.62), pl.posZ); Vec3 vec = start.subtract(end).normalize(); vec.xCoord /= 2; vec.yCoord /= 2; vec.zCoord /= 2; double lastDistSq = -1; Vec3 pos = Vec3.createVectorHelper(start.xCoord, start.yCoord, start.zCoord); boolean hit = true; while (true) { pos = pos.addVector(vec.xCoord, vec.yCoord, vec.zCoord); if (w.getBlock( (int) Math.floor(pos.xCoord), (int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord)) .isOpaqueCube()) { hit = false; break; } if (lastDistSq >= 0 && pos.squareDistanceTo(end) > lastDistSq) { break; } w.spawnParticle("witchMagic", pos.xCoord, pos.yCoord, pos.zCoord, 0, 0, 0); lastDistSq = pos.squareDistanceTo(end); } if (hit) { pl.attackEntityFrom( DamageSource.causeMobDamage(boss).setDamageBypassesArmor(), pl.getMaxHealth() / 4); } } } }
private void pathFollow() { Vec3 var1 = this.getEntityPosition(); int var2 = this.currentPath.getCurrentPathLength(); for (int var3 = this.currentPath.getCurrentPathIndex(); var3 < this.currentPath.getCurrentPathLength(); ++var3) { if (this.currentPath.getPathPointFromIndex(var3).yCoord != (int) var1.yCoord) { var2 = var3; break; } } float var8 = this.theEntity.width * this.theEntity.width; int var4; for (var4 = this.currentPath.getCurrentPathIndex(); var4 < var2; ++var4) { if (var1.squareDistanceTo(this.currentPath.getVectorFromIndex(this.theEntity, var4)) < (double) var8) { this.currentPath.setCurrentPathIndex(var4 + 1); } } var4 = MathHelper.ceiling_float_int(this.theEntity.width); int var5 = (int) this.theEntity.height + 1; int var6 = var4; for (int var7 = var2 - 1; var7 >= this.currentPath.getCurrentPathIndex(); --var7) { if (this.isDirectPathBetweenPoints( var1, this.currentPath.getVectorFromIndex(this.theEntity, var7), var4, var5, var6)) { this.currentPath.setCurrentPathIndex(var7); break; } } if (this.totalTicks - this.ticksAtLastPos > 100) { if (var1.squareDistanceTo(this.lastPosCheck) < 2.25D) { this.clearPathEntity(); } this.ticksAtLastPos = this.totalTicks; this.lastPosCheck.xCoord = var1.xCoord; this.lastPosCheck.yCoord = var1.yCoord; this.lastPosCheck.zCoord = var1.zCoord; } }
private static boolean canOperateOnMagnet(Vec3 magnetPos, Vec3 turtlePos) { return magnetPos.squareDistanceTo(turtlePos) <= 1.5 * 1.5; }
public MovingObjectPosition rayTraceBound( AxisAlignedBB bound, int i, int j, int k, Vec3 player, Vec3 view) { Vec3 minX = player.getIntermediateWithXValue(view, bound.minX); Vec3 maxX = player.getIntermediateWithXValue(view, bound.maxX); Vec3 minY = player.getIntermediateWithYValue(view, bound.minY); Vec3 maxY = player.getIntermediateWithYValue(view, bound.maxY); Vec3 minZ = player.getIntermediateWithZValue(view, bound.minZ); Vec3 maxZ = player.getIntermediateWithZValue(view, bound.maxZ); if (!this.isVecInsideYZBounds(bound, minX)) { minX = null; } if (!this.isVecInsideYZBounds(bound, maxX)) { maxX = null; } if (!this.isVecInsideXZBounds(bound, minY)) { minY = null; } if (!this.isVecInsideXZBounds(bound, maxY)) { maxY = null; } if (!this.isVecInsideXYBounds(bound, minZ)) { minZ = null; } if (!isVecInsideXYBounds(bound, maxZ)) { maxZ = null; } Vec3 tracedBound = null; if (minX != null && (tracedBound == null || player.squareDistanceTo(minX) < player.squareDistanceTo(tracedBound))) { tracedBound = minX; } if (maxX != null && (tracedBound == null || player.squareDistanceTo(maxX) < player.squareDistanceTo(tracedBound))) { tracedBound = maxX; } if (minY != null && (tracedBound == null || player.squareDistanceTo(minY) < player.squareDistanceTo(tracedBound))) { tracedBound = minY; } if (maxY != null && (tracedBound == null || player.squareDistanceTo(maxY) < player.squareDistanceTo(tracedBound))) { tracedBound = maxY; } if (minZ != null && (tracedBound == null || player.squareDistanceTo(minZ) < player.squareDistanceTo(tracedBound))) { tracedBound = minZ; } if (maxZ != null && (tracedBound == null || player.squareDistanceTo(maxZ) < player.squareDistanceTo(tracedBound))) { tracedBound = maxZ; } if (tracedBound == null) { return null; } byte side = -1; if (tracedBound == minX) { side = 4; } if (tracedBound == maxX) { side = 5; } if (tracedBound == minY) { side = 0; } if (tracedBound == maxY) { side = 1; } if (tracedBound == minZ) { side = 2; } if (tracedBound == maxZ) { side = 3; } return new MovingObjectPosition(i, j, k, side, tracedBound); }
private static boolean canOperateOnMagnet(Vec3 magnetPos, Vec3 turtlePos) { return magnetPos.squareDistanceTo(turtlePos) <= Config.turtleMagnetRangeDeactivate * Config.turtleMagnetRangeDeactivate; }
/** Called to update the entity's position/logic. */ public void onUpdate() { super.onUpdate(); if (this.fishPosRotationIncrements > 0) { double d7 = this.posX + (this.fishX - this.posX) / (double) this.fishPosRotationIncrements; double d8 = this.posY + (this.fishY - this.posY) / (double) this.fishPosRotationIncrements; double d9 = this.posZ + (this.fishZ - this.posZ) / (double) this.fishPosRotationIncrements; double d1 = MathHelper.wrapAngleTo180_double(this.fishYaw - (double) this.rotationYaw); this.rotationYaw = (float) ((double) this.rotationYaw + d1 / (double) this.fishPosRotationIncrements); this.rotationPitch = (float) ((double) this.rotationPitch + (this.fishPitch - (double) this.rotationPitch) / (double) this.fishPosRotationIncrements); --this.fishPosRotationIncrements; this.setPosition(d7, d8, d9); this.setRotation(this.rotationYaw, this.rotationPitch); } else { if (!this.worldObj.isRemote) { ItemStack itemstack = this.angler.getCurrentEquippedItem(); if (this.angler.isDead || !this.angler.isEntityAlive() || itemstack == null || itemstack.getItem() != Items.fishing_rod || this.getDistanceSqToEntity(this.angler) > 1024.0D) { this.setDead(); this.angler.fishEntity = null; return; } if (this.caughtEntity != null) { if (!this.caughtEntity.isDead) { this.posX = this.caughtEntity.posX; double d17 = (double) this.caughtEntity.height; this.posY = this.caughtEntity.getEntityBoundingBox().minY + d17 * 0.8D; this.posZ = this.caughtEntity.posZ; return; } this.caughtEntity = null; } } if (this.shake > 0) { --this.shake; } if (this.inGround) { if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile) { ++this.ticksInGround; if (this.ticksInGround == 1200) { this.setDead(); } return; } this.inGround = false; this.motionX *= (double) (this.rand.nextFloat() * 0.2F); this.motionY *= (double) (this.rand.nextFloat() * 0.2F); this.motionZ *= (double) (this.rand.nextFloat() * 0.2F); this.ticksInGround = 0; this.ticksInAir = 0; } else { ++this.ticksInAir; } Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ); Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3); vec31 = new Vec3(this.posX, this.posY, this.posZ); vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec3 = new Vec3( movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity( this, this.getEntityBoundingBox() .addCoord(this.motionX, this.motionY, this.motionZ) .expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; for (int i = 0; i < list.size(); ++i) { Entity entity1 = (Entity) list.get(i); if (entity1.canBeCollidedWith() && (entity1 != this.angler || this.ticksInAir >= 5)) { float f = 0.3F; AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double) f, (double) f, (double) f); MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec31, vec3); if (movingobjectposition1 != null) { double d2 = vec31.squareDistanceTo(movingobjectposition1.hitVec); if (d2 < d0 || d0 == 0.0D) { entity = entity1; d0 = d2; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { if (movingobjectposition.entityHit.attackEntityFrom( DamageSource.causeThrownDamage(this, this.angler), 0.0F)) { this.caughtEntity = movingobjectposition.entityHit; } } else { this.inGround = true; } } if (!this.inGround) { this.moveEntity(this.motionX, this.motionY, this.motionZ); float f5 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float) (MathHelper.func_181159_b(this.motionX, this.motionZ) * 180.0D / Math.PI); for (this.rotationPitch = (float) (MathHelper.func_181159_b(this.motionY, (double) f5) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f6 = 0.92F; if (this.onGround || this.isCollidedHorizontally) { f6 = 0.5F; } int j = 5; double d10 = 0.0D; for (int k = 0; k < j; ++k) { AxisAlignedBB axisalignedbb1 = this.getEntityBoundingBox(); double d3 = axisalignedbb1.maxY - axisalignedbb1.minY; double d4 = axisalignedbb1.minY + d3 * (double) k / (double) j; double d5 = axisalignedbb1.minY + d3 * (double) (k + 1) / (double) j; AxisAlignedBB axisalignedbb2 = new AxisAlignedBB( axisalignedbb1.minX, d4, axisalignedbb1.minZ, axisalignedbb1.maxX, d5, axisalignedbb1.maxZ); if (this.worldObj.isAABBInMaterial(axisalignedbb2, Material.water)) { d10 += 1.0D / (double) j; } } if (!this.worldObj.isRemote && d10 > 0.0D) { WorldServer worldserver = (WorldServer) this.worldObj; int l = 1; BlockPos blockpos = (new BlockPos(this)).up(); if (this.rand.nextFloat() < 0.25F && this.worldObj.canLightningStrike(blockpos)) { l = 2; } if (this.rand.nextFloat() < 0.5F && !this.worldObj.canSeeSky(blockpos)) { --l; } if (this.ticksCatchable > 0) { --this.ticksCatchable; if (this.ticksCatchable <= 0) { this.ticksCaughtDelay = 0; this.ticksCatchableDelay = 0; } } else if (this.ticksCatchableDelay > 0) { this.ticksCatchableDelay -= l; if (this.ticksCatchableDelay <= 0) { this.motionY -= 0.20000000298023224D; this.playSound( "random.splash", 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F); float f8 = (float) MathHelper.floor_double(this.getEntityBoundingBox().minY); worldserver.spawnParticle( EnumParticleTypes.WATER_BUBBLE, this.posX, (double) (f8 + 1.0F), this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D, new int[0]); worldserver.spawnParticle( EnumParticleTypes.WATER_WAKE, this.posX, (double) (f8 + 1.0F), this.posZ, (int) (1.0F + this.width * 20.0F), (double) this.width, 0.0D, (double) this.width, 0.20000000298023224D, new int[0]); this.ticksCatchable = MathHelper.getRandomIntegerInRange(this.rand, 10, 30); } else { this.fishApproachAngle = (float) ((double) this.fishApproachAngle + this.rand.nextGaussian() * 4.0D); float f7 = this.fishApproachAngle * 0.017453292F; float f10 = MathHelper.sin(f7); float f11 = MathHelper.cos(f7); double d13 = this.posX + (double) (f10 * (float) this.ticksCatchableDelay * 0.1F); double d15 = (double) ((float) MathHelper.floor_double(this.getEntityBoundingBox().minY) + 1.0F); double d16 = this.posZ + (double) (f11 * (float) this.ticksCatchableDelay * 0.1F); Block block1 = worldserver .getBlockState(new BlockPos((int) d13, (int) d15 - 1, (int) d16)) .getBlock(); if (block1 == Blocks.water || block1 == Blocks.flowing_water) { if (this.rand.nextFloat() < 0.15F) { worldserver.spawnParticle( EnumParticleTypes.WATER_BUBBLE, d13, d15 - 0.10000000149011612D, d16, 1, (double) f10, 0.1D, (double) f11, 0.0D, new int[0]); } float f3 = f10 * 0.04F; float f4 = f11 * 0.04F; worldserver.spawnParticle( EnumParticleTypes.WATER_WAKE, d13, d15, d16, 0, (double) f4, 0.01D, (double) (-f3), 1.0D, new int[0]); worldserver.spawnParticle( EnumParticleTypes.WATER_WAKE, d13, d15, d16, 0, (double) (-f4), 0.01D, (double) f3, 1.0D, new int[0]); } } } else if (this.ticksCaughtDelay > 0) { this.ticksCaughtDelay -= l; float f1 = 0.15F; if (this.ticksCaughtDelay < 20) { f1 = (float) ((double) f1 + (double) (20 - this.ticksCaughtDelay) * 0.05D); } else if (this.ticksCaughtDelay < 40) { f1 = (float) ((double) f1 + (double) (40 - this.ticksCaughtDelay) * 0.02D); } else if (this.ticksCaughtDelay < 60) { f1 = (float) ((double) f1 + (double) (60 - this.ticksCaughtDelay) * 0.01D); } if (this.rand.nextFloat() < f1) { float f9 = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F) * 0.017453292F; float f2 = MathHelper.randomFloatClamp(this.rand, 25.0F, 60.0F); double d12 = this.posX + (double) (MathHelper.sin(f9) * f2 * 0.1F); double d14 = (double) ((float) MathHelper.floor_double(this.getEntityBoundingBox().minY) + 1.0F); double d6 = this.posZ + (double) (MathHelper.cos(f9) * f2 * 0.1F); Block block = worldserver .getBlockState(new BlockPos((int) d12, (int) d14 - 1, (int) d6)) .getBlock(); if (block == Blocks.water || block == Blocks.flowing_water) { worldserver.spawnParticle( EnumParticleTypes.WATER_SPLASH, d12, d14, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D, new int[0]); } } if (this.ticksCaughtDelay <= 0) { this.fishApproachAngle = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F); this.ticksCatchableDelay = MathHelper.getRandomIntegerInRange(this.rand, 20, 80); } } else { this.ticksCaughtDelay = MathHelper.getRandomIntegerInRange(this.rand, 100, 900); this.ticksCaughtDelay -= EnchantmentHelper.getLureModifier(this.angler) * 20 * 5; } if (this.ticksCatchable > 0) { this.motionY -= (double) (this.rand.nextFloat() * this.rand.nextFloat() * this.rand.nextFloat()) * 0.2D; } } double d11 = d10 * 2.0D - 1.0D; this.motionY += 0.03999999910593033D * d11; if (d10 > 0.0D) { f6 = (float) ((double) f6 * 0.9D); this.motionY *= 0.8D; } this.motionX *= (double) f6; this.motionY *= (double) f6; this.motionZ *= (double) f6; this.setPosition(this.posX, this.posY, this.posZ); } } }
protected void updateEntityActionState() { this.worldObj.theProfiler.startSection("ai"); if (this.fleeingTick > 0 && --this.fleeingTick == 0) { AttributeInstance attributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed); attributeinstance.removeModifier(field_110181_i); } this.hasAttacked = this.isMovementCeased(); float f = 16.0F; if (this.entityToAttack == null) { this.entityToAttack = this.findPlayerToAttack(); if (this.entityToAttack != null) { this.pathToEntity = this.worldObj.getPathEntityToEntity( this, this.entityToAttack, f, true, false, false, true); } } else if (this.entityToAttack.isEntityAlive()) { float f1 = this.entityToAttack.getDistanceToEntity(this); if (this.canEntityBeSeen(this.entityToAttack)) { this.attackEntity(this.entityToAttack, f1); } } else { this.entityToAttack = null; } this.worldObj.theProfiler.endSection(); if (!this.hasAttacked && this.entityToAttack != null && (this.pathToEntity == null || this.rand.nextInt(20) == 0)) { this.pathToEntity = this.worldObj.getPathEntityToEntity( this, this.entityToAttack, f, true, false, false, true); } else if (!this.hasAttacked && (this.pathToEntity == null && this.rand.nextInt(180) == 0 || this.rand.nextInt(120) == 0 || this.fleeingTick > 0) && this.entityAge < 100) { this.updateWanderPath(); } int i = MathHelper.floor_double(this.boundingBox.minY + 0.5D); boolean flag = this.isInWater(); boolean flag1 = this.handleLavaMovement(); this.rotationPitch = 0.0F; if (this.pathToEntity != null && this.rand.nextInt(100) != 0) { this.worldObj.theProfiler.startSection("followpath"); Vec3 vec3 = this.pathToEntity.getPosition(this); double d0 = (double) (this.width * 2.0F); while (vec3 != null && vec3.squareDistanceTo(this.posX, vec3.yCoord, this.posZ) < d0 * d0) { this.pathToEntity.incrementPathIndex(); if (this.pathToEntity.isFinished()) { vec3 = null; this.pathToEntity = null; } else { vec3 = this.pathToEntity.getPosition(this); } } this.isJumping = false; if (vec3 != null) { double d1 = vec3.xCoord - this.posX; double d2 = vec3.zCoord - this.posZ; double d3 = vec3.yCoord - (double) i; float f2 = (float) (Math.atan2(d2, d1) * 180.0D / Math.PI) - 90.0F; float f3 = MathHelper.wrapAngleTo180_float(f2 - this.rotationYaw); this.moveForward = (float) this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue(); if (f3 > 30.0F) { f3 = 30.0F; } if (f3 < -30.0F) { f3 = -30.0F; } this.rotationYaw += f3; if (this.hasAttacked && this.entityToAttack != null) { double d4 = this.entityToAttack.posX - this.posX; double d5 = this.entityToAttack.posZ - this.posZ; float f4 = this.rotationYaw; this.rotationYaw = (float) (Math.atan2(d5, d4) * 180.0D / Math.PI) - 90.0F; f3 = (f4 - this.rotationYaw + 90.0F) * (float) Math.PI / 180.0F; this.moveStrafing = -MathHelper.sin(f3) * this.moveForward * 1.0F; this.moveForward = MathHelper.cos(f3) * this.moveForward * 1.0F; } if (d3 > 0.0D) { this.isJumping = true; } } if (this.entityToAttack != null) { this.faceEntity(this.entityToAttack, 30.0F, 30.0F); } if (this.isCollidedHorizontally && !this.hasPath()) { this.isJumping = true; } if (this.rand.nextFloat() < 0.8F && (flag || flag1)) { this.isJumping = true; } this.worldObj.theProfiler.endSection(); } else { super.updateEntityActionState(); this.pathToEntity = null; } }