public void TestChunkWorldPos() { Assert.Equal(_cbwPos1, _cwPos1.ToBlockWorldPos()); Assert.Equal(_cbwPos2, _cwPos2.ToBlockWorldPos()); Assert.Equal(_cbwPos3, _cwPos3.ToBlockWorldPos()); Assert.Equal(_cbwPos4, _cwPos4.ToBlockWorldPos()); Assert.Equal(_cbwPos5, _cwPos5.ToBlockWorldPos()); }
public virtual async Task Generate(IWorld world, ChunkWorldPos pos, int countPerChunk) { int seed = await world.GetSeed(); BlockWorldPos curChunkCorner = pos.ToBlockWorldPos(); int chunkSeed = pos.X ^ pos.Z ^ seed ^ this.GetType().GetHashCode() ^ this.GetPrimaryKeyString().GetHashCode(); Random rand = new Random(chunkSeed); int countCurChunk = rand.Next(countPerChunk + 1); for (int count = 0; count < countCurChunk; ++count) { int x = curChunkCorner.X + rand.Next(16); int z = curChunkCorner.Z + rand.Next(16); int groundHeight = await GetGroundHeight(world, pos, x, z); await GenerateSingle(world, pos, new BlockWorldPos { X = x, Y = groundHeight, Z = z }); } }
public async Task Generate(IWorld world, ChunkWorldPos chunkWorldPos, BlockState blockState, int count, int size, int minHeight, int maxHeight) { int seed = await world.GetSeed(); BlockWorldPos curChunkCorner = chunkWorldPos.ToBlockWorldPos(); int chunkSeed = chunkWorldPos.X ^ chunkWorldPos.Z ^ seed ^ blockState.GetHashCode(); Random random = new Random(chunkSeed); if (minHeight > maxHeight) { int tmp = minHeight; minHeight = maxHeight; maxHeight = tmp; } else if (maxHeight == minHeight) { if (minHeight < 255) { ++maxHeight; } else { --minHeight; } } for (int j = 0; j < count; ++j) { BlockWorldPos blockpos = BlockWorldPos.Add( curChunkCorner, random.Next(16), random.Next(maxHeight - minHeight) + minHeight, random.Next(16)); await GenerateSingle(world, chunkWorldPos, blockpos, blockState, size); } }