Exemplo n.º 1
0
        public override void updatePlayerActionState()
        {
            hasAttacked = false;
            float f = 16F;

            if (playerToAttack == null)
            {
                playerToAttack = findPlayerToAttack();
                if (playerToAttack != null)
                {
                    pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
                }
            }
            else if (!playerToAttack.isEntityAlive())
            {
                playerToAttack = null;
            }
            else
            {
                float f1 = playerToAttack.getDistanceToEntity(this);
                if (canEntityBeSeen(playerToAttack))
                {
                    attackEntity(playerToAttack, f1);
                }
            }
            if (!hasAttacked && playerToAttack != null && (pathToEntity == null || rand.nextInt(20) == 0))
            {
                pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
            }
            else if (pathToEntity == null && rand.nextInt(80) == 0 || rand.nextInt(80) == 0)
            {
                bool  flag = false;
                int   j    = -1;
                int   k    = -1;
                int   l    = -1;
                float f2   = -99999F;
                for (int i1 = 0; i1 < 10; i1++)
                {
                    int   j1 = MathHelper.floor_double((posX + rand.nextInt(13)) - 6D);
                    int   k1 = MathHelper.floor_double((posY + rand.nextInt(7)) - 3D);
                    int   l1 = MathHelper.floor_double((posZ + rand.nextInt(13)) - 6D);
                    float f3 = getBlockPathWeight(j1, k1, l1);
                    if (f3 > f2)
                    {
                        f2   = f3;
                        j    = j1;
                        k    = k1;
                        l    = l1;
                        flag = true;
                    }
                }

                if (flag)
                {
                    pathToEntity = worldObj.getEntityPathToXYZ(this, j, k, l, 10F);
                }
            }
            int  i     = MathHelper.floor_double(boundingBox.minY);
            bool flag1 = handleWaterMovement();
            bool flag2 = handleLavaMovement();

            rotationPitch = 0.0F;
            if (pathToEntity == null || rand.nextInt(100) == 0)
            {
                base.updatePlayerActionState();
                pathToEntity = null;
                return;
            }
            Vec3D vec3d = pathToEntity.getPosition(this);

            for (double d = width * 2.0F; vec3d != null && vec3d.squareDistanceTo(posX, vec3d.yCoord, posZ) < d * d;)
            {
                pathToEntity.incrementPathIndex();
                if (pathToEntity.isFinished())
                {
                    vec3d        = null;
                    pathToEntity = null;
                }
                else
                {
                    vec3d = pathToEntity.getPosition(this);
                }
            }

            isJumping = false;
            if (vec3d != null)
            {
                double d1 = vec3d.xCoord - posX;
                double d2 = vec3d.zCoord - posZ;
                double d3 = vec3d.yCoord - i;
                float  f4 = (float)((Math.atan2(d2, d1) * 180D) / 3.1415927410125732D) - 90F;
                float  f5 = f4 - rotationYaw;
                moveForward = moveSpeed;
                for (; f5 < -180F; f5 += 360F)
                {
                }
                for (; f5 >= 180F; f5 -= 360F)
                {
                }
                if (f5 > 30F)
                {
                    f5 = 30F;
                }
                if (f5 < -30F)
                {
                    f5 = -30F;
                }
                rotationYaw += f5;
                if (hasAttacked && playerToAttack != null)
                {
                    double d4 = playerToAttack.posX - posX;
                    double d5 = playerToAttack.posZ - posZ;
                    float  f7 = rotationYaw;
                    rotationYaw = (float)((Math.atan2(d5, d4) * 180D) / 3.1415927410125732D) - 90F;
                    float f6 = (((f7 - rotationYaw) + 90F) * 3.141593F) / 180F;
                    moveStrafing = -MathHelper.sin(f6) * moveForward * 1.0F;
                    moveForward  = MathHelper.cos(f6) * moveForward * 1.0F;
                }
                if (d3 > 0.0D)
                {
                    isJumping = true;
                }
            }
            if (playerToAttack != null)
            {
                faceEntity(playerToAttack, 30F);
            }
            if (isCollidedHorizontally)
            {
                isJumping = true;
            }
            if (rand.nextFloat() < 0.8F && (flag1 || flag2))
            {
                isJumping = true;
            }
        }
Exemplo n.º 2
0
        public static bool performSleepSpawning(World world, List list)
        {
            bool     flag       = false;
            var      pathfinder = new Pathfinder(world);
            Iterator iterator   = list.iterator();

            do
            {
                if (!iterator.hasNext())
                {
                    break;
                }
                var     entityplayer = (EntityPlayer)iterator.next();
                Class[] aclass       = field_22213_a;
                if (aclass != null && aclass.Length != 0)
                {
                    bool flag1 = false;
                    int  i     = 0;
                    while (i < 20 && !flag1)
                    {
                        int j = (MathHelper.floor_double(entityplayer.posX) + world.rand.nextInt(32)) -
                                world.rand.nextInt(32);
                        int k = (MathHelper.floor_double(entityplayer.posZ) + world.rand.nextInt(32)) -
                                world.rand.nextInt(32);
                        int l = (MathHelper.floor_double(entityplayer.posY) + world.rand.nextInt(16)) -
                                world.rand.nextInt(16);
                        if (l < 1)
                        {
                            l = 1;
                        }
                        else if (l > 128)
                        {
                            l = 128;
                        }
                        int i1 = world.rand.nextInt(aclass.Length);
                        int j1;
                        for (j1 = l; j1 > 2 && !world.isBlockOpaqueCube(j, j1 - 1, k); j1--)
                        {
                        }
                        for (;
                             !func_21167_a(EnumCreatureType.monster, world, j, j1, k) && j1 < l + 16 && j1 < 128;
                             j1++)
                        {
                        }
                        if (j1 >= l + 16 || j1 >= 128)
                        {
                            j1 = l;
                        }
                        else
                        {
                            float        f  = j + 0.5F;
                            float        f1 = j1;
                            float        f2 = k + 0.5F;
                            EntityLiving entityliving;
                            try
                            {
                                entityliving = (EntityLiving)aclass[i1].getConstructor(new Class[]
                                {
                                    typeof(World)
                                }).newInstance(new object[]
                                {
                                    world
                                });
                            }
                            catch (Exception exception)
                            {
                                exception.printStackTrace();
                                return(flag);
                            }
                            entityliving.setLocationAndAngles(f, f1, f2, world.rand.nextFloat() * 360F, 0.0F);
                            if (entityliving.getCanSpawnHere())
                            {
                                PathEntity pathentity = pathfinder.createEntityPathTo(entityliving, entityplayer, 32F);
                                if (pathentity != null && pathentity.pathLength > 1)
                                {
                                    PathPoint pathpoint = pathentity.func_22211_c();
                                    if (Math.abs(pathpoint.xCoord - entityplayer.posX) < 1.5D &&
                                        Math.abs(pathpoint.zCoord - entityplayer.posZ) < 1.5D &&
                                        Math.abs(pathpoint.yCoord - entityplayer.posY) < 1.5D)
                                    {
                                        ChunkCoordinates chunkcoordinates = BlockBed.func_22021_g(world,
                                                                                                  MathHelper.
                                                                                                  floor_double(
                                                                                                      entityplayer.
                                                                                                      posX),
                                                                                                  MathHelper.
                                                                                                  floor_double(
                                                                                                      entityplayer.
                                                                                                      posY),
                                                                                                  MathHelper.
                                                                                                  floor_double(
                                                                                                      entityplayer.
                                                                                                      posZ), 1);
                                        entityliving.setLocationAndAngles(chunkcoordinates.posX + 0.5F,
                                                                          chunkcoordinates.posY,
                                                                          chunkcoordinates.posZ + 0.5F, 0.0F,
                                                                          0.0F);
                                        world.entityJoinedWorld(entityliving);
                                        func_21166_a(entityliving, world, chunkcoordinates.posX + 0.5F,
                                                     chunkcoordinates.posY, chunkcoordinates.posZ + 0.5F);
                                        entityplayer.wakeUpPlayer(true, false);
                                        entityliving.func_22056_G();
                                        flag  = true;
                                        flag1 = true;
                                    }
                                }
                            }
                        }
                        i++;
                    }
                }
            } while (true);
            return(flag);
        }
Exemplo n.º 3
0
        public override void updatePlayerActionState()
        {
            hasAttacked = false;
            float f = 16F;
            if (playerToAttack == null)
            {
                playerToAttack = findPlayerToAttack();
                if (playerToAttack != null)
                {
                    pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
                }
            }
            else if (!playerToAttack.isEntityAlive())
            {
                playerToAttack = null;
            }
            else
            {
                float f1 = playerToAttack.getDistanceToEntity(this);
                if (canEntityBeSeen(playerToAttack))
                {
                    attackEntity(playerToAttack, f1);
                }
            }
            if (!hasAttacked && playerToAttack != null && (pathToEntity == null || rand.nextInt(20) == 0))
            {
                pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
            }
            else if (pathToEntity == null && rand.nextInt(80) == 0 || rand.nextInt(80) == 0)
            {
                bool flag = false;
                int j = -1;
                int k = -1;
                int l = -1;
                float f2 = -99999F;
                for (int i1 = 0; i1 < 10; i1++)
                {
                    int j1 = MathHelper.floor_double((posX + rand.nextInt(13)) - 6D);
                    int k1 = MathHelper.floor_double((posY + rand.nextInt(7)) - 3D);
                    int l1 = MathHelper.floor_double((posZ + rand.nextInt(13)) - 6D);
                    float f3 = getBlockPathWeight(j1, k1, l1);
                    if (f3 > f2)
                    {
                        f2 = f3;
                        j = j1;
                        k = k1;
                        l = l1;
                        flag = true;
                    }
                }

                if (flag)
                {
                    pathToEntity = worldObj.getEntityPathToXYZ(this, j, k, l, 10F);
                }
            }
            int i = MathHelper.floor_double(boundingBox.minY);
            bool flag1 = handleWaterMovement();
            bool flag2 = handleLavaMovement();
            rotationPitch = 0.0F;
            if (pathToEntity == null || rand.nextInt(100) == 0)
            {
                base.updatePlayerActionState();
                pathToEntity = null;
                return;
            }
            Vec3D vec3d = pathToEntity.getPosition(this);
            for (double d = width*2.0F; vec3d != null && vec3d.squareDistanceTo(posX, vec3d.yCoord, posZ) < d*d;)
            {
                pathToEntity.incrementPathIndex();
                if (pathToEntity.isFinished())
                {
                    vec3d = null;
                    pathToEntity = null;
                }
                else
                {
                    vec3d = pathToEntity.getPosition(this);
                }
            }

            isJumping = false;
            if (vec3d != null)
            {
                double d1 = vec3d.xCoord - posX;
                double d2 = vec3d.zCoord - posZ;
                double d3 = vec3d.yCoord - i;
                float f4 = (float) ((Math.atan2(d2, d1)*180D)/3.1415927410125732D) - 90F;
                float f5 = f4 - rotationYaw;
                moveForward = moveSpeed;
                for (; f5 < -180F; f5 += 360F)
                {
                }
                for (; f5 >= 180F; f5 -= 360F)
                {
                }
                if (f5 > 30F)
                {
                    f5 = 30F;
                }
                if (f5 < -30F)
                {
                    f5 = -30F;
                }
                rotationYaw += f5;
                if (hasAttacked && playerToAttack != null)
                {
                    double d4 = playerToAttack.posX - posX;
                    double d5 = playerToAttack.posZ - posZ;
                    float f7 = rotationYaw;
                    rotationYaw = (float) ((Math.atan2(d5, d4)*180D)/3.1415927410125732D) - 90F;
                    float f6 = (((f7 - rotationYaw) + 90F)*3.141593F)/180F;
                    moveStrafing = -MathHelper.sin(f6)*moveForward*1.0F;
                    moveForward = MathHelper.cos(f6)*moveForward*1.0F;
                }
                if (d3 > 0.0D)
                {
                    isJumping = true;
                }
            }
            if (playerToAttack != null)
            {
                faceEntity(playerToAttack, 30F);
            }
            if (isCollidedHorizontally)
            {
                isJumping = true;
            }
            if (rand.nextFloat() < 0.8F && (flag1 || flag2))
            {
                isJumping = true;
            }
        }