public DigData Dig(Vector3i worldPosition, int damage) { DigData result = new DigData(); Vector3i localPosition = GetLocalPosition(worldPosition); Block diggedBlock = this.blocks [localPosition.x, localPosition.y, localPosition.z]; diggedBlock.health -= damage; if (diggedBlock.health <= 0) { result = Place(worldPosition, 0); } return(result); }
public DigData Place(Vector3i worldPosition, byte placedBlockType) { DigData result = new DigData(); Vector3i localPosition = GetLocalPosition(worldPosition); byte diggedBlockType = this.blocks[localPosition.x, localPosition.y, localPosition.z].type; this.blocks [localPosition.x, localPosition.y, localPosition.z].type = placedBlockType; this.blocks [localPosition.x, localPosition.y, localPosition.z].health = this.blockDatabase.blockMaterials[placedBlockType].hardness; MeshArchitect meshArchitect = new MeshArchitect(this.size, this.blocks, this.blockDatabase); UpdateMesh(meshArchitect); result.success = true; result.diggedBlockType = diggedBlockType; result.localPosition = localPosition; return(result); }
//places a new block public void Place(Vector3i position, byte blockType) { for (int x = 0; x < this.chunks.GetLength(0); x++) { for (int z = 0; z < this.chunks.GetLength(1); z++) { Chunk chunk = this.chunks[x, z].GetComponent <Chunk>(); bool isInside = chunk.IsInside(position); if (isInside) { DigData result = chunk.Place(position, blockType); Vector3i chunkPosition = this.chunks [x, z].GetComponent <Chunk> ().position; AddChangedBlock(chunkPosition, result.localPosition, blockType); } } } }
//digs a block public byte Dig(Vector3i position, int damage) { byte diggedBlock = 0; for (int x = 0; x < this.chunks.GetLength(0); x++) { for (int z = 0; z < this.chunks.GetLength(1); z++) { Chunk chunk = this.chunks[x, z].GetComponent <Chunk>(); bool isInside = chunk.IsInside(position); if (isInside) { DigData result = chunk.Dig(position, damage); if (result.success) { Vector3i chunkPosition = this.chunks [x, z].GetComponent <Chunk> ().position; AddChangedBlock(chunkPosition, result.localPosition, 0); } return(result.diggedBlockType); } } } return(diggedBlock); }
void AddNewDigData(GameObject digO) { DigInfo di = digO.GetComponent<DigInfo> (); DigData dd = new DigData (digO.transform.position, digO.name, digO.transform.eulerAngles, digO.GetComponent<SpriteRenderer> ().sortingOrder, di.deep, di.currentDeep, di.texType); digData.Add (dd); }