Exemple #1
0
		//public static bool SetBlock(RaycastHit hit, Block block, bool adjacent = false)
		//{
		//	var chunk = hit.collider.GetComponent<Chunk>();
		//	if (chunk == null)
		//		return false;

		//	var pos = GetBlockPos(hit, adjacent);

		//	chunk.World.SetBlock(pos, block, true);

		//	return true;
		//}

		//public static bool SetBlock(RaycastHit hit, WorldPos pos, Block block)
		//{
		//	var chunk = hit.collider.GetComponent<Chunk>();
		//	if (chunk == null)
		//		return false;

		//	chunk.World.SetBlock(pos, block, true);

		//	return true;
		//}


		public static bool SetBlock(RaycastHit hit, VoxBlockType block, Color blockColor, bool adjacent = false)
		{
			var chunk = hit.collider.GetComponent<Chunk>();
			if (chunk == null)
				return false;

			var pos = GetBlockPos(hit, adjacent);

			chunk.World.SetBlock(pos, block, blockColor, true);

			return true;
		}
Exemple #2
0
		public void SetBlock(int x, int y, int z, VoxBlockType blockType, Color blockColor, bool createChunkIfNull = false)
		{
			var chunk = GetChunk(x, y, z, createChunkIfNull);

			if (chunk != null)
			{
				chunk.SetBlock(x - chunk.Pos.x, y - chunk.Pos.y, z - chunk.Pos.z, blockType, blockColor);
				chunk.RebuildNeeded = true;

				UpdateIfEqual(x - chunk.Pos.x, 0, new WorldPos(x - 1, y, z));
				UpdateIfEqual(x - chunk.Pos.x, ChunkSize - 1, new WorldPos(x + 1, y, z));
				UpdateIfEqual(y - chunk.Pos.y, 0, new WorldPos(x, y - 1, z));
				UpdateIfEqual(y - chunk.Pos.y, ChunkSize - 1, new WorldPos(x, y + 1, z));
				UpdateIfEqual(z - chunk.Pos.z, 0, new WorldPos(x, y, z - 1));
				UpdateIfEqual(z - chunk.Pos.z, ChunkSize - 1, new WorldPos(x, y, z + 1));
			}
		}
Exemple #3
0
		public void SetBlock(WorldPos pos, VoxBlockType blockType, Color blockColor, bool createChunkIfNull = false)
		{
			SetBlock(pos.x, pos.y, pos.z, blockType, blockColor, createChunkIfNull);
		}
Exemple #4
0
		//public void SetBlock(int x, int y, int z, VoxBlockType blockType)
		//{
		//	SetBlock(x,y,z,blockType,Color.white);
		//}

		public void SetBlock(int x, int y, int z, VoxBlockType blockType, Color blockColor)
		{
			if (InRange(x) && InRange(y) && InRange(z))
			{
				if (Blocks[x, y, z] != null)
				{
					Blocks[x, y, z].JustCreated = Blocks[x, y, z].IsEmpty();

					Blocks[x, y, z].BlockType = blockType;
					Blocks[x, y, z].BlockColor = blockColor;
					Blocks[x, y, z].Modified = true;
				}
				else
				{
					//Blocks[x, y, z] = new Block(blockColor) {BlockType = blockType};
					Debug.LogError("You're doing it wrong, block in range should not be null");
				}
				//Blocks[x, y, z] = block;
			}
			else
			{
				World.SetBlock(Pos.x + x, Pos.y + y, Pos.z + z, blockType, blockColor);
			}

		}
Exemple #5
0
		public static bool SetBlock(RaycastHit hit, WorldPos pos, VoxBlockType block, Color blockColor)
		{
			var chunk = hit.collider.GetComponent<Chunk>();
			if (chunk == null)
				return false;

			chunk.World.SetBlock(pos, block, blockColor, true);

			return true;
		}