Esempio n. 1
0
    public void CreateNewWorld()
    {
        int rn;

        if (single_nameField.text == "")
        {
            return;
        }

        if (single_seedField.text == "")
        {
            Random.InitState((int)DateTime.Now.Ticks);
            rn = (int)Random.Range(0, int.MaxValue);
            World.SetWorldSeed(rn.ToString());
        }
        else
        {
            World.SetWorldSeed(single_seedField.text);
        }

        World.SetWorldName(single_nameField.text);

        if (RegionFileHandler.CreateWorldFile(World.worldName, World.worldSeed))
        {
            OpenSingleplayerMenu();
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        this.renderDistance = World.renderDistance;

        regionHandler = new RegionFileHandler(renderDistance, newChunk);

        worldSeed = regionHandler.GetRealSeed();

        biomeHandler = new BiomeHandler(BiomeSeedFunction(worldSeed));

        this.worldGen = new WorldGenerator(worldSeed, BiomeSeedFunction(worldSeed), OffsetHashFunction(worldSeed), GenerationSeedFunction(worldSeed), biomeHandler, structHandler, this);

        // If character has been loaded
        if (regionHandler.playerFile.Length > 0)
        {
            player.position = regionHandler.LoadPlayer();
            PLAYERSPAWNED   = true;
        }

        int playerX = Mathf.FloorToInt(player.position.x / Chunk.chunkWidth);
        int playerZ = Mathf.FloorToInt(player.position.z / Chunk.chunkWidth);

        newChunk = new ChunkPos(playerX, playerZ);


        GetChunks(true);
    }
Esempio n. 3
0
    private void InitWorld()
    {
        this.regionHandler = new RegionFileHandler(this);
        worldSeed          = regionHandler.GetRealSeed();
        biomeHandler       = new BiomeHandler();
        this.worldGen      = new WorldGenerator(worldSeed, biomeHandler, structHandler, this);
        biomeHandler.SetWorldGenerator(this.worldGen);

        print("Initializing World");

        // Sends the first player it's information
        PlayerData pdat      = this.regionHandler.LoadPlayer(this.server.firstConnectedID); // CHANGE TO OTHER ACCOUNTID
        Vector3    playerPos = pdat.GetPosition();
        Vector3    playerDir = pdat.GetDirection();

        pdat.SetOnline(true);

        this.regionHandler.InitDataFiles(new ChunkPos((int)(playerPos.x / Chunk.chunkWidth), (int)(playerPos.z / Chunk.chunkWidth)));

        HandleServerCommunication();
        NetMessage message = new NetMessage(NetCode.SENDSERVERINFO);

        message.SendServerInfo(playerPos.x, playerPos.y, playerPos.z, playerDir.x, playerDir.y, playerDir.z);
        this.server.Send(message.GetMessage(), message.size, this.server.firstConnectedID);
        this.INITIALIZEDWORLD = true;
        this.time.SetLock(false);
    }