示例#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;
            }
        }
示例#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);
        }
示例#3
0
        public virtual bool goToSleep(int i, int j, int k)
        {
            if (isPlayerSleeping() || !isEntityAlive())
            {
                return(false);
            }
            if (worldObj.worldProvider.field_6167_c)
            {
                return(false);
            }
            if (worldObj.isDaytime())
            {
                return(false);
            }
            if (Math.abs(posX - i) > 3D || Math.abs(posY - j) > 2D || Math.abs(posZ - k) > 3D)
            {
                return(false);
            }
            setSize(0.2F, 0.2F);
            yOffset = 0.2F;
            if (worldObj.blockExists(i, j, k))
            {
                int   l  = worldObj.getBlockMetadata(i, j, k);
                int   i1 = BlockBed.func_22019_c(l);
                float f  = 0.5F;
                float f1 = 0.5F;
                switch (i1)
                {
                case 0:     // '\0'
                    f1 = 0.9F;
                    break;

                case 2:     // '\002'
                    f1 = 0.1F;
                    break;

                case 1:     // '\001'
                    f = 0.1F;
                    break;

                case 3:     // '\003'
                    f = 0.9F;
                    break;
                }
                func_22059_e(i1);
                setPosition(i + f, j + 0.9375F, k + f1);
            }
            else
            {
                setPosition(i + 0.5F, j + 0.9375F, k + 0.5F);
            }
            sleeping       = true;
            sleepTimer     = 0;
            playerLocation = new ChunkCoordinates(i, j, k);
            motionX        = motionZ = motionY = 0.0D;
            if (!worldObj.singleplayerWorld)
            {
                worldObj.updateAllPlayersSleepingFlag();
            }
            return(true);
        }