From b2af7bde456cad3c7447f6ff06c09a441bbb44fa Mon Sep 17 00:00:00 2001 From: polytomous Date: Tue, 7 Nov 2017 13:55:57 -0800 Subject: [PATCH 1/9] Restructure if statement and extract variable for readability. --- TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index b3fac9d..9e8b86b 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -33,7 +33,8 @@ namespace TrueCraft.Core.TerrainGen.Decorators var blockLocation = new Coordinates3D(x, height, z); var sugarCaneLocation = blockLocation + Coordinates3D.Up; var neighborsWater = Decoration.NeighboursBlock(chunk, blockLocation, WaterBlock.BlockID) || Decoration.NeighboursBlock(chunk, blockLocation, StationaryWaterBlock.BlockID); - if (chunk.GetBlockID(blockLocation).Equals(GrassBlock.BlockID) && neighborsWater || chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID) && neighborsWater) + var sugarCaneCanGrowOnCurrentBlock = (chunk.GetBlockID(blockLocation).Equals(GrassBlock.BlockID) || chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID)); + if (neighborsWater && sugarCaneCanGrowOnCurrentBlock) { var random = new Random(world.Seed); double heightChance = random.NextDouble(); From 4c6316e0044cf2d37a0e9999dc588574a0b3204b Mon Sep 17 00:00:00 2001 From: polytomous Date: Tue, 7 Nov 2017 16:05:26 -0800 Subject: [PATCH 2/9] Add basic test for sugarcane growing. --- .../World/SugarCaneDecoratorTests.cs | 437 ++++++++++++++++++ .../TerrainGen/Decorations/Decoration.cs | 8 +- .../Decorators/SugarCaneDecorator.cs | 24 +- 3 files changed, 463 insertions(+), 6 deletions(-) create mode 100644 TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs new file mode 100644 index 0000000..358a0a0 --- /dev/null +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -0,0 +1,437 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing.Printing; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Security.Cryptography.X509Certificates; +using fNbt; +using NUnit.Framework; +using TrueCraft.API; +using TrueCraft.API.Logic; +using TrueCraft.API.World; +using TrueCraft.Core.Logic.Blocks; +using TrueCraft.Core.Networking.Packets; +using TrueCraft.Core.TerrainGen; +using TrueCraft.Core.TerrainGen.Biomes; +using TrueCraft.Core.TerrainGen.Decorators; +using TrueCraft.Core.TerrainGen.Noise; +using TrueCraft.Core.World; + +namespace TrueCraft.Core.Test.World +{ + public class WorldWithJustASeed : IWorld + { + public WorldWithJustASeed(int seed) + { + this.Seed = seed; + } + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public string Name { get; set; } + public IBlockRepository BlockRepository { get; set; } + public int Seed { get; set; } + public IBiomeMap BiomeDiagram { get; set; } + public IChunkProvider ChunkProvider { get; set; } + public Coordinates3D SpawnPoint { get; set; } + public long Time { get; set; } + public event EventHandler BlockChanged; + public event EventHandler ChunkGenerated; + public event EventHandler ChunkLoaded; + public IChunk GetChunk(Coordinates2D coordinates, bool generate = true) + { + throw new NotImplementedException(); + } + + public IChunk FindChunk(Coordinates3D coordinates, bool generate = true) + { + throw new NotImplementedException(); + } + + public byte GetBlockID(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetMetadata(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetBlockLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetSkyLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public Coordinates3D FindBlockPosition(Coordinates3D coordinates, out IChunk chunk, bool generate = true) + { + throw new NotImplementedException(); + } + + public NbtCompound GetTileEntity(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public BlockDescriptor GetBlockData(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public void SetBlockData(Coordinates3D coordinates, BlockDescriptor block) + { + throw new NotImplementedException(); + } + + public void SetBlockID(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetMetadata(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetSkyLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetBlockLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) + { + throw new NotImplementedException(); + } + + public bool IsValidPosition(Coordinates3D position) + { + throw new NotImplementedException(); + } + + public void Save() + { + throw new NotImplementedException(); + } + + public void Save(string path) + { + throw new NotImplementedException(); + } + } + + + public class NoiseAlwaysGrowsSugarCaneInTestBounds : NoiseGen + { + public override double Value2D(double x, double y) + { + return x > 5 ? 0 : (y > 5 ? 0 : 1); + } + + public override double Value3D(double x, double y, double z) + { + double value2d = Value2D(x, y); + + return 1; + } + } + + public class PrimeSugarCaneGrowingSeasonChunk : IChunk + { + public void Dispose() + { + throw new NotImplementedException(); + } + + public event EventHandler Disposed; + public int X => 6; + public int Z => 6; + public int MaxHeight => 7; + public Coordinates2D Coordinates { get; set; } + public bool IsModified { get; set; } + public bool LightPopulated { get; set; } + public int[] HeightMap => Enumerable.Repeat(1, Chunk.Width * Chunk.Height).ToArray(); + public byte[] Biomes => Enumerable.Repeat(new SwamplandBiome().ID, Chunk.Width*Chunk.Height).ToArray(); + + public DateTime LastAccessed { get; set; } + public byte[] Data { get; } + public bool TerrainPopulated { get; set; } + public Dictionary TileEntities { get; set; } + public NibbleSlice Metadata { get; } + public NibbleSlice BlockLight { get; } + public NibbleSlice SkyLight { get; } + public IRegion ParentRegion { get; set; } + public int GetHeight(byte x, byte z) + { + // Pretty sure this is always one since we have a flat surface + // (Unless water heights are reported differently) + return 1; + } + + public void UpdateHeightMap() + { + throw new NotImplementedException(); + } + + + private static byte MapXZToTestBlock(int X, int Z) + { + // Sand on the outer left hand side + if (X == 0) + { + return GrassBlock.BlockID; + } + + // Sand on the outer right hand side + if (X == 5) + { + return SandBlock.BlockID; + } + + if (Z == 0) + return WaterBlock.BlockID; + + if (Z == 3) + return StationaryWaterBlock.BlockID; + + switch (X) + { + case 1: + return GrassBlock.BlockID; + case 2: + return DirtBlock.BlockID; + case 3: + return SandBlock.BlockID; + case 4: + return StoneBlock.BlockID; + } + + // What's in that block? + // Back at me. + // I have it, it's a block that doesn't matter because it's beyond our test grid. + // Look again + // The block is now diamonds. + // Anything is possible when you're in a test mock + // I'm on a pig. + return DiamondBlock.BlockID; + } + + + private static Dictionary createStartingBlockDictionary() + { + int xBounds = 6; + int yBounds = 7; + int zBounds = 6; + + Dictionary blockDictionary = new Dictionary(); + + for (int x = 0; x < xBounds; x++) + { + for (int z = 0; z < zBounds; z++) + { + byte row1Blocks = MapXZToTestBlock(x, z); + for (int y = 0; y < yBounds; y++) + { + byte blockToStore = AirBlock.BlockID; + if (y == 0) + { + // Dirt on the lowest layer + blockToStore = DirtBlock.BlockID; + } + if (y == 1) + { + blockToStore = row1Blocks; + } + blockDictionary.Add(new Coordinates3D(x,y,z), blockToStore); + } + } + } + + return blockDictionary; + } + + private Dictionary blockDictionary = createStartingBlockDictionary(); + + + public byte GetBlockID(Coordinates3D coordinates) + { + if(blockDictionary.ContainsKey(coordinates)) + { + return blockDictionary[coordinates]; + } + return AirBlock.BlockID; + } + + public byte GetMetadata(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetSkyLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetBlockLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public void SetBlockID(Coordinates3D coordinates, byte value) + { + blockDictionary[coordinates] = value; + } + + public void SetMetadata(Coordinates3D coordinates, byte value) + { + // + } + + public void SetSkyLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetBlockLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public NbtCompound GetTileEntity(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) + { + throw new NotImplementedException(); + } + + public static int CountBlockInColumn(Dictionary aChunk, int x, int z, byte blockId) + { + int counter = 0; + + for (int y = 0; y < 7; y++) + { + byte block = aChunk[new Coordinates3D(x: x, y: y, z: z)]; + if (block == blockId) + { + counter++; + } + } + return counter; + } + + + public static HashSet PointsWithoutAnySugarcane() + { + var result = new HashSet(); + var startingDictionary = createStartingBlockDictionary(); + foreach (var block in createStartingBlockDictionary()) + { + var placesToGrow = CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, SandBlock.BlockID); + placesToGrow += CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, GrassBlock.BlockID); + + if (placesToGrow == 0) + { + result.Add(new Coordinates2D(block.Key.X, block.Key.Z)); + } + } + + result.Add(new Coordinates2D(0, 0)); + result.Add(new Coordinates2D(0, 1)); + result.Add(new Coordinates2D(0, 0)); + result.Add(new Coordinates2D(0, 2)); + result.Add(new Coordinates2D(0, 4)); + result.Add(new Coordinates2D(0, 5)); + + + for (int i = 1; i < 5; i++) + { + // Top row of the test data is all landlocked + result.Add(new Coordinates2D(i, 5)); + } + + result.Add(new Coordinates2D(5, 5)); + result.Add(new Coordinates2D(5, 4)); + result.Add(new Coordinates2D(5, 2)); + result.Add(new Coordinates2D(5, 1)); + + return result; + } + } + + + [TestFixture] + public class SugarCaneDecoratorTests + { + bool ContainsSugarCane(IChunk aChunk, int x, int z) + { + return CountBlockInColumn(aChunk, x, z, SugarcaneBlock.BlockID) > 0; + } + + static int CountBlockInColumn(IChunk aChunk, int x, int z, byte blockId) + { + int counter = 0; + + for (int y = 0; y < 7; y++) + { + byte block = aChunk.GetBlockID(new Coordinates3D(x:x, y:y, z:z)); + if (block == blockId) + { + counter++; + } + } + return counter; + } + + + [Test] + public void TestBasicDecorator() + { + var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); + IWorld aWorld = new WorldWithJustASeed(9001); + IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + IBiomeRepository aBiomeRepository = new BiomeRepository(); + aBiomeRepository.RegisterBiomeProvider(new SwamplandBiome()); + + decorator.Decorate(aWorld, aChunk, aBiomeRepository); + + AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(aChunk); + } + + private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(IChunk aChunk) + { + for (int x = 0; x < 6; x++) + { + for (int z = 0; z < 6; z++) + { + Coordinates2D coord = new Coordinates2D(x, z); + if (PrimeSugarCaneGrowingSeasonChunk.PointsWithoutAnySugarcane().Contains(coord)) + { + Assert.AreEqual(0, CountBlockInColumn(aChunk, x, z, SugarcaneBlock.BlockID), string.Format("Sugarcane in column ({0},{1})", x,z)); + } + } + } + } + } +} \ No newline at end of file diff --git a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs index 325540b..46f8eff 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs @@ -40,12 +40,12 @@ namespace TrueCraft.Core.TerrainGen.Decorations }; for (int i = 0; i < surrounding.Length; i++) { - var toCheck = surrounding[i]; - if (toCheck.X < 0 || toCheck.X >= Chunk.Width || toCheck.Z < 0 || toCheck.Z >= Chunk.Depth || toCheck.Y < 0 || toCheck.Y >= Chunk.Height) + var locationToCheck = surrounding[i]; + if (locationToCheck.X < 0 || locationToCheck.X >= Chunk.Width || locationToCheck.Z < 0 || locationToCheck.Z >= Chunk.Depth || locationToCheck.Y < 0 || locationToCheck.Y >= Chunk.Height) return false; - if (chunk.GetBlockID(toCheck).Equals(block)) + if (chunk.GetBlockID(locationToCheck).Equals(block)) { - if (meta != 0x0 && chunk.GetMetadata(toCheck) != meta) + if (meta != 0x0 && chunk.GetMetadata(locationToCheck) != meta) return false; return true; } diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index 9e8b86b..648ee22 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -13,16 +13,36 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public class SugarCaneDecorator : IChunkDecorator { + private readonly NoiseGen suppliedNoise; + + public SugarCaneDecorator() + { + suppliedNoise = null; + } + + public SugarCaneDecorator(NoiseGen suppliedNoiseSource) + { + suppliedNoise = suppliedNoiseSource; + } public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) { - var noise = new Perlin(world.Seed); + NoiseGen noise; + if (suppliedNoise == null) + { + noise = new Perlin(world.Seed); + } + else + { + noise = suppliedNoise; + } var chanceNoise = new ClampNoise(noise); chanceNoise.MaxValue = 1; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { - var biome = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]); + var chunkBiome = chunk.Biomes[x * Chunk.Width + z]; + var biome = biomes.GetBiome(chunkBiome); var height = chunk.HeightMap[x * Chunk.Width + z]; var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X); var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z); From 00a2d8d41b68711af0e538470cc05980c62416f3 Mon Sep 17 00:00:00 2001 From: polytomous Date: Tue, 7 Nov 2017 16:13:57 -0800 Subject: [PATCH 3/9] Add failing test for the sugar cane randomness bug --- .../World/SugarCaneDecoratorTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 358a0a0..4421810 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -417,6 +417,7 @@ namespace TrueCraft.Core.Test.World decorator.Decorate(aWorld, aChunk, aBiomeRepository); AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(aChunk); + AssertChunkSugarCaneGrowthIsNotUniform(aChunk); } private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(IChunk aChunk) @@ -433,5 +434,28 @@ namespace TrueCraft.Core.Test.World } } } + + private void AssertChunkSugarCaneGrowthIsNotUniform(IChunk aChunk) + { + var counts = new List(); + for (int x = 0; x < 6; x++) + { + for (int z = 0; z < 6; z++) + { + Coordinates2D coord = new Coordinates2D(x, z); + var countOfSugarCane = CountBlockInColumn(aChunk, x, z, SugarcaneBlock.BlockID); + if (countOfSugarCane != 0) + { + counts.Add(countOfSugarCane); + } + } + } + double averageOfSugarCaneHeight = counts.Average(); + + for (int i = 1; i < 7; i++) + { + Assert.AreNotEqual(i, averageOfSugarCaneHeight, "Sugarcane grew with uniform height."); + } + } } } \ No newline at end of file From 9fe14c3b1b4e0714a0686342129e4d1949f974a9 Mon Sep 17 00:00:00 2001 From: polytomous Date: Tue, 7 Nov 2017 16:15:23 -0800 Subject: [PATCH 4/9] Add simplest possible fix for randomness bug. Technically this is also two other bugs, but it's different bugs from the one this fixes. --- TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index 648ee22..e08a2a7 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -35,6 +35,8 @@ namespace TrueCraft.Core.TerrainGen.Decorators { noise = suppliedNoise; } + var random = new Random(world.Seed); + var chanceNoise = new ClampNoise(noise); chanceNoise.MaxValue = 1; for (int x = 0; x < 16; x++) @@ -56,7 +58,6 @@ namespace TrueCraft.Core.TerrainGen.Decorators var sugarCaneCanGrowOnCurrentBlock = (chunk.GetBlockID(blockLocation).Equals(GrassBlock.BlockID) || chunk.GetBlockID(blockLocation).Equals(SandBlock.BlockID)); if (neighborsWater && sugarCaneCanGrowOnCurrentBlock) { - var random = new Random(world.Seed); double heightChance = random.NextDouble(); int caneHeight = 3; if (heightChance < 0.05) From 9b54fe9cbe41eae22ae20fe5ea9af8a0082edd69 Mon Sep 17 00:00:00 2001 From: polytomous Date: Wed, 8 Nov 2017 21:48:45 -0800 Subject: [PATCH 5/9] Get serious about splitting test fakes out into seperate files and organizing code in fakes based on the order of consumption and then useless interface values --- .../World/SugarCaneDecoratorTests.cs | 439 ++---------------- .../NoiseAlwaysGrowsSugarCaneInTestBounds.cs | 19 + .../PrimeSugarCaneGrowingSeasonChunk.cs | 235 ++++++++++ .../World/TestFakes/WorldWithJustASeed.cs | 134 ++++++ 4 files changed, 429 insertions(+), 398 deletions(-) create mode 100644 TrueCraft.Core.Test/World/TestFakes/NoiseAlwaysGrowsSugarCaneInTestBounds.cs create mode 100644 TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs create mode 100644 TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 4421810..557c771 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -1,422 +1,42 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Drawing.Printing; +using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Security.Cryptography.X509Certificates; -using fNbt; using NUnit.Framework; using TrueCraft.API; -using TrueCraft.API.Logic; using TrueCraft.API.World; using TrueCraft.Core.Logic.Blocks; -using TrueCraft.Core.Networking.Packets; using TrueCraft.Core.TerrainGen; using TrueCraft.Core.TerrainGen.Biomes; using TrueCraft.Core.TerrainGen.Decorators; -using TrueCraft.Core.TerrainGen.Noise; -using TrueCraft.Core.World; +using TrueCraft.Core.Test.World.TestFakes; namespace TrueCraft.Core.Test.World { - public class WorldWithJustASeed : IWorld - { - public WorldWithJustASeed(int seed) - { - this.Seed = seed; - } - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public string Name { get; set; } - public IBlockRepository BlockRepository { get; set; } - public int Seed { get; set; } - public IBiomeMap BiomeDiagram { get; set; } - public IChunkProvider ChunkProvider { get; set; } - public Coordinates3D SpawnPoint { get; set; } - public long Time { get; set; } - public event EventHandler BlockChanged; - public event EventHandler ChunkGenerated; - public event EventHandler ChunkLoaded; - public IChunk GetChunk(Coordinates2D coordinates, bool generate = true) - { - throw new NotImplementedException(); - } - - public IChunk FindChunk(Coordinates3D coordinates, bool generate = true) - { - throw new NotImplementedException(); - } - - public byte GetBlockID(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetMetadata(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetBlockLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetSkyLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public Coordinates3D FindBlockPosition(Coordinates3D coordinates, out IChunk chunk, bool generate = true) - { - throw new NotImplementedException(); - } - - public NbtCompound GetTileEntity(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public BlockDescriptor GetBlockData(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public void SetBlockData(Coordinates3D coordinates, BlockDescriptor block) - { - throw new NotImplementedException(); - } - - public void SetBlockID(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetMetadata(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetSkyLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetBlockLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) - { - throw new NotImplementedException(); - } - - public bool IsValidPosition(Coordinates3D position) - { - throw new NotImplementedException(); - } - - public void Save() - { - throw new NotImplementedException(); - } - - public void Save(string path) - { - throw new NotImplementedException(); - } - } - - - public class NoiseAlwaysGrowsSugarCaneInTestBounds : NoiseGen - { - public override double Value2D(double x, double y) - { - return x > 5 ? 0 : (y > 5 ? 0 : 1); - } - - public override double Value3D(double x, double y, double z) - { - double value2d = Value2D(x, y); - - return 1; - } - } - - public class PrimeSugarCaneGrowingSeasonChunk : IChunk - { - public void Dispose() - { - throw new NotImplementedException(); - } - - public event EventHandler Disposed; - public int X => 6; - public int Z => 6; - public int MaxHeight => 7; - public Coordinates2D Coordinates { get; set; } - public bool IsModified { get; set; } - public bool LightPopulated { get; set; } - public int[] HeightMap => Enumerable.Repeat(1, Chunk.Width * Chunk.Height).ToArray(); - public byte[] Biomes => Enumerable.Repeat(new SwamplandBiome().ID, Chunk.Width*Chunk.Height).ToArray(); - - public DateTime LastAccessed { get; set; } - public byte[] Data { get; } - public bool TerrainPopulated { get; set; } - public Dictionary TileEntities { get; set; } - public NibbleSlice Metadata { get; } - public NibbleSlice BlockLight { get; } - public NibbleSlice SkyLight { get; } - public IRegion ParentRegion { get; set; } - public int GetHeight(byte x, byte z) - { - // Pretty sure this is always one since we have a flat surface - // (Unless water heights are reported differently) - return 1; - } - - public void UpdateHeightMap() - { - throw new NotImplementedException(); - } - - - private static byte MapXZToTestBlock(int X, int Z) - { - // Sand on the outer left hand side - if (X == 0) - { - return GrassBlock.BlockID; - } - - // Sand on the outer right hand side - if (X == 5) - { - return SandBlock.BlockID; - } - - if (Z == 0) - return WaterBlock.BlockID; - - if (Z == 3) - return StationaryWaterBlock.BlockID; - - switch (X) - { - case 1: - return GrassBlock.BlockID; - case 2: - return DirtBlock.BlockID; - case 3: - return SandBlock.BlockID; - case 4: - return StoneBlock.BlockID; - } - - // What's in that block? - // Back at me. - // I have it, it's a block that doesn't matter because it's beyond our test grid. - // Look again - // The block is now diamonds. - // Anything is possible when you're in a test mock - // I'm on a pig. - return DiamondBlock.BlockID; - } - - - private static Dictionary createStartingBlockDictionary() - { - int xBounds = 6; - int yBounds = 7; - int zBounds = 6; - - Dictionary blockDictionary = new Dictionary(); - - for (int x = 0; x < xBounds; x++) - { - for (int z = 0; z < zBounds; z++) - { - byte row1Blocks = MapXZToTestBlock(x, z); - for (int y = 0; y < yBounds; y++) - { - byte blockToStore = AirBlock.BlockID; - if (y == 0) - { - // Dirt on the lowest layer - blockToStore = DirtBlock.BlockID; - } - if (y == 1) - { - blockToStore = row1Blocks; - } - blockDictionary.Add(new Coordinates3D(x,y,z), blockToStore); - } - } - } - - return blockDictionary; - } - - private Dictionary blockDictionary = createStartingBlockDictionary(); - - - public byte GetBlockID(Coordinates3D coordinates) - { - if(blockDictionary.ContainsKey(coordinates)) - { - return blockDictionary[coordinates]; - } - return AirBlock.BlockID; - } - - public byte GetMetadata(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetSkyLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetBlockLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public void SetBlockID(Coordinates3D coordinates, byte value) - { - blockDictionary[coordinates] = value; - } - - public void SetMetadata(Coordinates3D coordinates, byte value) - { - // - } - - public void SetSkyLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetBlockLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public NbtCompound GetTileEntity(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) - { - throw new NotImplementedException(); - } - - public static int CountBlockInColumn(Dictionary aChunk, int x, int z, byte blockId) - { - int counter = 0; - - for (int y = 0; y < 7; y++) - { - byte block = aChunk[new Coordinates3D(x: x, y: y, z: z)]; - if (block == blockId) - { - counter++; - } - } - return counter; - } - - - public static HashSet PointsWithoutAnySugarcane() - { - var result = new HashSet(); - var startingDictionary = createStartingBlockDictionary(); - foreach (var block in createStartingBlockDictionary()) - { - var placesToGrow = CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, SandBlock.BlockID); - placesToGrow += CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, GrassBlock.BlockID); - - if (placesToGrow == 0) - { - result.Add(new Coordinates2D(block.Key.X, block.Key.Z)); - } - } - - result.Add(new Coordinates2D(0, 0)); - result.Add(new Coordinates2D(0, 1)); - result.Add(new Coordinates2D(0, 0)); - result.Add(new Coordinates2D(0, 2)); - result.Add(new Coordinates2D(0, 4)); - result.Add(new Coordinates2D(0, 5)); - - - for (int i = 1; i < 5; i++) - { - // Top row of the test data is all landlocked - result.Add(new Coordinates2D(i, 5)); - } - - result.Add(new Coordinates2D(5, 5)); - result.Add(new Coordinates2D(5, 4)); - result.Add(new Coordinates2D(5, 2)); - result.Add(new Coordinates2D(5, 1)); - - return result; - } - } - - [TestFixture] public class SugarCaneDecoratorTests { - bool ContainsSugarCane(IChunk aChunk, int x, int z) - { - return CountBlockInColumn(aChunk, x, z, SugarcaneBlock.BlockID) > 0; - } - - static int CountBlockInColumn(IChunk aChunk, int x, int z, byte blockId) - { - int counter = 0; - - for (int y = 0; y < 7; y++) - { - byte block = aChunk.GetBlockID(new Coordinates3D(x:x, y:y, z:z)); - if (block == blockId) - { - counter++; - } - } - return counter; - } - - [Test] - public void TestBasicDecorator() + public void DecoratorGrowsNoInvalidSugarCane() { - var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); IWorld aWorld = new WorldWithJustASeed(9001); IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); - aBiomeRepository.RegisterBiomeProvider(new SwamplandBiome()); - + var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); + decorator.Decorate(aWorld, aChunk, aBiomeRepository); AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(aChunk); + } + + [Test] + public void DecoratorDoesNotGrowSugarcaneUniformly() + { + IWorld aWorld = new WorldWithJustASeed(9001); + IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + IBiomeRepository aBiomeRepository = new BiomeRepository(); + var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); + + decorator.Decorate(aWorld, aChunk, aBiomeRepository); + AssertChunkSugarCaneGrowthIsNotUniform(aChunk); } @@ -452,10 +72,33 @@ namespace TrueCraft.Core.Test.World } double averageOfSugarCaneHeight = counts.Average(); - for (int i = 1; i < 7; i++) + for (int i = 0; i < 7; i++) { Assert.AreNotEqual(i, averageOfSugarCaneHeight, "Sugarcane grew with uniform height."); } } + + private static SugarCaneDecorator GetDecoratorForTestChunk(IWorld aWorld, IChunk aChunk, + IBiomeRepository aBiomeRepository) + { + var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); + aBiomeRepository.RegisterBiomeProvider(new SwamplandBiome()); + return decorator; + } + + static int CountBlockInColumn(IChunk aChunk, int x, int z, byte blockId) + { + int counter = 0; + + for (int y = 0; y < 7; y++) + { + byte block = aChunk.GetBlockID(new Coordinates3D(x: x, y: y, z: z)); + if (block == blockId) + { + counter++; + } + } + return counter; + } } } \ No newline at end of file diff --git a/TrueCraft.Core.Test/World/TestFakes/NoiseAlwaysGrowsSugarCaneInTestBounds.cs b/TrueCraft.Core.Test/World/TestFakes/NoiseAlwaysGrowsSugarCaneInTestBounds.cs new file mode 100644 index 0000000..70969bd --- /dev/null +++ b/TrueCraft.Core.Test/World/TestFakes/NoiseAlwaysGrowsSugarCaneInTestBounds.cs @@ -0,0 +1,19 @@ +using TrueCraft.Core.TerrainGen.Noise; + +namespace TrueCraft.Core.Test.World.TestFakes +{ + public class NoiseAlwaysGrowsSugarCaneInTestBounds : NoiseGen + { + public override double Value2D(double x, double y) + { + return x > 5 ? 0 : (y > 5 ? 0 : 1); + } + + public override double Value3D(double x, double y, double z) + { + double value2d = Value2D(x, y); + + return 1; + } + } +} diff --git a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs new file mode 100644 index 0000000..4aefa5c --- /dev/null +++ b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs @@ -0,0 +1,235 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using fNbt; +using TrueCraft.API; +using TrueCraft.API.World; +using TrueCraft.Core.Logic.Blocks; +using TrueCraft.Core.TerrainGen.Biomes; +using TrueCraft.Core.World; + +public class PrimeSugarCaneGrowingSeasonChunk : IChunk +{ + public int X => 6; + public int Z => 6; + public int MaxHeight => 7; + + public int[] HeightMap => Enumerable.Repeat(1, Chunk.Width * Chunk.Height).ToArray(); + public byte[] Biomes => Enumerable.Repeat(new SwamplandBiome().ID, Chunk.Width * Chunk.Height).ToArray(); + + public int GetHeight(byte x, byte z) + { + // Pretty sure this is always one since we have a flat surface + // (Unless water heights are reported differently) + return 1; + } + + private Dictionary blockDictionary = createStartingBlockDictionary(); + + public byte GetBlockID(Coordinates3D coordinates) + { + if (blockDictionary.ContainsKey(coordinates)) + { + return blockDictionary[coordinates]; + } + return AirBlock.BlockID; + } + + public void SetBlockID(Coordinates3D coordinates, byte value) + { + blockDictionary[coordinates] = value; + } + + public static int CountBlockInColumn(Dictionary aChunk, int x, int z, byte blockId) + { + int counter = 0; + + for (int y = 0; y < 7; y++) + { + byte block = aChunk[new Coordinates3D(x: x, y: y, z: z)]; + if (block == blockId) + { + counter++; + } + } + return counter; + } + + private static byte MapXZToTestBlock(int X, int Z) + { + // Sand on the outer left hand side + if (X == 0) + { + return GrassBlock.BlockID; + } + + // Sand on the outer right hand side + if (X == 5) + { + return SandBlock.BlockID; + } + + if (Z == 0) + return WaterBlock.BlockID; + + if (Z == 3) + return StationaryWaterBlock.BlockID; + + switch (X) + { + case 1: + return GrassBlock.BlockID; + case 2: + return DirtBlock.BlockID; + case 3: + return SandBlock.BlockID; + case 4: + return StoneBlock.BlockID; + } + + return DiamondBlock.BlockID; + } + + + private static Dictionary createStartingBlockDictionary() + { + int xBounds = 6; + int yBounds = 7; + int zBounds = 6; + + Dictionary blockDictionary = new Dictionary(); + + for (int x = 0; x < xBounds; x++) + { + for (int z = 0; z < zBounds; z++) + { + byte row1Blocks = MapXZToTestBlock(x, z); + for (int y = 0; y < yBounds; y++) + { + byte blockToStore = AirBlock.BlockID; + if (y == 0) + { + // Dirt on the lowest layer + blockToStore = DirtBlock.BlockID; + } + if (y == 1) + { + blockToStore = row1Blocks; + } + blockDictionary.Add(new Coordinates3D(x, y, z), blockToStore); + } + } + } + + return blockDictionary; + } + + + + + public static HashSet PointsWithoutAnySugarcane() + { + var result = new HashSet(); + var startingDictionary = createStartingBlockDictionary(); + foreach (var block in createStartingBlockDictionary()) + { + var placesToGrow = CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, SandBlock.BlockID); + placesToGrow += CountBlockInColumn(startingDictionary, block.Key.X, block.Key.Z, GrassBlock.BlockID); + + if (placesToGrow == 0) + { + result.Add(new Coordinates2D(block.Key.X, block.Key.Z)); + } + } + + result.Add(new Coordinates2D(0, 0)); + result.Add(new Coordinates2D(0, 1)); + result.Add(new Coordinates2D(0, 0)); + result.Add(new Coordinates2D(0, 2)); + result.Add(new Coordinates2D(0, 4)); + result.Add(new Coordinates2D(0, 5)); + + + for (int i = 1; i < 5; i++) + { + // Top row of the test data is all landlocked + result.Add(new Coordinates2D(i, 5)); + } + + result.Add(new Coordinates2D(5, 5)); + result.Add(new Coordinates2D(5, 4)); + result.Add(new Coordinates2D(5, 2)); + result.Add(new Coordinates2D(5, 1)); + + return result; + } + + + // Extra IChunk interface things we don't need for block decoration tests below. + public void Dispose() + { + throw new NotImplementedException(); + } + + public event EventHandler Disposed; + public Coordinates2D Coordinates { get; set; } + public bool IsModified { get; set; } + public bool LightPopulated { get; set; } + + public DateTime LastAccessed { get; set; } + public byte[] Data { get; } + public bool TerrainPopulated { get; set; } + public Dictionary TileEntities { get; set; } + public NibbleSlice Metadata { get; } + public NibbleSlice BlockLight { get; } + public NibbleSlice SkyLight { get; } + public IRegion ParentRegion { get; set; } + + public void UpdateHeightMap() + { + throw new NotImplementedException(); + } + + public byte GetMetadata(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetSkyLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetBlockLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + + public void SetMetadata(Coordinates3D coordinates, byte value) + { + // + } + + public void SetSkyLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetBlockLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public NbtCompound GetTileEntity(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) + { + throw new NotImplementedException(); + } + + +} diff --git a/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs b/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs new file mode 100644 index 0000000..c9d0122 --- /dev/null +++ b/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using fNbt; +using TrueCraft.API; +using TrueCraft.API.Logic; +using TrueCraft.API.World; + +namespace TrueCraft.Core.Test.World.TestFakes +{ + public class WorldWithJustASeed : IWorld + { + public WorldWithJustASeed(int seed) + { + this.Seed = seed; + } + + public int Seed { get; set; } + + // This is everything we don't need for block decoration tests. + + public IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public string Name { get; set; } + public IBlockRepository BlockRepository { get; set; } + public IBiomeMap BiomeDiagram { get; set; } + public IChunkProvider ChunkProvider { get; set; } + public Coordinates3D SpawnPoint { get; set; } + public long Time { get; set; } + public event EventHandler BlockChanged; + public event EventHandler ChunkGenerated; + public event EventHandler ChunkLoaded; + public IChunk GetChunk(Coordinates2D coordinates, bool generate = true) + { + throw new NotImplementedException(); + } + + public IChunk FindChunk(Coordinates3D coordinates, bool generate = true) + { + throw new NotImplementedException(); + } + + public byte GetBlockID(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetMetadata(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetBlockLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public byte GetSkyLight(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public Coordinates3D FindBlockPosition(Coordinates3D coordinates, out IChunk chunk, bool generate = true) + { + throw new NotImplementedException(); + } + + public NbtCompound GetTileEntity(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public BlockDescriptor GetBlockData(Coordinates3D coordinates) + { + throw new NotImplementedException(); + } + + public void SetBlockData(Coordinates3D coordinates, BlockDescriptor block) + { + throw new NotImplementedException(); + } + + public void SetBlockID(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetMetadata(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetSkyLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetBlockLight(Coordinates3D coordinates, byte value) + { + throw new NotImplementedException(); + } + + public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) + { + throw new NotImplementedException(); + } + + public bool IsValidPosition(Coordinates3D position) + { + throw new NotImplementedException(); + } + + public void Save() + { + throw new NotImplementedException(); + } + + public void Save(string path) + { + throw new NotImplementedException(); + } + } +} From 954221ce5cf7c2166e89b3dc2dcd9e01915b2ee3 Mon Sep 17 00:00:00 2001 From: polytomous Date: Wed, 8 Nov 2017 22:35:53 -0800 Subject: [PATCH 6/9] Jebaited MOCKS AWAITED Jebaited DOUBTS INITIATED Jebaited NOW WE JEBAITED Jebaited --- .../World/SugarCaneDecoratorTests.cs | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 557c771..7bdee21 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -1,5 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using Moq; using NUnit.Framework; using TrueCraft.API; using TrueCraft.API.World; @@ -7,7 +9,9 @@ using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen; using TrueCraft.Core.TerrainGen.Biomes; using TrueCraft.Core.TerrainGen.Decorators; +using TrueCraft.Core.Test.Logic; using TrueCraft.Core.Test.World.TestFakes; +using TrueCraft.Core.World; namespace TrueCraft.Core.Test.World { @@ -100,5 +104,55 @@ namespace TrueCraft.Core.Test.World } return counter; } + + [Test] + public void TestUsingAMock() + { + Mock aWorld = new Mock(); + aWorld.Setup(foo => foo.Seed).Returns(9001); + + var ourDictionary = PrimeSugarCaneGrowingSeasonChunk.createStartingBlockDictionary(); + + Mock aChunk = new Mock(); + + aChunk.Setup(foo => foo.GetBlockID(It.IsAny())).Returns((Coordinates3D coordinates) => + { + if (ourDictionary.ContainsKey(coordinates)) + { + return ourDictionary[coordinates]; + } + return AirBlock.BlockID; + }); + + aChunk.Setup(foo => foo.SetBlockID(It.IsAny(), + It.IsAny())).Callback((a, b) => + { + ourDictionary[a] = b; + }); + + aChunk.Setup(chunk => chunk.X).Returns(6); + aChunk.Setup(chunk => chunk.Z).Returns(6); + aChunk.Setup(chunk => chunk.MaxHeight).Returns(6); + + aChunk.Setup(chunk => chunk.HeightMap).Returns(() => + { + return Enumerable.Repeat(1, Chunk.Width * Chunk.Height).ToArray(); + }); + + aChunk.Setup(chunk => chunk.Biomes).Returns(() => + { + return Enumerable.Repeat(new SwamplandBiome().ID, Chunk.Width * Chunk.Height).ToArray(); + }); + + aChunk.Setup(chunk => chunk.GetHeight(It.IsAny(), It.IsAny())).Returns(1); + + + IBiomeRepository aBiomeRepository = new BiomeRepository(); + var decorator = GetDecoratorForTestChunk(aWorld.Object, aChunk.Object, aBiomeRepository); + + decorator.Decorate(aWorld.Object, aChunk.Object, aBiomeRepository); + + AssertChunkSugarCaneGrowthIsNotUniform(aChunk.Object); + } } } \ No newline at end of file From 0b90f6b8730391e2aeaa95f4e5dcd7defb286a3d Mon Sep 17 00:00:00 2001 From: polytomous Date: Wed, 8 Nov 2017 23:16:01 -0800 Subject: [PATCH 7/9] Make dependency on world seed and block repository from the world explicit --- TrueCraft.API/World/IChunkDecorator.cs | 3 +- TrueCraft.API/World/IDecoration.cs | 2 +- TrueCraft.API/World/IWorld.cs | 8 +- .../TrueCraft.Core.Test.csproj | 17 +-- .../World/SugarCaneDecoratorTests.cs | 13 +- .../PrimeSugarCaneGrowingSeasonChunk.cs | 2 +- .../World/TestFakes/WorldWithJustASeed.cs | 123 +----------------- .../TerrainGen/Decorations/BalloonOakTree.cs | 2 +- .../TerrainGen/Decorations/BirchTree.cs | 2 +- .../TerrainGen/Decorations/ConiferTree.cs | 2 +- .../TerrainGen/Decorations/Decoration.cs | 2 +- .../TerrainGen/Decorations/Dungeon.cs | 2 +- .../TerrainGen/Decorations/OakTree.cs | 2 +- .../TerrainGen/Decorations/PineTree.cs | 2 +- .../TerrainGen/Decorators/CactusDecorator.cs | 3 +- .../TerrainGen/Decorators/DungeonDecorator.cs | 3 +- .../TerrainGen/Decorators/FreezeDecorator.cs | 3 +- .../TerrainGen/Decorators/LiquidDecorator.cs | 3 +- .../TerrainGen/Decorators/OreDecorator.cs | 3 +- .../TerrainGen/Decorators/PlantDecorator.cs | 3 +- .../Decorators/SugarCaneDecorator.cs | 3 +- .../TerrainGen/Decorators/TreeDecorator.cs | 5 +- .../TerrainGen/StandardGenerator.cs | 2 +- TrueCraft.Core/TrueCraft.Core.csproj | 6 +- 24 files changed, 52 insertions(+), 164 deletions(-) diff --git a/TrueCraft.API/World/IChunkDecorator.cs b/TrueCraft.API/World/IChunkDecorator.cs index 412926f..878646b 100644 --- a/TrueCraft.API/World/IChunkDecorator.cs +++ b/TrueCraft.API/World/IChunkDecorator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using TrueCraft.API.Logic; namespace TrueCraft.API.World { @@ -10,6 +11,6 @@ namespace TrueCraft.API.World /// public interface IChunkDecorator { - void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes); + void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository); } } diff --git a/TrueCraft.API/World/IDecoration.cs b/TrueCraft.API/World/IDecoration.cs index bd87e45..3ce06f1 100644 --- a/TrueCraft.API/World/IDecoration.cs +++ b/TrueCraft.API/World/IDecoration.cs @@ -8,6 +8,6 @@ namespace TrueCraft.API.World public interface IDecoration { bool ValidLocation(Coordinates3D location); - bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location); + bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location); } } \ No newline at end of file diff --git a/TrueCraft.API/World/IWorld.cs b/TrueCraft.API/World/IWorld.cs index 5b4c643..f32827f 100644 --- a/TrueCraft.API/World/IWorld.cs +++ b/TrueCraft.API/World/IWorld.cs @@ -9,11 +9,10 @@ namespace TrueCraft.API.World /// /// An in-game world composed of chunks and blocks. /// - public interface IWorld : IEnumerable + public interface IWorld : IEnumerable, IWorldSeed { string Name { get; set; } IBlockRepository BlockRepository { get; set; } - int Seed { get; set; } IBiomeMap BiomeDiagram { get; set; } IChunkProvider ChunkProvider { get; set; } Coordinates3D SpawnPoint { get; set; } @@ -42,4 +41,9 @@ namespace TrueCraft.API.World void Save(); void Save(string path); } + + public interface IWorldSeed + { + int Seed { get; set; } + } } \ No newline at end of file diff --git a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj index b516541..6b8150f 100644 --- a/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj +++ b/TrueCraft.Core.Test/TrueCraft.Core.Test.csproj @@ -1,4 +1,4 @@ - + Debug @@ -81,9 +81,14 @@ + + + + + @@ -92,13 +97,5 @@ - - - - - - - - - + \ No newline at end of file diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 7bdee21..19ca011 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -21,12 +21,12 @@ namespace TrueCraft.Core.Test.World [Test] public void DecoratorGrowsNoInvalidSugarCane() { - IWorld aWorld = new WorldWithJustASeed(9001); + var aWorld = new WorldWithJustASeed(9001); IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); - decorator.Decorate(aWorld, aChunk, aBiomeRepository); + decorator.Decorate(aWorld, aChunk, aBiomeRepository, null /* Don't need to fake it if you don't use it. */); AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(aChunk); } @@ -34,12 +34,12 @@ namespace TrueCraft.Core.Test.World [Test] public void DecoratorDoesNotGrowSugarcaneUniformly() { - IWorld aWorld = new WorldWithJustASeed(9001); + IWorldSeed aWorld = new WorldWithJustASeed(9001); IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); - decorator.Decorate(aWorld, aChunk, aBiomeRepository); + decorator.Decorate(aWorld, aChunk, aBiomeRepository, null); AssertChunkSugarCaneGrowthIsNotUniform(aChunk); } @@ -82,7 +82,7 @@ namespace TrueCraft.Core.Test.World } } - private static SugarCaneDecorator GetDecoratorForTestChunk(IWorld aWorld, IChunk aChunk, + private static SugarCaneDecorator GetDecoratorForTestChunk(IWorldSeed aWorld, IChunk aChunk, IBiomeRepository aBiomeRepository) { var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); @@ -146,11 +146,12 @@ namespace TrueCraft.Core.Test.World aChunk.Setup(chunk => chunk.GetHeight(It.IsAny(), It.IsAny())).Returns(1); + IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld.Object, aChunk.Object, aBiomeRepository); - decorator.Decorate(aWorld.Object, aChunk.Object, aBiomeRepository); + decorator.Decorate(aWorld.Object, aChunk.Object, aBiomeRepository, null); AssertChunkSugarCaneGrowthIsNotUniform(aChunk.Object); } diff --git a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs index 4aefa5c..b9bf6d0 100644 --- a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs +++ b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs @@ -91,7 +91,7 @@ public class PrimeSugarCaneGrowingSeasonChunk : IChunk } - private static Dictionary createStartingBlockDictionary() + public static Dictionary createStartingBlockDictionary() { int xBounds = 6; int yBounds = 7; diff --git a/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs b/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs index c9d0122..901df55 100644 --- a/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs +++ b/TrueCraft.Core.Test/World/TestFakes/WorldWithJustASeed.cs @@ -1,17 +1,9 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using fNbt; -using TrueCraft.API; -using TrueCraft.API.Logic; + using TrueCraft.API.World; namespace TrueCraft.Core.Test.World.TestFakes { - public class WorldWithJustASeed : IWorld + public class WorldWithJustASeed : IWorldSeed { public WorldWithJustASeed(int seed) { @@ -19,116 +11,5 @@ namespace TrueCraft.Core.Test.World.TestFakes } public int Seed { get; set; } - - // This is everything we don't need for block decoration tests. - - public IEnumerator GetEnumerator() - { - throw new NotImplementedException(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public string Name { get; set; } - public IBlockRepository BlockRepository { get; set; } - public IBiomeMap BiomeDiagram { get; set; } - public IChunkProvider ChunkProvider { get; set; } - public Coordinates3D SpawnPoint { get; set; } - public long Time { get; set; } - public event EventHandler BlockChanged; - public event EventHandler ChunkGenerated; - public event EventHandler ChunkLoaded; - public IChunk GetChunk(Coordinates2D coordinates, bool generate = true) - { - throw new NotImplementedException(); - } - - public IChunk FindChunk(Coordinates3D coordinates, bool generate = true) - { - throw new NotImplementedException(); - } - - public byte GetBlockID(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetMetadata(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetBlockLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetSkyLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public Coordinates3D FindBlockPosition(Coordinates3D coordinates, out IChunk chunk, bool generate = true) - { - throw new NotImplementedException(); - } - - public NbtCompound GetTileEntity(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public BlockDescriptor GetBlockData(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public void SetBlockData(Coordinates3D coordinates, BlockDescriptor block) - { - throw new NotImplementedException(); - } - - public void SetBlockID(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetMetadata(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetSkyLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetBlockLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) - { - throw new NotImplementedException(); - } - - public bool IsValidPosition(Coordinates3D position) - { - throw new NotImplementedException(); - } - - public void Save() - { - throw new NotImplementedException(); - } - - public void Save(string path) - { - throw new NotImplementedException(); - } } } diff --git a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs index 6937cb6..e36aced 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs index 889ba16..4bedbc8 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs @@ -25,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs index 7a7cfd3..6d69f54 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs @@ -13,7 +13,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { const int LeafRadius = 2; - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs index 46f8eff..194543d 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs @@ -12,7 +12,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { public virtual bool ValidLocation(Coordinates3D location) { return true; } - public abstract bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location); + public abstract bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location); public static bool IsCuboidWall(Coordinates2D location, Coordinates3D start, Vector3 size) { diff --git a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs index 6edd523..2852483 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { Console.WriteLine("Dungeon in chunk {0}", chunk.Coordinates); if (!ValidLocation(location)) diff --git a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs index 3c17d19..2d7b033 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs index be12487..ef479e1 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorld world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs index a2b9671..eeaabf3 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs @@ -7,13 +7,14 @@ using TrueCraft.Core.World; using TrueCraft.Core.TerrainGen.Noise; using TrueCraft.Core.Logic.Blocks; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.TerrainGen.Decorations; namespace TrueCraft.Core.TerrainGen.Decorators { public class CactusDecorator : IChunkDecorator { - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); diff --git a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs index 18493f2..210bd7a 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs @@ -6,6 +6,7 @@ using TrueCraft.API.World; using TrueCraft.Core.World; using TrueCraft.Core.TerrainGen.Noise; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Decorations; @@ -20,7 +21,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators this.BaseLevel = groundLevel; } - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int attempts = 0; attempts < 8; attempts++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs index 1d1ea8d..4bf83fb 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs @@ -6,12 +6,13 @@ using TrueCraft.API.World; using TrueCraft.Core.World; using TrueCraft.Core.Logic.Blocks; using TrueCraft.API; +using TrueCraft.API.Logic; namespace TrueCraft.Core.TerrainGen.Decorators { class FreezeDecorator : IChunkDecorator { - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < 16; x++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs index 2e4aa69..3258a36 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using TrueCraft.API.World; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.World; using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Noise; @@ -14,7 +15,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public static readonly int WaterLevel = 40; - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < Chunk.Width; x++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs index 3f9f8d1..a0ad602 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs @@ -8,6 +8,7 @@ using TrueCraft.Core.World; using TrueCraft.API; using TrueCraft.Core.Logic.Blocks; using System.IO; +using TrueCraft.API.Logic; namespace TrueCraft.Core.TerrainGen.Decorators { @@ -53,7 +54,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators Ores.Add(redstone); } - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var perlin = new Perlin(world.Seed); perlin.Lacunarity = 1; diff --git a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs index 559ef76..c03eb48 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs @@ -6,13 +6,14 @@ using TrueCraft.API.World; using TrueCraft.Core.TerrainGen.Noise; using TrueCraft.Core.World; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.Logic.Blocks; namespace TrueCraft.Core.TerrainGen.Decorators { public class PlantDecorator : IChunkDecorator { - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index e08a2a7..5e070d7 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -6,6 +6,7 @@ using TrueCraft.API.World; using TrueCraft.Core.World; using TrueCraft.Core.TerrainGen.Noise; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Decorations; @@ -24,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { suppliedNoise = suppliedNoiseSource; } - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { NoiseGen noise; if (suppliedNoise == null) diff --git a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs index 6ed2b35..c214b6c 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using TrueCraft.API.World; using TrueCraft.API; +using TrueCraft.API.Logic; using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Noise; using TrueCraft.Core.World; @@ -16,7 +17,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators public Perlin Noise { get; set; } public ClampNoise ChanceNoise { get; set; } - public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes) + public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { Noise = new Perlin(world.Seed); ChanceNoise = new ClampNoise(Noise); @@ -38,7 +39,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { var location = new Coordinates3D(x, height, z); var id = chunk.GetBlockID(location); - var provider = world.BlockRepository.GetBlockProvider(id); + var provider = blockRepository.GetBlockProvider(id); if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID || (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID && id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID diff --git a/TrueCraft.Core/TerrainGen/StandardGenerator.cs b/TrueCraft.Core/TerrainGen/StandardGenerator.cs index 6b095c9..51dfa83 100644 --- a/TrueCraft.Core/TerrainGen/StandardGenerator.cs +++ b/TrueCraft.Core/TerrainGen/StandardGenerator.cs @@ -189,7 +189,7 @@ namespace TrueCraft.Core.TerrainGen } } foreach (var decorator in ChunkDecorators) - decorator.Decorate(world, chunk, Biomes); + decorator.Decorate(world, chunk, Biomes, world.BlockRepository); chunk.TerrainPopulated = true; chunk.UpdateHeightMap(); return chunk; diff --git a/TrueCraft.Core/TrueCraft.Core.csproj b/TrueCraft.Core/TrueCraft.Core.csproj index 246f610..2da648e 100644 --- a/TrueCraft.Core/TrueCraft.Core.csproj +++ b/TrueCraft.Core/TrueCraft.Core.csproj @@ -372,11 +372,7 @@ TrueCraft.Profiling - - - - - + From 22b944a18989b966512d1f8d7e20ec2bf699a266 Mon Sep 17 00:00:00 2001 From: polytomous Date: Wed, 8 Nov 2017 23:44:14 -0800 Subject: [PATCH 8/9] Factor out block information interface. Using a nonsense name because I haven't decided what the right name should be. --- TrueCraft.API/World/ApplesauceChunk.cs | 31 +++++++ TrueCraft.API/World/IChunk.cs | 13 +-- TrueCraft.API/World/IChunkDecorator.cs | 2 +- TrueCraft.API/World/IDecoration.cs | 2 +- .../World/SugarCaneDecoratorTests.cs | 14 ++-- .../PrimeSugarCaneGrowingSeasonChunk.cs | 84 ++++--------------- .../TerrainGen/Decorations/BalloonOakTree.cs | 2 +- .../TerrainGen/Decorations/BirchTree.cs | 2 +- .../TerrainGen/Decorations/ConiferTree.cs | 2 +- .../TerrainGen/Decorations/Decoration.cs | 16 ++-- .../TerrainGen/Decorations/Dungeon.cs | 8 +- .../TerrainGen/Decorations/OakTree.cs | 2 +- .../TerrainGen/Decorations/PineTree.cs | 4 +- .../TerrainGen/Decorators/CactusDecorator.cs | 2 +- .../TerrainGen/Decorators/DungeonDecorator.cs | 2 +- .../TerrainGen/Decorators/FreezeDecorator.cs | 4 +- .../TerrainGen/Decorators/LiquidDecorator.cs | 2 +- .../TerrainGen/Decorators/OreDecorator.cs | 2 +- .../TerrainGen/Decorators/PlantDecorator.cs | 10 +-- .../Decorators/SugarCaneDecorator.cs | 2 +- .../TerrainGen/Decorators/TreeDecorator.cs | 2 +- 21 files changed, 86 insertions(+), 122 deletions(-) create mode 100644 TrueCraft.API/World/ApplesauceChunk.cs diff --git a/TrueCraft.API/World/ApplesauceChunk.cs b/TrueCraft.API/World/ApplesauceChunk.cs new file mode 100644 index 0000000..d38859c --- /dev/null +++ b/TrueCraft.API/World/ApplesauceChunk.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrueCraft.API.World +{ + public interface ApplesauceChunk + { + int X {get;} + int Z { get; } + int MaxHeight { get; } + + int[] HeightMap { get; } + + byte[] Biomes { get; } + + + int GetHeight(byte x, byte z); + + + // This is really all one related concept. + byte GetBlockID(Coordinates3D coordinates); + void SetBlockID(Coordinates3D coordinates, byte value); + byte GetMetadata(Coordinates3D locationToCheck); + void SetMetadata(Coordinates3D blockLocation, byte meta); + + Coordinates2D Coordinates { get; set; } + } +} diff --git a/TrueCraft.API/World/IChunk.cs b/TrueCraft.API/World/IChunk.cs index 08f729a..9ea2a41 100644 --- a/TrueCraft.API/World/IChunk.cs +++ b/TrueCraft.API/World/IChunk.cs @@ -4,16 +4,10 @@ using System.Collections.Generic; namespace TrueCraft.API.World { - public interface IChunk : IEventSubject, IDisposable + public interface IChunk : IEventSubject, IDisposable, ApplesauceChunk { - int X { get; } - int Z { get; } - int MaxHeight { get; } - Coordinates2D Coordinates { get; set; } bool IsModified { get; set; } bool LightPopulated { get; set; } - int[] HeightMap { get; } - byte[] Biomes { get; } DateTime LastAccessed { get; set; } byte[] Data { get; } bool TerrainPopulated { get; set; } @@ -22,14 +16,9 @@ namespace TrueCraft.API.World NibbleSlice BlockLight { get; } NibbleSlice SkyLight { get; } IRegion ParentRegion { get; set; } - int GetHeight(byte x, byte z); void UpdateHeightMap(); - byte GetBlockID(Coordinates3D coordinates); - byte GetMetadata(Coordinates3D coordinates); byte GetSkyLight(Coordinates3D coordinates); byte GetBlockLight(Coordinates3D coordinates); - void SetBlockID(Coordinates3D coordinates, byte value); - void SetMetadata(Coordinates3D coordinates, byte value); void SetSkyLight(Coordinates3D coordinates, byte value); void SetBlockLight(Coordinates3D coordinates, byte value); NbtCompound GetTileEntity(Coordinates3D coordinates); diff --git a/TrueCraft.API/World/IChunkDecorator.cs b/TrueCraft.API/World/IChunkDecorator.cs index 878646b..0ac378c 100644 --- a/TrueCraft.API/World/IChunkDecorator.cs +++ b/TrueCraft.API/World/IChunkDecorator.cs @@ -11,6 +11,6 @@ namespace TrueCraft.API.World /// public interface IChunkDecorator { - void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository); + void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository); } } diff --git a/TrueCraft.API/World/IDecoration.cs b/TrueCraft.API/World/IDecoration.cs index 3ce06f1..8ca7668 100644 --- a/TrueCraft.API/World/IDecoration.cs +++ b/TrueCraft.API/World/IDecoration.cs @@ -8,6 +8,6 @@ namespace TrueCraft.API.World public interface IDecoration { bool ValidLocation(Coordinates3D location); - bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location); + bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location); } } \ No newline at end of file diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 19ca011..3cb5a23 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -22,7 +22,7 @@ namespace TrueCraft.Core.Test.World public void DecoratorGrowsNoInvalidSugarCane() { var aWorld = new WorldWithJustASeed(9001); - IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + ApplesauceChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); @@ -35,7 +35,7 @@ namespace TrueCraft.Core.Test.World public void DecoratorDoesNotGrowSugarcaneUniformly() { IWorldSeed aWorld = new WorldWithJustASeed(9001); - IChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + ApplesauceChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); @@ -44,7 +44,7 @@ namespace TrueCraft.Core.Test.World AssertChunkSugarCaneGrowthIsNotUniform(aChunk); } - private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(IChunk aChunk) + private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(ApplesauceChunk aChunk) { for (int x = 0; x < 6; x++) { @@ -59,7 +59,7 @@ namespace TrueCraft.Core.Test.World } } - private void AssertChunkSugarCaneGrowthIsNotUniform(IChunk aChunk) + private void AssertChunkSugarCaneGrowthIsNotUniform(ApplesauceChunk aChunk) { var counts = new List(); for (int x = 0; x < 6; x++) @@ -82,7 +82,7 @@ namespace TrueCraft.Core.Test.World } } - private static SugarCaneDecorator GetDecoratorForTestChunk(IWorldSeed aWorld, IChunk aChunk, + private static SugarCaneDecorator GetDecoratorForTestChunk(IWorldSeed aWorld, ApplesauceChunk aChunk, IBiomeRepository aBiomeRepository) { var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); @@ -90,7 +90,7 @@ namespace TrueCraft.Core.Test.World return decorator; } - static int CountBlockInColumn(IChunk aChunk, int x, int z, byte blockId) + static int CountBlockInColumn(ApplesauceChunk aChunk, int x, int z, byte blockId) { int counter = 0; @@ -113,7 +113,7 @@ namespace TrueCraft.Core.Test.World var ourDictionary = PrimeSugarCaneGrowingSeasonChunk.createStartingBlockDictionary(); - Mock aChunk = new Mock(); + Mock aChunk = new Mock(); aChunk.Setup(foo => foo.GetBlockID(It.IsAny())).Returns((Coordinates3D coordinates) => { diff --git a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs index b9bf6d0..31c2d80 100644 --- a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs +++ b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs @@ -8,7 +8,7 @@ using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Biomes; using TrueCraft.Core.World; -public class PrimeSugarCaneGrowingSeasonChunk : IChunk +public class PrimeSugarCaneGrowingSeasonChunk : ApplesauceChunk { public int X => 6; public int Z => 6; @@ -40,6 +40,18 @@ public class PrimeSugarCaneGrowingSeasonChunk : IChunk blockDictionary[coordinates] = value; } + public int GetMetadata(Coordinates3D locationToCheck) + { + return -1; + } + + public void SetMetadata(Coordinates3D blockLocation, byte meta) + { + // + } + + public Coordinates2D Coordinates { get; set; } + public static int CountBlockInColumn(Dictionary aChunk, int x, int z, byte blockId) { int counter = 0; @@ -90,7 +102,6 @@ public class PrimeSugarCaneGrowingSeasonChunk : IChunk return DiamondBlock.BlockID; } - public static Dictionary createStartingBlockDictionary() { int xBounds = 6; @@ -124,9 +135,6 @@ public class PrimeSugarCaneGrowingSeasonChunk : IChunk return blockDictionary; } - - - public static HashSet PointsWithoutAnySugarcane() { var result = new HashSet(); @@ -164,72 +172,8 @@ public class PrimeSugarCaneGrowingSeasonChunk : IChunk return result; } - - // Extra IChunk interface things we don't need for block decoration tests below. - public void Dispose() + byte ApplesauceChunk.GetMetadata(Coordinates3D locationToCheck) { throw new NotImplementedException(); } - - public event EventHandler Disposed; - public Coordinates2D Coordinates { get; set; } - public bool IsModified { get; set; } - public bool LightPopulated { get; set; } - - public DateTime LastAccessed { get; set; } - public byte[] Data { get; } - public bool TerrainPopulated { get; set; } - public Dictionary TileEntities { get; set; } - public NibbleSlice Metadata { get; } - public NibbleSlice BlockLight { get; } - public NibbleSlice SkyLight { get; } - public IRegion ParentRegion { get; set; } - - public void UpdateHeightMap() - { - throw new NotImplementedException(); - } - - public byte GetMetadata(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetSkyLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public byte GetBlockLight(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - - public void SetMetadata(Coordinates3D coordinates, byte value) - { - // - } - - public void SetSkyLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public void SetBlockLight(Coordinates3D coordinates, byte value) - { - throw new NotImplementedException(); - } - - public NbtCompound GetTileEntity(Coordinates3D coordinates) - { - throw new NotImplementedException(); - } - - public void SetTileEntity(Coordinates3D coordinates, NbtCompound value) - { - throw new NotImplementedException(); - } - - } diff --git a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs index e36aced..e3bcc20 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs index 4bedbc8..6fd63de 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs @@ -25,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs index 6d69f54..e26cbab 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs @@ -13,7 +13,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { const int LeafRadius = 2; - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs index 194543d..cac6d5f 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs @@ -12,7 +12,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { public virtual bool ValidLocation(Coordinates3D location) { return true; } - public abstract bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location); + public abstract bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location); public static bool IsCuboidWall(Coordinates2D location, Coordinates3D start, Vector3 size) { @@ -30,7 +30,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations || location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z + (int)size.Z - 1); } - public static bool NeighboursBlock(IChunk chunk, Coordinates3D location, byte block, byte meta = 0x0) + public static bool NeighboursBlock(ApplesauceChunk chunk, Coordinates3D location, byte block, byte meta = 0x0) { var surrounding = new[] { location + Coordinates3D.Left, @@ -53,7 +53,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return false; } - public static void GenerateColumn(IChunk chunk, Coordinates3D location, int height, byte block, byte meta = 0x0) + public static void GenerateColumn(ApplesauceChunk chunk, Coordinates3D location, int height, byte block, byte meta = 0x0) { for (int offset = 0; offset < height; offset++) { @@ -71,7 +71,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations * 0x1 - Hollow cuboid of the specified block * 0x2 - Outlines the area of the cuboid using the specified block */ - public static void GenerateCuboid(IChunk chunk, Coordinates3D location, Vector3 size, byte block, byte meta = 0x0, byte mode = 0x0) + public static void GenerateCuboid(ApplesauceChunk chunk, Coordinates3D location, Vector3 size, byte block, byte meta = 0x0, byte mode = 0x0) { //If mode is 0x2 offset the size by 2 and change mode to 0x1 if (mode.Equals(0x2)) @@ -102,7 +102,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateVanillaLeaves(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected void GenerateVanillaLeaves(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { int radiusOffset = radius; for (int yOffset = -radius; yOffset <= radius; yOffset = (yOffset + 1)) @@ -116,7 +116,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateVanillaCircle(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0) + protected void GenerateVanillaCircle(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0) { for (int i = -radius; i <= radius; i = (i + 1)) { @@ -146,7 +146,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateCircle(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected void GenerateCircle(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { for (int i = -radius; i <= radius; i = (i + 1)) { @@ -172,7 +172,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected static void GenerateSphere(IChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected static void GenerateSphere(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { for (int i = -radius; i <= radius; i = (i + 1)) { diff --git a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs index 2852483..d1445ff 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { Console.WriteLine("Dungeon in chunk {0}", chunk.Coordinates); if (!ValidLocation(location)) @@ -52,7 +52,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - private void CreateEntraces(IChunk chunk, Coordinates3D location, Random random) + private void CreateEntraces(ApplesauceChunk chunk, Coordinates3D location, Random random) { int entrances = 0; var above = location + Coordinates3D.Up; @@ -80,7 +80,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - private void MossFloor(IChunk chunk, Coordinates3D location, Random random) + private void MossFloor(ApplesauceChunk chunk, Coordinates3D location, Random random) { for (int x = location.X; x < location.X + Size.X; x++) { @@ -96,7 +96,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - private void PlaceChests(IChunk chunk, Coordinates3D location, Random random) + private void PlaceChests(ApplesauceChunk chunk, Coordinates3D location, Random random) { var above = location + Coordinates3D.Up; var chests = random.Next(0, 2); diff --git a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs index 2d7b033..6d74635 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs index ef479e1..7d21b94 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, IChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; @@ -51,7 +51,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations * 0x0 - two level topper * 0x1 - three level topper */ - protected void GenerateTopper(IChunk chunk, Coordinates3D location, byte type = 0x0) + protected void GenerateTopper(ApplesauceChunk chunk, Coordinates3D location, byte type = 0x0) { const int sectionRadius = 1; GenerateCircle(chunk, location, sectionRadius, LeavesBlock.BlockID, 0x1); diff --git a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs index eeaabf3..ccb37f9 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs @@ -14,7 +14,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public class CactusDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); diff --git a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs index 210bd7a..10c0812 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs @@ -21,7 +21,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators this.BaseLevel = groundLevel; } - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int attempts = 0; attempts < 8; attempts++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs index 4bf83fb..a238147 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs @@ -12,7 +12,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { class FreezeDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < 16; x++) { @@ -51,7 +51,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators } } - bool CoverIce(IChunk chunk, IBiomeRepository biomes, Coordinates3D location) + bool CoverIce(ApplesauceChunk chunk, IBiomeRepository biomes, Coordinates3D location) { const int maxDistance = 4; var adjacent = new[] { diff --git a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs index 3258a36..e85e75e 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs @@ -15,7 +15,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public static readonly int WaterLevel = 40; - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < Chunk.Width; x++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs index a0ad602..ebaf35a 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs @@ -54,7 +54,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators Ores.Add(redstone); } - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var perlin = new Perlin(world.Seed); perlin.Lacunarity = 1; diff --git a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs index c03eb48..1f9d984 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs @@ -13,7 +13,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public class PlantDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); @@ -68,23 +68,23 @@ namespace TrueCraft.Core.TerrainGen.Decorators } } - void GenerateRose(IChunk chunk, Coordinates3D location) + void GenerateRose(ApplesauceChunk chunk, Coordinates3D location) { chunk.SetBlockID(location, RoseBlock.BlockID); } - void GenerateDandelion(IChunk chunk, Coordinates3D location) + void GenerateDandelion(ApplesauceChunk chunk, Coordinates3D location) { chunk.SetBlockID(location, DandelionBlock.BlockID); } - void GenerateTallGrass(IChunk chunk, Coordinates3D location, byte meta) + void GenerateTallGrass(ApplesauceChunk chunk, Coordinates3D location, byte meta) { chunk.SetBlockID(location, TallGrassBlock.BlockID); chunk.SetMetadata(location, meta); } - void GenerateDeadBush(IChunk chunk, Coordinates3D location) + void GenerateDeadBush(ApplesauceChunk chunk, Coordinates3D location) { chunk.SetBlockID(location, DeadBushBlock.BlockID); } diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index 5e070d7..96dc551 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -25,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { suppliedNoise = suppliedNoiseSource; } - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { NoiseGen noise; if (suppliedNoise == null) diff --git a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs index c214b6c..d7f8067 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs @@ -17,7 +17,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators public Perlin Noise { get; set; } public ClampNoise ChanceNoise { get; set; } - public void Decorate(IWorldSeed world, IChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { Noise = new Perlin(world.Seed); ChanceNoise = new ClampNoise(Noise); From 0bb3541d23c622e61060d37f7e5d7562af5ac68c Mon Sep 17 00:00:00 2001 From: polytomous Date: Wed, 8 Nov 2017 23:48:19 -0800 Subject: [PATCH 9/9] Switch to a serious name I like --- TrueCraft.API/World/IChunk.cs | 2 +- TrueCraft.API/World/IChunkDecorator.cs | 2 +- TrueCraft.API/World/IDecoration.cs | 2 +- ...nk.cs => ISpatialBlockInformationProvider.cs} | 2 +- .../World/SugarCaneDecoratorTests.cs | 14 +++++++------- .../PrimeSugarCaneGrowingSeasonChunk.cs | 4 ++-- .../TerrainGen/Decorations/BalloonOakTree.cs | 2 +- .../TerrainGen/Decorations/BirchTree.cs | 2 +- .../TerrainGen/Decorations/ConiferTree.cs | 2 +- .../TerrainGen/Decorations/Decoration.cs | 16 ++++++++-------- TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs | 8 ++++---- TrueCraft.Core/TerrainGen/Decorations/OakTree.cs | 2 +- .../TerrainGen/Decorations/PineTree.cs | 4 ++-- .../TerrainGen/Decorators/CactusDecorator.cs | 2 +- .../TerrainGen/Decorators/DungeonDecorator.cs | 2 +- .../TerrainGen/Decorators/FreezeDecorator.cs | 4 ++-- .../TerrainGen/Decorators/LiquidDecorator.cs | 2 +- .../TerrainGen/Decorators/OreDecorator.cs | 2 +- .../TerrainGen/Decorators/PlantDecorator.cs | 10 +++++----- .../TerrainGen/Decorators/SugarCaneDecorator.cs | 2 +- .../TerrainGen/Decorators/TreeDecorator.cs | 2 +- 21 files changed, 44 insertions(+), 44 deletions(-) rename TrueCraft.API/World/{ApplesauceChunk.cs => ISpatialBlockInformationProvider.cs} (92%) diff --git a/TrueCraft.API/World/IChunk.cs b/TrueCraft.API/World/IChunk.cs index 9ea2a41..2cb9388 100644 --- a/TrueCraft.API/World/IChunk.cs +++ b/TrueCraft.API/World/IChunk.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace TrueCraft.API.World { - public interface IChunk : IEventSubject, IDisposable, ApplesauceChunk + public interface IChunk : IEventSubject, IDisposable, ISpatialBlockInformationProvider { bool IsModified { get; set; } bool LightPopulated { get; set; } diff --git a/TrueCraft.API/World/IChunkDecorator.cs b/TrueCraft.API/World/IChunkDecorator.cs index 0ac378c..7a968c5 100644 --- a/TrueCraft.API/World/IChunkDecorator.cs +++ b/TrueCraft.API/World/IChunkDecorator.cs @@ -11,6 +11,6 @@ namespace TrueCraft.API.World /// public interface IChunkDecorator { - void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository); + void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository); } } diff --git a/TrueCraft.API/World/IDecoration.cs b/TrueCraft.API/World/IDecoration.cs index 8ca7668..86e311f 100644 --- a/TrueCraft.API/World/IDecoration.cs +++ b/TrueCraft.API/World/IDecoration.cs @@ -8,6 +8,6 @@ namespace TrueCraft.API.World public interface IDecoration { bool ValidLocation(Coordinates3D location); - bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location); + bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location); } } \ No newline at end of file diff --git a/TrueCraft.API/World/ApplesauceChunk.cs b/TrueCraft.API/World/ISpatialBlockInformationProvider.cs similarity index 92% rename from TrueCraft.API/World/ApplesauceChunk.cs rename to TrueCraft.API/World/ISpatialBlockInformationProvider.cs index d38859c..f0e65ce 100644 --- a/TrueCraft.API/World/ApplesauceChunk.cs +++ b/TrueCraft.API/World/ISpatialBlockInformationProvider.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace TrueCraft.API.World { - public interface ApplesauceChunk + public interface ISpatialBlockInformationProvider { int X {get;} int Z { get; } diff --git a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs index 3cb5a23..70e3de7 100644 --- a/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs +++ b/TrueCraft.Core.Test/World/SugarCaneDecoratorTests.cs @@ -22,7 +22,7 @@ namespace TrueCraft.Core.Test.World public void DecoratorGrowsNoInvalidSugarCane() { var aWorld = new WorldWithJustASeed(9001); - ApplesauceChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + ISpatialBlockInformationProvider aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); @@ -35,7 +35,7 @@ namespace TrueCraft.Core.Test.World public void DecoratorDoesNotGrowSugarcaneUniformly() { IWorldSeed aWorld = new WorldWithJustASeed(9001); - ApplesauceChunk aChunk = new PrimeSugarCaneGrowingSeasonChunk(); + ISpatialBlockInformationProvider aChunk = new PrimeSugarCaneGrowingSeasonChunk(); IBiomeRepository aBiomeRepository = new BiomeRepository(); var decorator = GetDecoratorForTestChunk(aWorld, aChunk, aBiomeRepository); @@ -44,7 +44,7 @@ namespace TrueCraft.Core.Test.World AssertChunkSugarCaneGrowthIsNotUniform(aChunk); } - private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(ApplesauceChunk aChunk) + private void AssertChunkHasNoSugarCaneInColumnsWhereItShouldNot(ISpatialBlockInformationProvider aChunk) { for (int x = 0; x < 6; x++) { @@ -59,7 +59,7 @@ namespace TrueCraft.Core.Test.World } } - private void AssertChunkSugarCaneGrowthIsNotUniform(ApplesauceChunk aChunk) + private void AssertChunkSugarCaneGrowthIsNotUniform(ISpatialBlockInformationProvider aChunk) { var counts = new List(); for (int x = 0; x < 6; x++) @@ -82,7 +82,7 @@ namespace TrueCraft.Core.Test.World } } - private static SugarCaneDecorator GetDecoratorForTestChunk(IWorldSeed aWorld, ApplesauceChunk aChunk, + private static SugarCaneDecorator GetDecoratorForTestChunk(IWorldSeed aWorld, ISpatialBlockInformationProvider aChunk, IBiomeRepository aBiomeRepository) { var decorator = new SugarCaneDecorator(new NoiseAlwaysGrowsSugarCaneInTestBounds()); @@ -90,7 +90,7 @@ namespace TrueCraft.Core.Test.World return decorator; } - static int CountBlockInColumn(ApplesauceChunk aChunk, int x, int z, byte blockId) + static int CountBlockInColumn(ISpatialBlockInformationProvider aChunk, int x, int z, byte blockId) { int counter = 0; @@ -113,7 +113,7 @@ namespace TrueCraft.Core.Test.World var ourDictionary = PrimeSugarCaneGrowingSeasonChunk.createStartingBlockDictionary(); - Mock aChunk = new Mock(); + Mock aChunk = new Mock(); aChunk.Setup(foo => foo.GetBlockID(It.IsAny())).Returns((Coordinates3D coordinates) => { diff --git a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs index 31c2d80..b64fa5d 100644 --- a/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs +++ b/TrueCraft.Core.Test/World/TestFakes/PrimeSugarCaneGrowingSeasonChunk.cs @@ -8,7 +8,7 @@ using TrueCraft.Core.Logic.Blocks; using TrueCraft.Core.TerrainGen.Biomes; using TrueCraft.Core.World; -public class PrimeSugarCaneGrowingSeasonChunk : ApplesauceChunk +public class PrimeSugarCaneGrowingSeasonChunk : ISpatialBlockInformationProvider { public int X => 6; public int Z => 6; @@ -172,7 +172,7 @@ public class PrimeSugarCaneGrowingSeasonChunk : ApplesauceChunk return result; } - byte ApplesauceChunk.GetMetadata(Coordinates3D locationToCheck) + byte ISpatialBlockInformationProvider.GetMetadata(Coordinates3D locationToCheck) { throw new NotImplementedException(); } diff --git a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs index e3bcc20..7a226c0 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BalloonOakTree.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs index 6fd63de..5cdc342 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/BirchTree.cs @@ -25,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs index e26cbab..3b7b7c5 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/ConiferTree.cs @@ -13,7 +13,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { const int LeafRadius = 2; - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs index cac6d5f..625b79f 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Decoration.cs @@ -12,7 +12,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations { public virtual bool ValidLocation(Coordinates3D location) { return true; } - public abstract bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location); + public abstract bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location); public static bool IsCuboidWall(Coordinates2D location, Coordinates3D start, Vector3 size) { @@ -30,7 +30,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations || location.X.Equals(start.X + (int)size.X - 1) && location.Z.Equals(start.Z + (int)size.Z - 1); } - public static bool NeighboursBlock(ApplesauceChunk chunk, Coordinates3D location, byte block, byte meta = 0x0) + public static bool NeighboursBlock(ISpatialBlockInformationProvider chunk, Coordinates3D location, byte block, byte meta = 0x0) { var surrounding = new[] { location + Coordinates3D.Left, @@ -53,7 +53,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return false; } - public static void GenerateColumn(ApplesauceChunk chunk, Coordinates3D location, int height, byte block, byte meta = 0x0) + public static void GenerateColumn(ISpatialBlockInformationProvider chunk, Coordinates3D location, int height, byte block, byte meta = 0x0) { for (int offset = 0; offset < height; offset++) { @@ -71,7 +71,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations * 0x1 - Hollow cuboid of the specified block * 0x2 - Outlines the area of the cuboid using the specified block */ - public static void GenerateCuboid(ApplesauceChunk chunk, Coordinates3D location, Vector3 size, byte block, byte meta = 0x0, byte mode = 0x0) + public static void GenerateCuboid(ISpatialBlockInformationProvider chunk, Coordinates3D location, Vector3 size, byte block, byte meta = 0x0, byte mode = 0x0) { //If mode is 0x2 offset the size by 2 and change mode to 0x1 if (mode.Equals(0x2)) @@ -102,7 +102,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateVanillaLeaves(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected void GenerateVanillaLeaves(ISpatialBlockInformationProvider chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { int radiusOffset = radius; for (int yOffset = -radius; yOffset <= radius; yOffset = (yOffset + 1)) @@ -116,7 +116,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateVanillaCircle(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0) + protected void GenerateVanillaCircle(ISpatialBlockInformationProvider chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0, double corner = 0) { for (int i = -radius; i <= radius; i = (i + 1)) { @@ -146,7 +146,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected void GenerateCircle(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected void GenerateCircle(ISpatialBlockInformationProvider chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { for (int i = -radius; i <= radius; i = (i + 1)) { @@ -172,7 +172,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - protected static void GenerateSphere(ApplesauceChunk chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) + protected static void GenerateSphere(ISpatialBlockInformationProvider chunk, Coordinates3D location, int radius, byte block, byte meta = 0x0) { for (int i = -radius; i <= radius; i = (i + 1)) { diff --git a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs index d1445ff..6580d5b 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/Dungeon.cs @@ -26,7 +26,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { Console.WriteLine("Dungeon in chunk {0}", chunk.Coordinates); if (!ValidLocation(location)) @@ -52,7 +52,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - private void CreateEntraces(ApplesauceChunk chunk, Coordinates3D location, Random random) + private void CreateEntraces(ISpatialBlockInformationProvider chunk, Coordinates3D location, Random random) { int entrances = 0; var above = location + Coordinates3D.Up; @@ -80,7 +80,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - private void MossFloor(ApplesauceChunk chunk, Coordinates3D location, Random random) + private void MossFloor(ISpatialBlockInformationProvider chunk, Coordinates3D location, Random random) { for (int x = location.X; x < location.X + Size.X; x++) { @@ -96,7 +96,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations } } - private void PlaceChests(ApplesauceChunk chunk, Coordinates3D location, Random random) + private void PlaceChests(ISpatialBlockInformationProvider chunk, Coordinates3D location, Random random) { var above = location + Coordinates3D.Up; var chests = random.Next(0, 2); diff --git a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs index 6d74635..6d6fd1f 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/OakTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; diff --git a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs index 7d21b94..3a3f6b6 100644 --- a/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs +++ b/TrueCraft.Core/TerrainGen/Decorations/PineTree.cs @@ -23,7 +23,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations return true; } - public override bool GenerateAt(IWorldSeed world, ApplesauceChunk chunk, Coordinates3D location) + public override bool GenerateAt(IWorldSeed world, ISpatialBlockInformationProvider chunk, Coordinates3D location) { if (!ValidLocation(location)) return false; @@ -51,7 +51,7 @@ namespace TrueCraft.Core.TerrainGen.Decorations * 0x0 - two level topper * 0x1 - three level topper */ - protected void GenerateTopper(ApplesauceChunk chunk, Coordinates3D location, byte type = 0x0) + protected void GenerateTopper(ISpatialBlockInformationProvider chunk, Coordinates3D location, byte type = 0x0) { const int sectionRadius = 1; GenerateCircle(chunk, location, sectionRadius, LeavesBlock.BlockID, 0x1); diff --git a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs index ccb37f9..a61bd54 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/CactusDecorator.cs @@ -14,7 +14,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public class CactusDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); diff --git a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs index 10c0812..62bec23 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/DungeonDecorator.cs @@ -21,7 +21,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators this.BaseLevel = groundLevel; } - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int attempts = 0; attempts < 8; attempts++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs index a238147..4e34f92 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/FreezeDecorator.cs @@ -12,7 +12,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { class FreezeDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < 16; x++) { @@ -51,7 +51,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators } } - bool CoverIce(ApplesauceChunk chunk, IBiomeRepository biomes, Coordinates3D location) + bool CoverIce(ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, Coordinates3D location) { const int maxDistance = 4; var adjacent = new[] { diff --git a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs index e85e75e..3fa02a6 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/LiquidDecorator.cs @@ -15,7 +15,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public static readonly int WaterLevel = 40; - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { for (int x = 0; x < Chunk.Width; x++) { diff --git a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs index ebaf35a..394cc3f 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/OreDecorator.cs @@ -54,7 +54,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators Ores.Add(redstone); } - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var perlin = new Perlin(world.Seed); perlin.Lacunarity = 1; diff --git a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs index 1f9d984..2c3ec8f 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/PlantDecorator.cs @@ -13,7 +13,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { public class PlantDecorator : IChunkDecorator { - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { var noise = new Perlin(world.Seed); var chanceNoise = new ClampNoise(noise); @@ -68,23 +68,23 @@ namespace TrueCraft.Core.TerrainGen.Decorators } } - void GenerateRose(ApplesauceChunk chunk, Coordinates3D location) + void GenerateRose(ISpatialBlockInformationProvider chunk, Coordinates3D location) { chunk.SetBlockID(location, RoseBlock.BlockID); } - void GenerateDandelion(ApplesauceChunk chunk, Coordinates3D location) + void GenerateDandelion(ISpatialBlockInformationProvider chunk, Coordinates3D location) { chunk.SetBlockID(location, DandelionBlock.BlockID); } - void GenerateTallGrass(ApplesauceChunk chunk, Coordinates3D location, byte meta) + void GenerateTallGrass(ISpatialBlockInformationProvider chunk, Coordinates3D location, byte meta) { chunk.SetBlockID(location, TallGrassBlock.BlockID); chunk.SetMetadata(location, meta); } - void GenerateDeadBush(ApplesauceChunk chunk, Coordinates3D location) + void GenerateDeadBush(ISpatialBlockInformationProvider chunk, Coordinates3D location) { chunk.SetBlockID(location, DeadBushBlock.BlockID); } diff --git a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs index 96dc551..25b97eb 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/SugarCaneDecorator.cs @@ -25,7 +25,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators { suppliedNoise = suppliedNoiseSource; } - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { NoiseGen noise; if (suppliedNoise == null) diff --git a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs index d7f8067..9dfff15 100644 --- a/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs +++ b/TrueCraft.Core/TerrainGen/Decorators/TreeDecorator.cs @@ -17,7 +17,7 @@ namespace TrueCraft.Core.TerrainGen.Decorators public Perlin Noise { get; set; } public ClampNoise ChanceNoise { get; set; } - public void Decorate(IWorldSeed world, ApplesauceChunk chunk, IBiomeRepository biomes, IBlockRepository blockRepository) + public void Decorate(IWorldSeed world, ISpatialBlockInformationProvider chunk, IBiomeRepository biomes, IBlockRepository blockRepository) { Noise = new Perlin(world.Seed); ChanceNoise = new ClampNoise(Noise);