public void initWorldGen()
        {
            LoadGlobalConfig(api);

            rnd       = new Random(api.WorldManager.Seed);
            chunksize = api.WorldManager.ChunkSize;

            treeSupplier.LoadTrees();

            worldheight     = api.WorldManager.MapSizeY;
            chunkMapSizeY   = api.WorldManager.MapSizeY / chunksize;
            regionChunkSize = api.WorldManager.RegionSize / chunksize;

            RockBlockIdsByType = new Dictionary <string, int>();
            RockStrataConfig rockstrata = api.Assets.Get("worldgen/rockstrata.json").ToObject <RockStrataConfig>();

            for (int i = 0; i < rockstrata.Variants.Length; i++)
            {
                Block block = api.World.GetBlock(rockstrata.Variants[i].BlockCode);
                RockBlockIdsByType[block.LastCodePart()] = block.BlockId;
            }
            IAsset asset = api.Assets.Get("worldgen/blockpatches.json");

            bpc = asset.ToObject <BlockPatchConfig>();
            bpc.ResolveBlockIds(api, rockstrata);
        }
Exemple #2
0
        public void GameWorldLoaded()
        {
            LoadGlobalConfig(api);

            rnd       = new Random(api.WorldManager.Seed);
            chunksize = api.WorldManager.ChunkSize;

            treeSupplier.LoadTrees();

            worldheight     = api.WorldManager.MapSizeY;
            chunkMapSizeY   = api.WorldManager.MapSizeY / chunksize;
            regionChunkSize = api.WorldManager.RegionSize / chunksize;

            RockBlockIdsByType = new Dictionary <string, ushort>();
            RockstrataWorldProperty rockstrata = api.Assets.Get("worldgen/rockstrata.json").ToObject <RockstrataWorldProperty>();

            for (int i = 0; i < rockstrata.Variants.Length; i++)
            {
                RockBlockIdsByType.Add(rockstrata.Variants[i].RockType, api.World.GetBlock(rockstrata.Variants[i].BlockCode).BlockId);
            }
            IAsset asset = api.Assets.Get("worldgen/blockpatchconfig.json");

            bpc = asset.ToObject <BlockPatchConfig>();
            bpc.ResolveBlockIds(api, rockstrata);
        }
        public void initWorldGen()
        {
            regionSize          = sapi.WorldManager.RegionSize;
            chunksize           = sapi.World.BlockAccessor.ChunkSize;
            noiseSizeDensityMap = regionSize / TerraGenConfig.blockPatchesMapScale;

            LoadGlobalConfig(sapi);

            rnd       = new LCGRandom(sapi.WorldManager.Seed - 87698);
            chunksize = sapi.WorldManager.ChunkSize;

            treeSupplier.LoadTrees();

            worldheight     = sapi.WorldManager.MapSizeY;
            chunkMapSizeY   = sapi.WorldManager.MapSizeY / chunksize;
            regionChunkSize = sapi.WorldManager.RegionSize / chunksize;

            RockBlockIdsByType = new Dictionary <string, int>();
            RockStrataConfig rockstrata = sapi.Assets.Get("worldgen/rockstrata.json").ToObject <RockStrataConfig>();

            for (int i = 0; i < rockstrata.Variants.Length; i++)
            {
                Block block = sapi.World.GetBlock(rockstrata.Variants[i].BlockCode);
                RockBlockIdsByType[block.LastCodePart()] = block.BlockId;
            }
            IAsset asset = sapi.Assets.Get("worldgen/blockpatches.json");

            bpc = asset.ToObject <BlockPatchConfig>();

            var blockpatchesfiles = sapi.Assets.GetMany <BlockPatch[]>(sapi.World.Logger, "worldgen/blockpatches/");

            foreach (var patches in blockpatchesfiles.Values)
            {
                bpc.Patches = bpc.Patches.Append(patches);
            }

            bpc.ResolveBlockIds(sapi, rockstrata, rnd);
            treeSupplier.treeGenerators.forestFloorSystem.SetBlockPatches(bpc);


            ITreeAttribute worldConfig = sapi.WorldManager.SaveGame.WorldConfiguration;

            forestMod = worldConfig.GetString("globalForestation").ToFloat(0);

            blockPatchMapGens.Clear();
            foreach (var patch in bpc.Patches)
            {
                if (patch.MapCode == null || blockPatchMapGens.ContainsKey(patch.MapCode))
                {
                    continue;
                }

                int hs   = patch.MapCode.GetHashCode();
                int seed = sapi.World.Seed + 112897 + hs;
                blockPatchMapGens[patch.MapCode] = new MapLayerWobbled(seed, 2, 0.9f, TerraGenConfig.forestMapScale, 4000, -3000);
            }
        }