Example #1
0
        // Acts like a constructor.
        public void initWorld(WorldData data)
        {
            this.worldData    = data;
            this.loadedChunks = new Dictionary <ChunkPos, Chunk>();
            this.entityList   = new List <Entity>();
            this.nbtIOHelper  = new NbtIOHelper(this.worldData);
            this.generator    = WorldType.getFromId(this.worldData.worldType).getGenerator(this, this.worldData.seed);

            this.lighter = new WorldLighter(this);

            if (!this.nbtIOHelper.readGenerationData(this.generator))
            {
                // Generate the generation data, and save it if there was any.
                if (this.generator.generateLevelData())
                {
                    this.nbtIOHelper.writeGenerationData(this.generator);
                }
                this.worldData.spawnPos = this.generator.getSpawnPoint(this);

                if (this.worldData.writeToDisk)
                {
                    // Save the world data right away so we don't have a folder with chunks that is
                    // recognized as a save.
                    this.nbtIOHelper.writeWorldDataToDisk(this.worldData);
                }
            }

            // Create game objects to hold others in for inspector organization.
            this.chunkWrapper      = this.createWrapper("CHUNKS");
            this.entityWrapper     = this.createWrapper("ENTITIES");
            this.tileEntityWrapper = this.createWrapper("TILE_ENTITIES");
        }
Example #2
0
 /// <summary>
 /// Tries to read the world data from the disk, returning true if it was found.
 /// </summary>
 public bool readGenerationData(WorldGeneratorBase generator)
 {
     if (File.Exists(this.generationDataFileName))
     {
         NbtFile file = new NbtFile();
         file.LoadFromFile(this.generationDataFileName);
         generator.readFromNbt(file.RootTag);
         return(true);
     }
     return(false);
 }
Example #3
0
        public void writeGenerationData(WorldGeneratorBase generator)
        {
            if (this.dontWriteToDisk)
            {
                return;
            }

            NbtFile file = new NbtFile(generator.writeToNbt(new NbtCompound("generationData")));

            file.SaveToFile(this.generationDataFileName, NbtCompression.None);
        }