Example #1
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);
        }
Example #2
0
        public void Init(ICoreServerAPI api, RockstrataWorldProperty rockstrata, Random rnd)
        {
            if (NoiseAmplitudes != null && NoiseFrequencies != null)
            {
                noise = new ClampedSimplexNoise(NoiseAmplitudes, NoiseFrequencies, rnd.Next());
            }

            ResolveBlockIds(api, rockstrata);
        }
Example #3
0
        internal void Init(ICoreServerAPI api)
        {
            IAsset asset = api.Assets.Get("worldgen/rockstrata.json");
            RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>();

            asset            = api.Assets.Get("worldgen/blocklayerconfig.json");
            blockLayerConfig = asset.ToObject <BlockLayerConfig>();
            blockLayerConfig.ResolveBlockIds(api, rockstrata);


            for (int i = 0; i < Structures.Length; i++)
            {
                Structures[i].Init(api, blockLayerConfig);
            }
        }
Example #4
0
        public void GameWorldLoaded()
        {
            LoadGlobalConfig(api);

            IAsset asset = api.Assets.Get("worldgen/rockstrata.json");
            RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>();

            asset            = api.Assets.Get("worldgen/blocklayerconfig.json");
            blockLayerConfig = asset.ToObject <BlockLayerConfig>();
            blockLayerConfig.ResolveBlockIds(api, rockstrata);

            rnd          = new Random(api.WorldManager.Seed);
            grassDensity = new ClampedSimplexNoise(new double[] { 4 }, new double[] { 0.5 }, rnd.Next());
            grassHeight  = new ClampedSimplexNoise(new double[] { 1.5 }, new double[] { 0.5 }, rnd.Next());

            mapheight = api.WorldManager.MapSizeY;
        }
Example #5
0
        void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata)
        {
            if (BlockCode != null && BlockCode.Path.Length > 0)
            {
                if (BlockCode.Path.Contains("{rocktype}"))
                {
                    BlockIdMapping = new Dictionary <ushort, ushort>();
                    for (int i = 0; i < rockstrata.Variants.Length; i++)
                    {
                        string rocktype = rockstrata.Variants[i].BlockCode.Path.Split('-')[1];
                        BlockIdMapping.Add(api.WorldManager.GetBlockId(rockstrata.Variants[i].BlockCode), api.WorldManager.GetBlockId(BlockCode.CopyWithPath(BlockCode.Path.Replace("{rocktype}", rocktype))));
                    }
                }
                else
                {
                    BlockId = api.WorldManager.GetBlockId(BlockCode);
                }
            }
            else
            {
                BlockCode = null;
            }

            if (BlockCodeByMin != null)
            {
                for (int i = 0; i < BlockCodeByMin.Length; i++)
                {
                    AssetLocation blockCode = BlockCodeByMin[i].BlockCode;

                    if (blockCode.Path.Contains("{rocktype}"))
                    {
                        BlockCodeByMin[i].BlockIdMapping = new Dictionary <ushort, ushort>();
                        for (int j = 0; j < rockstrata.Variants.Length; j++)
                        {
                            string rocktype = rockstrata.Variants[j].BlockCode.Path.Split('-')[1];
                            BlockCodeByMin[i].BlockIdMapping.Add(api.WorldManager.GetBlockId(rockstrata.Variants[j].BlockCode), api.WorldManager.GetBlockId(blockCode.CopyWithPath(blockCode.Path.Replace("{rocktype}", rocktype))));
                        }
                    }
                    else
                    {
                        BlockCodeByMin[i].BlockId = api.WorldManager.GetBlockId(blockCode);
                    }
                }
            }
        }
        /// <summary>
        /// Loads and caches the BlockLayerConfig if it's not already loaded. Otherwise
        /// returns the cached value
        /// </summary>
        /// <param name="api"></param>
        /// <returns></returns>
        public static BlockLayerConfig GetInstance(ICoreServerAPI api)
        {
            if (api.ObjectCache.ContainsKey(cacheKey))
            {
                return(api.ObjectCache[cacheKey] as BlockLayerConfig);
            }
            else
            {
                IAsset asset = api.Assets.Get("worldgen/rockstrata.json");
                RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>();
                asset = api.Assets.Get("worldgen/blocklayerconfig.json");
                BlockLayerConfig blockLayerConfig = asset.ToObject <BlockLayerConfig>();
                blockLayerConfig.ResolveBlockIds(api, rockstrata);

                api.ObjectCache[cacheKey] = blockLayerConfig;
                return(blockLayerConfig);
            }
        }
        internal void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata)
        {
            for (int i = 0; i < Patches.Length; i++)
            {
                BlockPatch patch = Patches[i];

                List <Block> blocks = new List <Block>();

                for (int j = 0; j < patch.blockCodes.Length; j++)
                {
                    AssetLocation code = patch.blockCodes[j];

                    if (code.Path.Contains("{rocktype}"))
                    {
                        if (patch.BlocksByRockType == null)
                        {
                            patch.BlocksByRockType = new Dictionary <ushort, Block[]>();
                        }

                        for (int k = 0; k < rockstrata.Variants.Length; k++)
                        {
                            string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1];
                            patch.BlocksByRockType.Add(
                                api.WorldManager.GetBlockId(rockstrata.Variants[k].BlockCode),
                                new Block[] { api.World.GetBlock(code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype))) }
                                );
                        }
                    }
                    else
                    {
                        blocks.Add(api.WorldManager.GetBlockType(api.WorldManager.GetBlockId(code)));
                    }
                }

                patch.Blocks = blocks.ToArray();

                if (patch.BlockCodeIndex == null)
                {
                    patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length);
                }
            }
        }
Example #8
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            IAsset asset = api.Assets.Get("worldgen/rockstrata.json");

            rockstrata = asset.ToObject <RockstrataWorldProperty>();

            asset     = api.Assets.Get("worldgen/geologicprovinces.json");
            provinces = asset.ToObject <GeologicProvinces>();

            this.api = api;


            // Call our loaded method manually if the server is already running (happens when mods are reloaded at runtime)
            if (api.Server.CurrentRunPhase == EnumServerRunPhase.RunGame)
            {
                OnGameWorldLoaded();
            }

            api.Event.ChunkColumnGeneration(GenChunkColumn, EnumWorldGenPass.Terrain);
            api.Event.SaveGameLoaded += OnGameWorldLoaded;
        }
        public void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata)
        {
            for (int i = 0; i < Blocklayers.Length; i++)
            {
                Random rnd = new Random(api.WorldManager.Seed + i);

                Blocklayers[i].Init(api, rockstrata, rnd);
            }

            SnowLayer.BlockId = api.WorldManager.GetBlockId(SnowLayer.BlockCode);

            for (int i = 0; i < Tallgrass.BlockCodeByMin.Length; i++)
            {
                Tallgrass.BlockCodeByMin[i].BlockId = api.WorldManager.GetBlockId(Tallgrass.BlockCodeByMin[i].BlockCode);
            }

            for (int i = 0; i < LakeBedLayer.BlockCodeByMin.Length; i++)
            {
                Random rnd = new Random(api.WorldManager.Seed + i);
                LakeBedLayer.BlockCodeByMin[i].Init(api, rockstrata, rnd);
            }
        }
Example #10
0
        public void GameWorldLoaded()
        {
            LoadGlobalConfig(api);

            rand             = new Random(api.WorldManager.Seed);
            searchSize       = 3 * chunksize;
            mapOffset        = chunksize;
            minBoundary      = -chunksize + 1;
            maxBoundary      = 2 * chunksize - 1;
            mapheight        = api.WorldManager.MapSizeY;
            didCheckPosition = new bool[searchSize * searchSize];

            IAsset asset = api.Assets.Get("worldgen/rockstrata.json");
            RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>();

            asset = api.Assets.Get("worldgen/blocklayerconfig.json");
            BlockLayerConfig blockLayerConfig = asset.ToObject <BlockLayerConfig>();

            blockLayerConfig.ResolveBlockIds(api, rockstrata);

            lakebedLayerConfig = blockLayerConfig.LakeBedLayer;
        }
 public void Init(ICoreServerAPI api, RockstrataWorldProperty rockstrata, Random rnd)
 {
     ResolveBlockIds(api, rockstrata);
 }