本文整理汇总了C#中Chunk.SetBlock方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.SetBlock方法的具体用法?C# Chunk.SetBlock怎么用?C# Chunk.SetBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk.SetBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChunkColumnGen
public Chunk ChunkColumnGen(Chunk chunk, int x, int z)
{
int stoneHeight = Mathf.FloorToInt (stoneBaseHeight);
stoneHeight += GetNoise (x, 0, z, stoneMountainFrequency, Mathf.FloorToInt(stoneMountainHeight));
if(stoneHeight < stoneMinHeight)
stoneHeight = Mathf.FloorToInt(stoneMinHeight);
stoneHeight += GetNoise(x, 0, z, stoneBaseNoise, Mathf.FloorToInt(stoneBaseNoise));
int dirtHeight = stoneHeight + Mathf.FloorToInt(dirtBaseHeight);
dirtHeight += GetNoise(x,100,z, dirtNoise, Mathf.FloorToInt(dirtNoiseHeight));
for (int y = chunk.pos.y; y < chunk.pos.y + Chunk.chunkSize; y++)
{
if (y <= stoneHeight)
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block());
}
else if (y <= dirtHeight)
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockGrass());
}
else
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir());
}
}
return chunk;
}
示例2: ChunkColumnGen
public Chunk ChunkColumnGen(Chunk chunk, int x, int z)
{
int stoneHeight = Mathf.FloorToInt(stoneBaseHeight);
stoneHeight += GetNoise(x, 0, z, stoneMountainFrequency, Mathf.FloorToInt(stoneMountainHeight));
if (stoneHeight < stoneMinHeight)
stoneHeight = Mathf.FloorToInt(stoneMinHeight);
stoneHeight += GetNoise(x, 0, z, stoneBaseNoise, Mathf.FloorToInt(stoneBaseNoiseHeight));
int dirtHeight = stoneHeight + Mathf.FloorToInt(dirtBaseHeight);
dirtHeight += GetNoise(x, 100, z, dirtNoise, Mathf.FloorToInt(dirtNoiseHeight));
for (int y = chunk.pos.y; y < chunk.pos.y + Chunk.chunkSize; y++)
{
//Get a value to base cave generation on
int caveChance = GetNoise(x, y, z, caveFrequency, 100); //Add this line
if (y <= stoneHeight && caveSize < caveChance) //Add caveSize < caveChance
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block());
}
else if (y <= dirtHeight && caveSize < caveChance) //Add caveSize < caveChance
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockGrass());
}
else
{
chunk.SetBlock(x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir());
}
}
return chunk;
}
示例3: ChunkColumnGen
public Chunk ChunkColumnGen(Chunk chunk, int x, int z)
{
/*int stoneHeight = Mathf.FloorToInt (stoneBaseHeight);
stoneHeight += GetNoise (x, 0, z, stoneMountainFrequency, Mathf.FloorToInt (stoneMountainHeight));
if (stoneHeight < stoneMinHeight)
stoneHeight = Mathf.FloorToInt (stoneMinHeight);
stoneHeight += GetNoise (x, 0, z, stoneBaseNoise, Mathf.FloorToInt (stoneBaseNoiseHeight));
int dirtHeight = stoneHeight + Mathf.FloorToInt (dirtBaseHeight);
dirtHeight += GetNoise (x, 100, z, dirtNoise, Mathf.FloorToInt (dirtNoiseHeight));
for (int y = 0; y < Chunk.chunkHeight; y++)
{
if (y <= stoneHeight)
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new Block ());
} else if (y <= dirtHeight)
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockGrass ());
} else
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockAir ());
}
}*/
//*********************
Random.seed = chunk.world.seed;
Vector3 offSet0 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);
Vector3 offSet1 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);
Vector3 offSet2 = new Vector3 (Random.value * 10000, Random.value * 10000, Random.value * 10000);
for (int y = 0; y < Chunk.chunkHeight; y++)
{
WorldPos pos = new WorldPos (x, y, z);
float noiseValue = CalculateNoiseValue (pos, offSet0, 0.03f);
noiseValue += CalculateNoiseValue (pos, offSet1, 0.02f);
noiseValue += CalculateNoiseValue (pos, offSet2, 0.005f);
noiseValue += (20 - y) / 10f;
if (noiseValue < 0.08f)
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockAir ());
} else if (noiseValue < 0.3f)
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockGrass ());
} else
{
chunk.SetBlock (x - chunk.pos.x, y, z - chunk.pos.z, new BlockStone ());
}
}
return chunk;
}
示例4: GenerateChunk
public Chunk GenerateChunk(Vector3 Position)
{
Chunk chunk = new Chunk(Position);
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
for (int y = 1; y < 3; y++)
chunk.SetBlock(new Vector3(x, y, z), new DirtBlock());
chunk.SetBlock(new Vector3(x, 0, z), new BedrockBlock());
chunk.SetBlock(new Vector3(x, 3, z), new GrassBlock());
}
}
return chunk;
}
示例5: GenerateChunk
public Chunk GenerateChunk(Vector3 position)
{
var chunk = new Chunk(position);
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
for (int y = 1; y < 3; y++)
chunk.SetBlock(new Vector3(x, y, z), new DirtBlock());
chunk.SetBlock(new Vector3(x, 0, z), new BedrockBlock());
chunk.SetBlock(new Vector3(x, 3, z), new GrassBlock());
chunk.SetBiome((byte)x, (byte)z, Biome.Plains);
}
}
return chunk;
}
示例6: Load
public static bool Load(Chunk chunk)
{
string saveFile = SaveLocation(chunk.world.worldName);
saveFile += FileName(chunk.pos);
if (!File.Exists(saveFile))
return false;
try
{
IFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(saveFile, FileMode.Open);
Save save = (Save)formatter.Deserialize(stream);
//Once the blocks in the save are added they're marked as unmodified so
//as not to trigger a new save on unload unless new blocks are added.
for (int i =0; i< save.blocks.Length; i++)
{
Block placeBlock = save.blocks[i];
placeBlock.modified = false;
chunk.SetBlock(save.positions[i], placeBlock, false);
}
stream.Close();
}
catch (Exception ex)
{
Debug.LogError(ex);
}
return true;
}
示例7: GenerateChunk
/// <summary>
/// Generates a chunk with red wool across the X axis, blue
/// wool across the Z axis, and yellow wool across the Y axis,
/// divided into sections by glass.
/// </summary>
public Chunk GenerateChunk(Vector3 position)
{
var chunk = new Chunk(position);
for (int x = 0; x < Chunk.Width; x++)
for (int z = 0; z < Chunk.Width; z++)
{
chunk.SetBlock(new Vector3(x, 0, z), new GoldBlock());
}
return chunk;
}
示例8: SetBlock
public static void SetBlock(Chunk chunk, Block block, BlockPos pos, bool replaceBlocks = false)
{
if (Chunk.InRange(pos))
{
if (replaceBlocks || chunk.GetBlock(pos).type == Block.Air.type)
{
block.modified = false;
chunk.SetBlock(pos, block, false);
}
}
}
示例9: SetBlock
public static void SetBlock(int x, int y, int z, Block block, Chunk chunk, bool replaceBlocks = false)
{
x -= chunk.pos.x;
y -= chunk.pos.y;
z -= chunk.pos.z;
if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z))
{
if (replaceBlocks || chunk.blocks[x, y, z] == null)
chunk.SetBlock(x, y, z, block);
}
}
示例10: generate
public static void generate (World world, Chunk chunk)
{
for (int x = 0; x < world.ChunkX; x++) {
for (int z = 0; z < world.ChunkZ; z++) {
float seed = 0.035f;
float terrain = 0.01f;
//float holes = 0.05f;
float waterlevel = 42;
//int bottom = (int)(SimplexNoise.noise ((chunk.WorldX + x) * terrain, (chunk.WorldZ + z) * terrain) * world.ChunkY / 12) + (world.ChunkY / 4);
//int top = (int)(SimplexNoise.noise ((chunk.WorldX + x) * holes, (chunk.WorldZ + z) * holes) * world.ChunkY / 10) + (world.ChunkY / 2) - (world.ChunkY / 10);
int height = (int)(SimplexNoise.noise ((chunk.WorldX + x) * terrain, (chunk.WorldZ + z) * terrain) * world.ChunkY / 12) + (world.ChunkY / 3);
//int baseHeight = world.ChunkY / 4;
//Debug.Log(height);
for (int y = 0; y < height * 2; y++) {
chunk.SetBlock (new Grass (), x, y, z);
}
if (height < waterlevel) {
for (int y = height; y < waterlevel; y++) {
chunk.SetBlock (new Water (), x, y, z);
}
}
/*
for (int y = 0; y < height; y++) {
if (y < bottom) {
chunk.SetBlock (new Element (), x, y, z);
} else if (y < top && SimplexNoise.noise ((chunk.WorldX + x) * seed, y * seed, (chunk.WorldZ + z) * seed) > 0) {
//chunk.SetBlock (new Element (), x, y, z);
} else {
chunk.SetBlock (new Element (), x, y, z);
}
}
*/
}
}
}
示例11: RandomUpdate
//On random update spread grass to any nearby dirt blocks on the surface
public override void RandomUpdate(Chunk chunk, BlockPos pos, Block block)
{
for (int x = -1; x <= 1; x++)
{
for (int y = -1; y <= 1; y++)
{
for (int z = -1; z <= 1; z++)
{
if (chunk.GetBlock(pos.Add(x, y, z) - chunk.pos) == dirt
&& chunk.GetBlock(pos.Add(x, y + 1, z) - chunk.pos) == air)
{
chunk.SetBlock(pos.Add(x, y, z) - chunk.pos, "grass", false);
chunk.SetFlag(Chunk.Flag.updateSoon, true);
}
}
}
}
}
示例12: ChunkGen
public Chunk ChunkGen(Chunk chunk)
{
for (int x = chunk.pos.x; x < chunk.pos.x + Chunk.chunkSize; x++)
{
for (int z = chunk.pos.z; z < chunk.pos.z + Chunk.chunkSize; z++)
{
if (IsGenerateTerrain) {
chunk = ChunkColumnGen(chunk, x, z);
} else {
for (int y = chunk.pos.y; y < chunk.pos.y + Chunk.chunkSize; y++) {
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir ());
}
}
}
}
if (IsTowerDefence) {
BlockStructure MyTownHall = GetManager.GetDataManager ().BlockStructuresList [0];
Vector3 TownHallSize = MyTownHall.MyBlocks.Size;
Vector3 TownHallPosition = new Vector3(0,0,0);
Vector3 Buffer = new Vector3(-TownHallSize.x/2f, 0, -TownHallSize.z/2f);
if (IsInsideBlockStructure(chunk, MyTownHall, TownHallPosition+Buffer, TownHallSize))
{ // if centre chunk
AddBlockStructureToTerrain(chunk, MyTownHall, TownHallSize, TownHallPosition, Buffer);
}
}
// if dungeon generation
if (!IsGenerateTerrain) {
if (!HasAddedDungeon) {
Maze MyDungeon = GetManager.GetDataManager ().MazeList [1];
Vector3 TownHallSize = MyDungeon.MyBlocks.Size;
Vector3 TownHallPosition = new Vector3(0,0,0);
//TownHallPosition.x -= TownHallSize.x/2f;
//TownHallPosition.z -= TownHallSize.z/2f;
if (IsInsideBlockStructure(chunk, (BlockStructure)MyDungeon, TownHallPosition, TownHallSize))
{ // if centre chunk
Debug.Log ("Adding Dungeon To Terrain");
AddBlockStructureToTerrain(chunk, (BlockStructure)MyDungeon, TownHallSize, TownHallPosition);
//HasAddedDungeon = true;
}
}
}
return chunk;
}
示例13: UpdateChunkAtPosition
public bool UpdateChunkAtPosition(Chunk chunk, Vector3 NewPosition) {
bool IsTransparent = false;
Fill (5);
Debug.LogError (" BlockSize: " + MyBlocks.Size.ToString () + " : NewPosition: " + NewPosition.ToString ());
Debug.Break ();
for (int i = Mathf.RoundToInt(NewPosition.x); i < Mathf.RoundToInt(NewPosition.x)+MyBlocks.Size.x; i++)
for (int j = Mathf.RoundToInt(NewPosition.y); j < Mathf.RoundToInt(NewPosition.y)+MyBlocks.Size.y; j++)
for (int k = Mathf.RoundToInt(NewPosition.z); k < Mathf.RoundToInt(NewPosition.z)+MyBlocks.Size.z; k++)
{
chunk.SetBlock (i,j,k,new BlockGrass());
//if (!IsTransparent)
// if (MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k)) == 0)
// Terrain.SetBlock(chunk.world, i,j,k, new BlockAir(), false); // cobble stone
if (MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k)) == 1)
chunk.SetBlock (i,j,k,new Block());
//Terrain.SetBlock(chunk.world, i,j,k, new Block(), false); // cobble stone
else if (MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k)) == 2)
chunk.SetBlock (i,j,k,new BlockGrass());
//Terrain.SetBlock(chunk.world, i,j,k, new BlockGrass(), false);
else if (MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k)) >= 3)
chunk.SetBlock (i,j,k,new Block(MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k))));
//Terrain.SetBlock(chunk.world, i,j,k, new Block(MyBlocks.GetBlockType (new UnityEngine.Vector3(i,j,k))), false);
}
return true;
}
示例14: ChunkColumnGen
// if closer to 'region points' increase the noise amplitude
public Chunk ChunkColumnGen(Chunk chunk, int x, int z) {
//float BiomeTypeFloat = GetNoiseF (NoiseBuffer.x + x, NoiseBuffer.y+0, NoiseBuffer.z+z, 0.01f, MyBiomes.Count);
//int BiomeType = Mathf.Clamp (Mathf.FloorToInt (BiomeTypeFloat), 0, MyBiomes.Count - 1);
//BiomeType = Mathf.Clamp (BiomeType, 0, MaxBiomes);
int BiomeType = 0;
Biome MyBiome = MyBiomes [BiomeType];
// first generate the height value
int LandHeight = Mathf.FloorToInt (MyBiome.BaseHeight);
if (IsTowerDefence) {
if (IsSymmetrical) {
int NewX = Mathf.Abs(x)+Mathf.Abs (z);
LandHeight += GetNoise (Mathf.RoundToInt(NoiseBuffer.x) + NewX,
Mathf.RoundToInt(NoiseBuffer.y) + 0,
Mathf.RoundToInt(NoiseBuffer.z) + NewX,
MyBiome.GroundFrequency,
Mathf.FloorToInt (MyBiome.LandAmplitude));
} else {
LandHeight += GetNoise (Mathf.RoundToInt(NoiseBuffer.x) + x,
Mathf.RoundToInt(NoiseBuffer.y) + 0,
Mathf.RoundToInt(NoiseBuffer.z) + z,
MyBiome.GroundFrequency,
Mathf.FloorToInt (MyBiome.LandAmplitude));
}
float ClosenessToCentre = Vector3.Distance (new Vector3(0,0,0), new Vector3(x,0,z));
int LandAddition = Mathf.RoundToInt(ClosenessToCentre / 8f)+1;
if (LandAddition < 1) LandAddition = 1;
LandHeight -= LandAddition;
} else {
LandHeight += GetNoise (Mathf.RoundToInt (NoiseBuffer.x) + x, Mathf.RoundToInt (NoiseBuffer.y) + 0, Mathf.RoundToInt (NoiseBuffer.z) + z, MyBiome.GroundFrequency, Mathf.FloorToInt (MyBiome.LandAmplitude));
}
if (LandHeight < MyBiome.LandHeightMinimum)
LandHeight = Mathf.FloorToInt (MyBiome.LandHeightMinimum);
int DirtHeight = 2;
//stoneHeight += GetNoise (x, 0, z, stoneBaseNoise, Mathf.FloorToInt (stoneBaseNoiseHeight));
//int dirtHeight = stoneHeight + Mathf.FloorToInt (dirtBaseHeight);
//dirtHeight += GetNoise (x, 100, z, dirtNoise, Mathf.FloorToInt (dirtNoiseHeight));
//if ()
{ // boundaries
//chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir ()); // air
for (int y = chunk.pos.y; y < chunk.pos.y + Chunk.chunkSize; y++)
{
if (y == MyBiome.LandHeightMinimum && MyBiome.BedRockType > 0) {
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.BedRockType));
} else if (y > MyBiome.LandHeightMinimum && y < LandHeight - DirtHeight) { // the stone in between
// makes adjustments for chunk position as the x and z are world positions
float ChanceBronze = GetNoiseFloat (x, y, z, MyBiome.BronzeFrequency, MyBiome.BronzeAmplitude);
if (ChanceBronze > 0.95f) {
if (MyBiome.BronzeType > 0)
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.BronzeType)); // cobble stone
} else {
if (MyBiome.StoneType > 0)
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.StoneType)); // cobble stone
}
} else if (y >= MyBiome.LandHeightMinimum - DirtHeight && y < LandHeight) {
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.DirtType)); // cobble stone
} else if (y == LandHeight) { // top blocks
if (y <= SeaLevel) {
if (MyBiome.SandType > 0)
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.SandType));
} else {
if (MyBiome.GrassType > 0)
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.GrassType));
}
} else if (y >= MyBiome.LandHeightMinimum && y <= SeaLevel && MyBiome.WaterType > 0) {
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.WaterType));
} else {
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir ());
}
// roads for the TD
if (IsTowerDefence) {
float PathSize = 4;
if (y == LandHeight && ((x >= - PathSize && x <= PathSize) || (z >= - PathSize && z <= PathSize)))
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new Block (MyBiome.RoadType)); // cobble stone
if((x > 80 || x < -80 || z > 80 || z < -80))
chunk.SetBlock (x - chunk.pos.x, y - chunk.pos.y, z - chunk.pos.z, new BlockAir ());
}
}
if (MyBiome.IsTrees) {
//if (Mathf.RoundToInt(x) % 2 == 0 && Mathf.RoundToInt(z) % 2 == 0)
if (LandHeight > SeaLevel) {
float IsTree = (Noise.Generate (x * MyBiome.TreeFrequency, 0, z * MyBiome.TreeFrequency));
if (IsTree > MyBiome.TreeSpawnThreshold) {
int y = (LandHeight + 1) - chunk.pos.y;
// height based on x,z coordinates and noise algorithm
float TreeHeight = Mathf.RoundToInt (10 * (Noise.Generate (x * MyBiome.TreeFrequency, 0, z * MyBiome.TreeFrequency)));
TreeHeight = Mathf.Clamp (TreeHeight, MyBiome.TreeHeightMinimum, MyBiome.TreeHeightMaximum);
// branch
for (int i = 0; i <= 6; i++)
chunk.SetBlock (x - chunk.pos.x, i + y, z - chunk.pos.z, new Block (MyBiome.WoodType));
// leaves
for (int i = 6; i <= 10; i++)
//.........这里部分代码省略.........
示例15: AddBlockStructureToTerrain
public void AddBlockStructureToTerrain(Chunk chunk, BlockStructure MyTownHall, Vector3 TownHallSize, Vector3 TownHallPosition, Vector3 Buffer) {
for (int i = 0; i < TownHallSize.x; i++)
for (int j = 0; j < TownHallSize.y; j++)
for (int k = 0; k < TownHallSize.z; k++) {
Vector3 MyBlockStructurePosition = new Vector3 (i, j, k);
MyBlockStructurePosition += TownHallPosition;
MyBlockStructurePosition.x -= chunk.pos.x;
MyBlockStructurePosition.y -= chunk.pos.y;
MyBlockStructurePosition.z -= chunk.pos.z;
{
int BlockType = MyTownHall.MyBlocks.GetBlockType (MyBlockStructurePosition + new Vector3(chunk.pos.x, chunk.pos.y, chunk.pos.z));
// spawn town hall here
MyBlockStructurePosition += Buffer;
int x = Mathf.FloorToInt (MyBlockStructurePosition.x);
int y = Mathf.FloorToInt (MyBlockStructurePosition.y);
int z = Mathf.FloorToInt (MyBlockStructurePosition.z);
if (Chunk.InRange(x) && Chunk.InRange(y) && Chunk.InRange(z)) {
if (BlockType != 0)
chunk.SetBlock (x,y,z,
new Block (BlockType)); // cobble stone
else
chunk.SetBlock (x,y,z,
new BlockAir ());
}
}
}
}