public bool TryMine(Vector3i pos) { Block block = World.GetBlock(pos); if (block is ImpenetrableStoneBlock) { StopMining("Mining operation halted! Hit bedrock!"); return(false); } //if (pos.XZ.WrappedDistance(this.Position3i.XZ) >= 20) //{ // StopMining("Mining operation halted! Too far away"); // return false; //} if (block == null || block is EmptyBlock || block is WorldObjectBlock || block is WaterBlock) { return(true); //skip when worlobject, water or air } Item blockItem = BlockItem.CreatingItem(block.GetType()); int amount = 1; if (block is IRepresentsItem) { //ChatUtils.SendMessageToAll("RepresentsItem"); blockItem = Item.Create((block as IRepresentsItem).RepresentedItemType); if (block.Is <Minable>()) { amount = 4; // ore, coal or stone, could also limit to ore and coal by stringcomparison } } else if (block is RockySoilBlock) { blockItem = Item.Create(typeof(DirtItem)); } if ((block.Is <Diggable>() || block.Is <Minable>()) && blockItem != null) { if ((this.Parent.GetComponent <FuelSupplyComponent>().Energy + this.Parent.GetComponent <FuelSupplyComponent>().EnergyInSupply) < fuelconsumption) { // ChatUtils.SendMessageToAll("Not enough fuel"); UpdateStatus("NO FUEL! "); return(false); } if (++hitsperformed < hitsneeded) { this.Parent.GetComponent <FuelSupplyComponent>().TryConsumeFuel(fuelconsumption); UpdateStatus(); if (RandomUtil.CoinToss()) { hitsperformed++; //50% chance of a free extra hit for randomization, after Update to prevent values >100% } return(false); } Result result = LinkedStorage.TryAddItems(blockItem.Type, amount); if (result.Success) { UpdateStatus(); this.Parent.GetComponent <FuelSupplyComponent>().TryConsumeFuel(fuelconsumption); World.DeleteBlock(pos); hitsperformed = 0; Resetpos(); return(false); } else { //ChatUtils.SendMessageToAll("No Space"); hitsperformed = hitsneeded; UpdateStatus("STORAGE FULL! "); return(false); } } //else ChatUtils.SendMessageToAll("No valid Block"); return(true); }