Browse Source

savanna biome basic implement

JasonWang 6 years ago
parent
commit
d0f44bdf09

+ 2 - 0
src/MineCase.Algorithm/World/Biomes/Biome.cs

@@ -188,6 +188,8 @@ namespace MineCase.Algorithm.World.Biomes
                      return new BiomeRiver(new BiomeProperties(), settings);
                      return new BiomeRiver(new BiomeProperties(), settings);
                 case BiomeId.Beach:
                 case BiomeId.Beach:
                      return new BiomeBeach(new BiomeProperties(), settings);
                      return new BiomeBeach(new BiomeProperties(), settings);
+                case BiomeId.Savanna:
+                     return new BiomeSavanna(new BiomeProperties(), settings);
                 default:
                 default:
                      return null;
                      return null;
             }
             }

+ 25 - 0
src/MineCase.Algorithm/World/Biomes/BiomeSavanna.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MineCase.Server.Game.Entities;
+using MineCase.World.Biomes;
+using MineCase.World.Generation;
+
+namespace MineCase.Algorithm.World.Biomes
+{
+    public class BiomeSavanna : Biome
+    {
+        public BiomeSavanna(BiomeProperties properties, GeneratorSettings genSettings)
+            : base(properties, genSettings)
+        {
+            _name = "savanna";
+            _biomeId = BiomeId.Savanna;
+            _baseHeight = 0.125f;
+            _heightVariation = 0.05f;
+            _temperature = 1.2f;
+            _rainfall = 0.0f;
+            _enableSnow = false;
+            _enableRain = false;
+        }
+    }
+}

+ 4 - 0
src/MineCase.Algorithm/World/Layer/GenLayerBiome.cs

@@ -41,6 +41,10 @@ namespace MineCase.Algorithm.World.Layer
                         {
                         {
                             parentResult[i, j] = (int)BiomeId.Taiga;
                             parentResult[i, j] = (int)BiomeId.Taiga;
                         }
                         }
+                        else if (r >= 7 && r < 8)
+                        {
+                            parentResult[i, j] = (int)BiomeId.Savanna;
+                        }
                     }
                     }
                 }
                 }
             }
             }

+ 1 - 0
src/MineCase.Core/World/Biomes/BiomeId.cs

@@ -30,6 +30,7 @@ namespace MineCase.World.Biomes
         StoneShore = 25,
         StoneShore = 25,
         SnowyBeach = 26,
         SnowyBeach = 26,
         BirchForest = 27,
         BirchForest = 27,
+        Savanna = 35,
         WarmOcean = 44,
         WarmOcean = 44,
         LukewarmOcean = 45,
         LukewarmOcean = 45,
         ColdOcean = 46,
         ColdOcean = 46,

+ 1 - 1
src/MineCase.Core/World/Plants/PlantsType.cs

@@ -14,7 +14,7 @@ namespace MineCase.World.Plants
         Spruce,
         Spruce,
         Birch,
         Birch,
         JungleTree,
         JungleTree,
-        SavannaTree,
+        AcaciaTree,
 
 
         Sunflower,
         Sunflower,
         Lilac,
         Lilac,

+ 2 - 1
src/MineCase.Server.Grains/World/Decoration/Biomes/BiomePlainsDecoratorGrain.cs

@@ -98,13 +98,14 @@ namespace MineCase.Server.World.Decoration.Biomes
                     ExtraHeight = 20
                     ExtraHeight = 20
                 }));
                 }));
             await jungletreeGenerator.Generate(world, chunkWorldPos, 1);
             await jungletreeGenerator.Generate(world, chunkWorldPos, 1);
-            */
+
             var savannatreeGenerator = GrainFactory.GetGrain<ISavannaTreeGenerator>(
             var savannatreeGenerator = GrainFactory.GetGrain<ISavannaTreeGenerator>(
                 JsonConvert.SerializeObject(new PlantsInfo
                 JsonConvert.SerializeObject(new PlantsInfo
                 {
                 {
                     PlantType = PlantsType.SavannaTree,
                     PlantType = PlantsType.SavannaTree,
                 }));
                 }));
             await savannatreeGenerator.Generate(world, chunkWorldPos, 1);
             await savannatreeGenerator.Generate(world, chunkWorldPos, 1);
+            */
 
 
             var oaktreeGenerator = GrainFactory.GetGrain<ITreeGenerator>(
             var oaktreeGenerator = GrainFactory.GetGrain<ITreeGenerator>(
                 JsonConvert.SerializeObject(new PlantsInfo
                 JsonConvert.SerializeObject(new PlantsInfo

+ 60 - 2
src/MineCase.Server.Grains/World/Decoration/Biomes/BiomeSavannaDecoratorGrain.cs

@@ -2,8 +2,15 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using MineCase.Block;
+using MineCase.Server.Game.Entities;
+using MineCase.Server.World.Decoration.Plants;
 using MineCase.World;
 using MineCase.World;
+using MineCase.World.Biomes;
 using MineCase.World.Generation;
 using MineCase.World.Generation;
+using MineCase.World.Plants;
+using Newtonsoft.Json;
+using Orleans;
 using Orleans.Concurrency;
 using Orleans.Concurrency;
 
 
 namespace MineCase.Server.World.Decoration.Biomes
 namespace MineCase.Server.World.Decoration.Biomes
@@ -11,9 +18,60 @@ namespace MineCase.Server.World.Decoration.Biomes
     [StatelessWorker]
     [StatelessWorker]
     public class BiomeSavannaDecoratorGrain : BiomeDecoratorGrain, IBiomeSavannaDecorator
     public class BiomeSavannaDecoratorGrain : BiomeDecoratorGrain, IBiomeSavannaDecorator
     {
     {
-        public override Task Decorate(IWorld world, ChunkWorldPos chunkWorldPos, GeneratorSettings settings)
+        public override Task OnActivateAsync()
         {
         {
-            throw new NotImplementedException();
+            if (this.GetPrimaryKeyLong() == (long)BiomeId.Savanna)
+            {
+                BiomeProperties.BaseHeight = 0.125f;
+                BiomeProperties.HeightVariation = 0.05f;
+                BiomeProperties.Temperature = 1.2f;
+                BiomeProperties.Rainfall = 0.0f;
+                BiomeProperties.EnableSnow = false;
+                BiomeProperties.WaterColor = 16777215;
+                BiomeProperties.EnableRain = false;
+            }
+
+            TopBlock = BlockStates.GrassBlock();
+            FillerBlock = BlockStates.Dirt();
+
+            PlantsList.Add(PlantsType.TallGrass);
+            PlantsList.Add(PlantsType.AcaciaTree);
+
+            PassiveMobList.Add(MobType.Cow);
+            PassiveMobList.Add(MobType.Sheep);
+            PassiveMobList.Add(MobType.Horse);
+
+            MonsterList.Add(MobType.Creeper);
+            MonsterList.Add(MobType.Skeleton);
+            MonsterList.Add(MobType.Zombie);
+            MonsterList.Add(MobType.Spider);
+
+            return Task.CompletedTask;
+        }
+
+        public async override Task Decorate(IWorld world, ChunkWorldPos chunkWorldPos, GeneratorSettings settings)
+        {
+            await GenerateOre(world, chunkWorldPos, settings);
+
+            var grassGenerator = GrainFactory.GetGrain<IGrassGenerator>(JsonConvert.SerializeObject(new PlantsInfo { }));
+            await grassGenerator.Generate(world, chunkWorldPos, 10);
+
+            /*
+            var jungletreeGenerator = GrainFactory.GetGrain<IJungleGenerator>(
+                JsonConvert.SerializeObject(new PlantsInfo
+                {
+                    PlantType = PlantsType.Jungle,
+                    TreeHeight = 10,
+                    ExtraHeight = 20
+                }));
+            await jungletreeGenerator.Generate(world, chunkWorldPos, 1);
+            */
+            var savannatreeGenerator = GrainFactory.GetGrain<ISavannaTreeGenerator>(
+                JsonConvert.SerializeObject(new PlantsInfo
+                {
+                    PlantType = PlantsType.AcaciaTree,
+                }));
+            await savannatreeGenerator.Generate(world, chunkWorldPos, 1);
         }
         }
 
 
         public override Task SpawnMob(IWorld world, ChunkWorldPos chunkWorldPos, GeneratorSettings settings)
         public override Task SpawnMob(IWorld world, ChunkWorldPos chunkWorldPos, GeneratorSettings settings)

+ 16 - 16
src/MineCase.Server.Grains/World/Decoration/Plants/SavannaTreeGeneratorGrain.cs

@@ -35,32 +35,32 @@ namespace MineCase.Server.World.Decoration.Plants
 
 
         private async Task<bool> GenerateImpl(IWorld world, ChunkWorldPos chunkWorldPos, BlockWorldPos pos, Random rand)
         private async Task<bool> GenerateImpl(IWorld world, ChunkWorldPos chunkWorldPos, BlockWorldPos pos, Random rand)
         {
         {
-            int i = rand.Next(3) + rand.Next(3) + 5;
+            int height = rand.Next(3) + rand.Next(3) + 5;
             bool flag = true;
             bool flag = true;
 
 
-            if (pos.Y >= 1 && pos.Y + i + 1 <= 256)
+            if (pos.Y >= 1 && pos.Y + height + 1 <= 256)
             {
             {
-                for (int j = pos.Y; j <= pos.Y + 1 + i; ++j)
+                for (int y = pos.Y; y <= pos.Y + 1 + height; ++y)
                 {
                 {
-                    int k = 1;
+                    int xzRange = 1;
 
 
-                    if (j == pos.Y)
+                    if (y == pos.Y)
                     {
                     {
-                        k = 0;
+                        xzRange = 0;
                     }
                     }
 
 
-                    if (j >= pos.Y + 1 + i - 2)
+                    if (y >= pos.Y + 1 + height - 2)
                     {
                     {
-                        k = 2;
+                        xzRange = 2;
                     }
                     }
 
 
-                    for (int l = pos.X - k; l <= pos.X + k && flag; ++l)
+                    for (int xOffset = pos.X - xzRange; xOffset <= pos.X + xzRange && flag; ++xOffset)
                     {
                     {
-                        for (int i1 = pos.Z - k; i1 <= pos.Z + k && flag; ++i1)
+                        for (int zOffset = pos.Z - xzRange; zOffset <= pos.Z + xzRange && flag; ++zOffset)
                         {
                         {
-                            if (j >= 0 && j < 256)
+                            if (y >= 0 && y < 256)
                             {
                             {
-                                var blockState = await world.GetBlockStateUnsafe(this.GrainFactory, new BlockWorldPos(l, j, i1));
+                                var blockState = await world.GetBlockStateUnsafe(this.GrainFactory, new BlockWorldPos(xOffset, y, zOffset));
                                 if (!IsReplaceable(blockState))
                                 if (!IsReplaceable(blockState))
                                 {
                                 {
                                     flag = false;
                                     flag = false;
@@ -84,17 +84,17 @@ namespace MineCase.Server.World.Decoration.Plants
                     BlockState state = await world.GetBlockStateUnsafe(this.GrainFactory, down);
                     BlockState state = await world.GetBlockStateUnsafe(this.GrainFactory, down);
                     bool isSoil = IsSoil(state);
                     bool isSoil = IsSoil(state);
 
 
-                    if (isSoil && pos.Y < ChunkConstants.ChunkHeight - i - 1)
+                    if (isSoil && pos.Y < ChunkConstants.ChunkHeight - height - 1)
                     {
                     {
                         // state.getBlock().onPlantGrow(state, world, down, pos);
                         // state.getBlock().onPlantGrow(state, world, down, pos);
                         Facing enumfacing = Facing.RadomFacing(rand, Plane.XZ);
                         Facing enumfacing = Facing.RadomFacing(rand, Plane.XZ);
-                        int k2 = i - rand.Next(4) - 1;
+                        int k2 = height - rand.Next(4) - 1;
                         int l2 = 3 - rand.Next(3);
                         int l2 = 3 - rand.Next(3);
                         int i3 = pos.X;
                         int i3 = pos.X;
                         int j1 = pos.Z;
                         int j1 = pos.Z;
                         int k1 = 0;
                         int k1 = 0;
 
 
-                        for (int l1 = 0; l1 < i; ++l1)
+                        for (int l1 = 0; l1 < height; ++l1)
                         {
                         {
                             int i2 = pos.Y + l1;
                             int i2 = pos.Y + l1;
 
 
@@ -152,7 +152,7 @@ namespace MineCase.Server.World.Decoration.Plants
                             int k4 = 1 + rand.Next(3);
                             int k4 = 1 + rand.Next(3);
                             k1 = 0;
                             k1 = 0;
 
 
-                            for (int l4 = l3; l4 < i && k4 > 0; --k4)
+                            for (int l4 = l3; l4 < height && k4 > 0; --k4)
                             {
                             {
                                 if (l4 >= 1)
                                 if (l4 >= 1)
                                 {
                                 {

+ 5 - 0
src/MineCase.Server.Grains/World/Generation/ChunkGeneratorOverworldGrain.cs

@@ -121,6 +121,11 @@ namespace MineCase.Server.World.Generation
                 var decorator = GrainFactory.GetGrain<IBiomeTaigaDecorator>((long)BiomeId.Taiga);
                 var decorator = GrainFactory.GetGrain<IBiomeTaigaDecorator>((long)BiomeId.Taiga);
                 await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
                 await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
             }
             }
+            else if (chunkBiome.GetBiomeId() == BiomeId.Savanna)
+            {
+                var decorator = GrainFactory.GetGrain<IBiomeSavannaDecorator>((long)BiomeId.Savanna);
+                await decorator.Decorate(world, new ChunkWorldPos(x, z), settings);
+            }
         }
         }
 
 
         private void GenerateChunk(MapGenerationInfo info, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)
         private void GenerateChunk(MapGenerationInfo info, ChunkColumnStorage chunk, int x, int z, GeneratorSettings settings)

+ 3 - 3
src/MineCase.Server.Grains/World/WorldGrain.cs

@@ -90,9 +90,9 @@ namespace MineCase.Server.World
 
 
         public async Task<EntityWorldPos> GetSpawnPosition()
         public async Task<EntityWorldPos> GetSpawnPosition()
         {
         {
-            EntityWorldPos retval = new EntityWorldPos(8, 256, 8);
-            int height = await this.GetHeight(GrainFactory, new BlockWorldPos(8, 0, 8));
-            return new EntityWorldPos(8, height, 8);
+            EntityWorldPos retval = new EntityWorldPos(-8, 256, -8);
+            int height = await this.GetHeight(GrainFactory, new BlockWorldPos(-8, 0, -8));
+            return new EntityWorldPos(-8, height, -8);
         }
         }
 
 
         private void MarkDirty()
         private void MarkDirty()

+ 1 - 1
src/MineCase.Server/server.json

@@ -26,7 +26,7 @@
     "generate-structures": true,
     "generate-structures": true,
     "generator-settings": "",
     "generator-settings": "",
     "max-build-height": 256,
     "max-build-height": 256,
-    "level-seed": "minecase",
+    "level-seed": "MineCaseSeed",
     "level-type": "DEFAULT",
     "level-type": "DEFAULT",
     "enable-command-block": false,
     "enable-command-block": false,
     "hardcore": false,
     "hardcore": false,