/// <summary> /// Sets the given block at the X/Y/Z chunk coordinates for a chunk. /// </summary> /// <param name="x">Chunk X coordinate</param> /// <param name="y">Chunk Y coordinate</param> /// <param name="z">Chunk Z coordinate</param> /// <param name="block">Block to set</param> /// <param name="chunk">Chunk in which to set the block</param> /// <param name="replaceBlocks">Optional; if true, overwrite any block at the current chunk coordinate.</param> protected static void SetBlock(int x, int y, int z, Wixel block, WixelChunk chunk, bool replaceBlocks = false) { x -= chunk.WorldPosition.x; y -= chunk.WorldPosition.y; z -= chunk.WorldPosition.z; bool isInRange = WixelChunk.InRange(x) && WixelChunk.InRange(y) && WixelChunk.InRange(z); if (isInRange && (replaceBlocks || chunk.Blocks[x, y, z] == null)) { chunk.SetBlock(x, y, z, block); } }
public void SetBlock(int x, int y, int z, Wixel block) { WixelChunk chunk = GetChunk(x, y, z); if (chunk == null) { return; } chunk.SetBlock(x - chunk.WorldPosition.x, y - chunk.WorldPosition.y, z - chunk.WorldPosition.z, block); chunk.PerformUpdates = true; UpdateIfEqual(x - chunk.WorldPosition.x, WixelChunk.chunkSize - 1, new WorldPosition(x + 1, y, z)); UpdateIfEqual(y - chunk.WorldPosition.y, 0, new WorldPosition(x, y - 1, z)); UpdateIfEqual(y - chunk.WorldPosition.y, WixelChunk.chunkSize - 1, new WorldPosition(x, y + 1, z)); UpdateIfEqual(z - chunk.WorldPosition.z, 0, new WorldPosition(x, y, z - 1)); UpdateIfEqual(z - chunk.WorldPosition.z, WixelChunk.chunkSize - 1, new WorldPosition(x, y, z + 1)); }