Пример #1
0
        public static bool PerformSleepSpawning(net.minecraft.src.World world, List <EntityPlayer> list)
        {
            bool flag = false;

            net.minecraft.src.Pathfinder   pathfinder = new net.minecraft.src.Pathfinder(world);
            System.Collections.IEnumerator iterator   = list.GetEnumerator();
            do
            {
                if (!iterator.MoveNext())
                {
                    break;
                }
                net.minecraft.src.EntityPlayer entityplayer = (net.minecraft.src.EntityPlayer)iterator
                                                              .Current;
                System.Type[] aclass = field_22213_a;
                if (aclass != null && aclass.Length != 0)
                {
                    bool flag1 = false;
                    int  i     = 0;
                    while (i < 20 && !flag1)
                    {
                        int j = (net.minecraft.src.MathHelper.Floor_double(entityplayer.posX) + world.rand
                                 .NextInt(32)) - world.rand.Next(32);
                        int k = (net.minecraft.src.MathHelper.Floor_double(entityplayer.posZ) + world.rand
                                 .NextInt(32)) - world.rand.Next(32);
                        int l = (net.minecraft.src.MathHelper.Floor_double(entityplayer.posY) + world.rand
                                 .NextInt(16)) - world.rand.Next(16);
                        if (l < 1)
                        {
                            l = 1;
                        }
                        else
                        {
                            if (l > 128)
                            {
                                l = 128;
                            }
                        }
                        int i1 = world.rand.Next(aclass.Length);
                        int j1;
                        for (j1 = l; j1 > 2 && !world.IsBlockNormalCube(j, j1 - 1, k); j1--)
                        {
                        }
                        for (; !Func_21167_a(net.minecraft.src.EnumCreatureType.monster, world, j, j1, k) &&
                             j1 < l + 16 && j1 < 128; j1++)
                        {
                        }
                        if (j1 >= l + 16 || j1 >= 128)
                        {
                            j1 = l;
                        }
                        else
                        {
                            float f  = (float)j + 0.5F;
                            float f1 = j1;
                            float f2 = (float)k + 0.5F;
                            net.minecraft.src.EntityLiving entityliving;
                            try
                            {
                                entityliving = (net.minecraft.src.EntityLiving)(aclass[i1].GetConstructor(new System.Type[] { Sharpen.Runtime.GetClassForType(typeof(net.minecraft.src.World)) }).Invoke(new object[] { world }));
                            }
                            catch (System.Exception exception)
                            {
                                Sharpen.Runtime.PrintStackTrace(exception);
                                return(flag);
                            }
                            entityliving.SetLocationAndAngles(f, f1, f2, world.rand.NextFloat() * 360F, 0.0F);
                            if (entityliving.GetCanSpawnHere())
                            {
                                net.minecraft.src.PathEntity pathentity = pathfinder.CreateEntityPathTo(entityliving
                                                                                                        , entityplayer, 32F);
                                if (pathentity != null && pathentity.pathLength > 1)
                                {
                                    net.minecraft.src.PathPoint pathpoint = pathentity.Func_22211_c();
                                    if (System.Math.Abs((double)pathpoint.xCoord - entityplayer.posX) < 1.5D && System.Math
                                        .Abs((double)pathpoint.zCoord - entityplayer.posZ) < 1.5D && System.Math.Abs((double
                                                                                                                      )pathpoint.yCoord - entityplayer.posY) < 1.5D)
                                    {
                                        net.minecraft.src.ChunkCoordinates chunkcoordinates = net.minecraft.src.BlockBed.
                                                                                              Func_22021_g(world, net.minecraft.src.MathHelper.Floor_double(entityplayer.posX)
                                                                                                           , net.minecraft.src.MathHelper.Floor_double(entityplayer.posY), net.minecraft.src.MathHelper
                                                                                                           .Floor_double(entityplayer.posZ), 1);
                                        if (chunkcoordinates == null)
                                        {
                                            chunkcoordinates = new net.minecraft.src.ChunkCoordinates(j, j1 + 1, k);
                                        }
                                        entityliving.SetLocationAndAngles((float)chunkcoordinates.posX + 0.5F, chunkcoordinates
                                                                          .posY, (float)chunkcoordinates.posZ + 0.5F, 0.0F, 0.0F);
                                        world.AddEntity(entityliving);
                                        Func_21166_a(entityliving, world, (float)chunkcoordinates.posX + 0.5F, chunkcoordinates
                                                     .posY, (float)chunkcoordinates.posZ + 0.5F);
                                        entityplayer.WakeUpPlayer(true, false, false);
                                        entityliving.PlayLivingSound();
                                        flag  = true;
                                        flag1 = true;
                                    }
                                }
                            }
                        }
                        i++;
                    }
                }
            }while (true);
            return(flag);
        }