Page 1 of 1

Simple Auto-Mining Block?

PostPosted: Wed Jul 03, 2013 14:22
by JWinch
Hi my name is JWINCH and I am a 15 year old programmer that loves my RPi, Linux and computing.

A question I have is about making a simple mod for personal development with the minetest API. I want to make a simple block that automatically mines a set area. Here is some pseudo code:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
If minetest.register_abm = true
For loop < 100:
posArray = [posY = current.y - 1, posXP = current.x + 1, posXN = current.x - 1, posZP = current.z + 1, posZN = current.z - 1]
set  node(posArray) to node(default:air)
End For
End If


Does the air interfere with the gravity function or does it allow mine block to fall into the position below replaced by air and could someone give me an example of how I can run the loop within the minetest.register_abm function.

Please realize that I am only starting with minetest and so all help would be great. I haven't really used LUA for a lot at all. I have come from learning python, java and now C++ for desktop applications.

I am only experimenting at the moment as I need a project to keep me busy and this might be it but that depends on the support.

PostPosted: Wed Jul 03, 2013 16:43
by Zeg9
JWinch wrote:could someone give me an example of how I can run the loop within the minetest.register_abm function.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_abm({
    nodenames = {"yourmod:yournode"},
    interval=1.0, -- in seconds
    chance=1,
    action = function(pos, node, ...)
        for x=-1,1 do
        for y=-1,1 do
        for z=-1,1 do
            minetest.remove_node({x=pos.x+x, y=pos.y+y, z=pos.z+z})
        done
        done
        done
    end,
})

This one will remove a 3x3 area around "yourmod:yournode", every second, with a probability of 1/1.
Of course you have to register your node first.

PostPosted: Wed Jul 03, 2013 21:16
by CODE_MACHINE
Zeg9 wrote:
JWinch wrote:could someone give me an example of how I can run the loop within the minetest.register_abm function.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_abm({
    nodenames = {"yourmod:yournode"},
    interval=1.0, -- in seconds
    chance=1,
    action = function(pos, node, ...)
        for x=-1,1 do
        for y=-1,1 do
        for z=-1,1 do
            minetest.remove_node({x=pos.x+x, y=pos.y+y, z=pos.z+z})
        done
        done
        done
    end,
})

This one will remove a 3x3 area around "yourmod:yournode", every second, with a probability of 1/1.
Of course you have to register your node first.


Thanks a bunch! I see what you mean about the 3x3 area being removed. If I had done it my way it would have removed a + shape. So by adding the interval within the minetest.register_abm function it runs the function at the set number of seconds. I have declared my node and set gravity to on.