Пример #1
0
 public WorldPlayerNode(EntityPlayerSP player)
 {
     pitch  = player.camera.pitch;
     yaw    = player.camera.yaw;
     pos    = player.pos;
     hotbar = player.hotbar;
 }
Пример #2
0
        public static World loadWorld()
        {
            var bf = new BinaryFormatter();

            if (!Directory.Exists(dir))
            {
                return(null);
            }

            World world = null;

            try
            {
                WorldChunksNode wcn;
                WorldPlayerNode wpn;

                using (var fs = File.OpenRead(dir + "/chunks.dat"))
                {
                    wcn = (WorldChunksNode)bf.Deserialize(fs);
                }

                using (var fs = File.OpenRead(dir + "/player.dat"))
                {
                    wpn = (WorldPlayerNode)bf.Deserialize(fs);
                }

                world = World.Create(wcn.seed, wcn.caches);

                var player = new EntityPlayerSP(wpn.pos);
                player.camera.pitch = wpn.pitch;
                player.camera.yaw   = wpn.yaw;

                for (int i = 0; i < wpn.hotbar.Length; i++)
                {
                    player.hotbar[i] = wpn.hotbar[i];
                }

                world.addEntity(player);

                Game.INSTANCE.player = player;
            }
            catch
            {
            }

            return(world);
        }
Пример #3
0
        public void startGame()
        {
            var loadedWorld = WorldLoader.loadWorld();

            if (loadedWorld == null)
            {
                Console.WriteLine("DEBUG: generating world");

                var r = new Random();

                var playerPos = new BlockPos(-100 + (float)r.NextDouble() * 200, 0,
                                             -100 + (float)r.NextDouble() * 200);

                world = new World(0);
                world.generateChunk(playerPos, true);

                player = new EntityPlayerSP(new Vector3(playerPos.x, world.getHeightAtPos(playerPos.x, playerPos.z),
                                                        playerPos.z));

                world.addEntity(player);

                player.setItemStackInHotbar(0, new ItemStack(new ItemBlock(EnumBlock.CRAFTING_TABLE)));
                player.setItemStackInHotbar(1, new ItemStack(new ItemBlock(EnumBlock.FURNACE)));
                player.setItemStackInHotbar(2, new ItemStack(new ItemBlock(EnumBlock.COBBLESTONE)));
                player.setItemStackInHotbar(3, new ItemStack(new ItemBlock(EnumBlock.PLANKS)));
                player.setItemStackInHotbar(4, new ItemStack(new ItemBlock(EnumBlock.GLASS)));
            }
            else
            {
                world = loadedWorld;
            }

            resetMouse();

            var state = OpenTK.Input.Mouse.GetState();

            mouseLast = new Point(state.X, state.Y);

            gameRenderer.setCamera(player.camera);

            runUpdateThreads();

            ShaderManager.updateProjectionMatrix();

            world.setBlock(new BlockPos(player.pos), EnumBlock.RARE, 1, true);
        }