コード例 #1
0
ファイル: PathPoint.cs プロジェクト: riverar/Crafty
 public float distanceTo(PathPoint pathpoint)
 {
     float f = pathpoint.xCoord - xCoord;
     float f1 = pathpoint.yCoord - yCoord;
     float f2 = pathpoint.zCoord - zCoord;
     return MathHelper.sqrt_float(f*f + f1*f1 + f2*f2);
 }
コード例 #2
0
        private void sortBack(int i)
        {
            PathPoint pathpoint = pathPoints[i];
            float     f         = pathpoint.distanceToTarget;

            do
            {
                if (i <= 0)
                {
                    break;
                }
                int       j          = i - 1 >> 1;
                PathPoint pathpoint1 = pathPoints[j];
                if (f >= pathpoint1.distanceToTarget)
                {
                    break;
                }
                pathPoints[i]    = pathpoint1;
                pathpoint1.index = i;
                i = j;
            } while (true);
            pathPoints[i]   = pathpoint;
            pathpoint.index = i;
        }
コード例 #3
0
ファイル: SpawnerAnimals.cs プロジェクト: geckosoft/Crafty
        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);
        }