Azure Mines style mining

I was wondering if anybody had a method for creating a mining system similar to Azure Mines?

Heres a poorly made diagram of what i mean
If you didn’t know that’s how Azure mines mining works
its a good method! Generating blocks around where the player broke is alot more optimized than generating every block…

How would i create the blocks around the block that you break while ignoring other tunnels?


I would have a table containing what should generate every, say, 10 layers.

local layers = {
-- Each index is 10 layers; 1 is the first 10, 2 is the next 10, etc.
    {{"Dirt", 80}, {"Stone", 10}, {"Copper", 9}, {"Coal", 1}},
    {{"Dirt", 50}, {"Stone", 20}, {"Copper", 15}, {"Coal", 10}, {"Iron", 5}}
    -- And so on for every 10 layers 

Then, every time a player digs a block, it should check how deep it is. If the player is 5 blocks deep, go in layers[1] as it is within the first 10 blocks and randomly choose what will generate. If the player is say, 12 blocks deep, go to layers[2]. Note how all the numbers add up to 100, a full percentage. You would ideally do math.random(1, 100) to pick what will generate in the space made available. You can see that Dirt is the most likely to generate while other materials are less likely. Then, as the list goes on, Dirt loses its frequency and other materials get rarer. By the time you reach say, the 8th item on the list, you could have rare stuff like {"Diamonds", 5} to start generating those.

This is a basic idea of how I’d go about it. If anyone has a simpler idea feel free to chime in though as I’ve never actually made a full on mining game before, though I’ve played a whole bunch of them like Epic Mining 2.


I’ve tried this, and one solution that works well is to not remove blocks completely when they’re mined, but replace them with a special “air” block that is invisible, non-cancollide, ignored by raycasts, etc., but not ignored by the mining system when it checks to see where it should create new blocks.

1 Like

I have written some pseudo-code to share my idea. Basically, you need a class that can load and unload cells and do this safely. This means that it should only load a cell if it actually if its coordinates are not already occupied by another cell. Then you can check if the cell that you are loading is empty or transparent. In that case, you will need to load surrounding cells.

Also, this code assumes that air is a cell type and that the World table keeps track of all cells that are loaded.

-- Static class that manages the cells in your world
local World = {}

function World.LoadCell(coordinates, cellType)
	if not World.HasCell(coordinates) then
		-- Load the cell

function World.UnloadCell(coordinates)
	local cell = World.GetCell(coordinates)
	if cell then
		-- Unload the cell

function World.SetCell(coordinates, cellType, canReplace)
	if World.HasCell(coordinates) then
		if canReplace then
			if cellIsTransparentOrAir then
				-- Load surrounding cells
			World.LoadCell(coordinates, cellType)
		World.LoadCell(coordinates, cellType)

function World.HasCell(coordinates)
	-- Some implementation that returns if a cell is loaded

function World.GetCell(coordinates)
	-- Some implementation that returns a cell if it exists

So something like Mining Simulator? Follow this tutorial

I followed the same tutorial, not the best optimisation but it’s a working start. Customize it to your needs, use LootPlan to make random ore generation.

Good luck :+1:

1 Like

what you can do is use rays to do that make a ray make it spin if there isnt a block there then return but if there is the place a block there

1 Like