Ejemplo n.º 1
0
        public virtual void wakeUpPlayer(bool flag, bool flag1)
        {
            setSize(0.6F, 1.8F);
            resetHeight();
            ChunkCoordinates chunkcoordinates = playerLocation;

            if (chunkcoordinates != null &&
                worldObj.getBlockId(chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ) ==
                Block.bed.blockID)
            {
                BlockBed.func_22022_a(worldObj, chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ,
                                      false);
                ChunkCoordinates chunkcoordinates1 = BlockBed.func_22021_g(worldObj, chunkcoordinates.posX,
                                                                           chunkcoordinates.posY, chunkcoordinates.posZ,
                                                                           0);
                setPosition(chunkcoordinates1.posX + 0.5F, chunkcoordinates1.posY + yOffset + 0.1F,
                            chunkcoordinates1.posZ + 0.5F);
            }
            sleeping = false;
            if (!worldObj.singleplayerWorld && flag1)
            {
                worldObj.updateAllPlayersSleepingFlag();
            }
            if (flag)
            {
                sleepTimer = 0;
            }
            else
            {
                sleepTimer = 100;
            }
        }
Ejemplo 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);
        }