Topic: Simulate player dig/place

Currently, the Mesecons mod has pistons, but they don't properly update things like any other mesecon component. I'd like to see an addition to the Lua API that would allow us to simulate player digging/placing, so we can do things like improve pistons so they can properly push conductive stuff like mesecon.

Here's a possible interface:

minetest.env:place_node(pos,node)
minetest.env:dig_node(pos)

Or even better, expose all those property names in the node objects returned by get_node:

minetest.env:get_node(pos).after_place_node(pos)

Not sure how feasible the second one would be.

The Mesecons Laboratory, a site dedicated to the art of Mesecons circuitry!

Latest article: Mesecons Basics.

Re: Simulate player dig/place

+1
Great idea! This might turn out to be something useful!

Re: Simulate player dig/place

why not building some gravity pistons and other ones

Sorry for my crappy english, im dutch :D

Re: Simulate player dig/place

mesecons just needs to be changed to use the new on_construct and on_destruct callbacks, as (for instance) a piston pushing a mesecon out of a circuit will trigger on_destruct when it's taken out of the circuit and on_construct when it's placed in it's new position.

Take a look at my Candles Mod and Tricorder Mod, my Minetest Development Tree, and my server.

Re: Simulate player dig/place

Temperest wrote:

Currently, the Mesecons mod has pistons, but they don't properly update things like any other mesecon component. I'd like to see an addition to the Lua API that would allow us to simulate player digging/placing, so we can do things like improve pistons so they can properly push conductive stuff like mesecon.

The problem here is, the on_place and on_dig callbacks require having an object which is doing the placement or digging, and just defining that it *rarely* can be nil isn't wise, because nobody will remember it and everything will crash.

There are a few additions in 0.4.dev-20120603 related to this:
- There now exist the on_construct and on_destruct callbacks to nodes, which are always called. They should now be responsible of setting up the node in such a way that it will be operable.
- You can now fully copy and set the metadata of a node, allowing moving of nodes with metadata.

The new furnace code uses this hack to replace the furnace node without destroying it's metadata:

function hacky_swap_node(pos,name)
    local node = minetest.env:get_node(pos)
    local meta = minetest.env:get_meta(pos)
    local meta0 = meta:to_table()
    if node.name == name then
        return
    end
    node.name = name
    local meta0 = meta:to_table()
    minetest.env:set_node(pos,node)
    meta = minetest.env:get_meta(pos)
    meta:from_table(meta0)
end

However, the on_construct and on_destruct callbacks don't fix everything. Item drops and other environmental effects should not be done in on_construct/on_destruct, because otherwise there is *no way* to skip them. And some mesecon and other things probably want to cause them.

Maybe there could be a "nobody" object that can be set as a parameter to everything as needed - that would solve many things. I'll see what I can come up with tonight.

6

Re: Simulate player dig/place

darkrose wrote:

mesecons just needs to be changed to use the new on_construct and on_destruct callbacks, as (for instance) a piston pushing a mesecon out of a circuit will trigger on_destruct when it's taken out of the circuit and on_construct when it's placed in it's new position.

I've already updated the mesecons mod to use after_*_node functions, but the on_destruct functions will not work for this case because mesecons expects the node to have alredy been removed by the time the mesecons:receptor_off(pos) function is called. Additionally, this would create huge slowdowns when loading mesecon circuits using soemthing like WorldEdit (which I do rather frequently), and may even crash the game. Mesecons probably would need significan internal changes to support any other form.

New suggestion: something like after_destruct_node? It would alo solve a few other things I have in mind.

Re: Simulate player dig/place

Temperest As Guest wrote:
darkrose wrote:

mesecons just needs to be changed to use the new on_construct and on_destruct callbacks, as (for instance) a piston pushing a mesecon out of a circuit will trigger on_destruct when it's taken out of the circuit and on_construct when it's placed in it's new position.

I've already updated the mesecons mod to use after_*_node functions, but the on_destruct functions will not work for this case because mesecons expects the node to have alredy been removed by the time the mesecons:receptor_off(pos) function is called. Additionally, this would create huge slowdowns when loading mesecon circuits using soemthing like WorldEdit (which I do rather frequently), and may even crash the game. Mesecons probably would need significan internal changes to support any other form.

New suggestion: something like after_destruct_node? It would alo solve a few other things I have in mind.

after_destruct_node is already in

My Mods: Nuke Mod WorldEdit Particles and working on Mesecons
Subscribe me on YouTube if you like my Stuff
My Minetest Builds for Windows

Re: Simulate player dig/place

place_node, dig_node and punch_node:

https://github.com/celeron55/minetest/c … 37dcdd422b

Please check out and tell if there are problems. These will be included in a development snapshot in a day or two.

Re: Simulate player dig/place

Temperest As Guest wrote:

I've already updated the mesecons mod to use after_*_node functions, but the on_destruct functions will not work for this case because mesecons expects the node to have alredy been removed by the time the mesecons:receptor_off(pos) function is called. Additionally, this would create huge slowdowns when loading mesecon circuits using soemthing like WorldEdit (which I do rather frequently), and may even crash the game. Mesecons probably would need significan internal changes to support any other form.

New suggestion: something like after_destruct_node? It would alo solve a few other things I have in mind.

Is after_destruct really necessary? Is there any use for it other than easier support for old mesecons code?

Re: Simulate player dig/place

sfan5 wrote:

after_destruct_node is already in

I believe you meant after_dig_node, since after_destruct_node is nowhere to be found in lua_api.txt. The latter is being proposed because it triggers in more cases than after_dig_node, such as pushing by pistons, removal by mods, or et cetera.

The Mesecons Laboratory, a site dedicated to the art of Mesecons circuitry!

Latest article: Mesecons Basics.

11 (edited by Temperest 2012-06-05 20:41:59)

Re: Simulate player dig/place

In any case celeron55 has added this functionality as originally suggested. Thanks celeron55!

Edit: Mesecons will be updated to use this at the next dev build.

The Mesecons Laboratory, a site dedicated to the art of Mesecons circuitry!

Latest article: Mesecons Basics.

Re: Simulate player dig/place

I also added after_destruct, because adding it is very cheap and the point of the modding API is to not cause unnecessary burden on doing things.

https://github.com/celeron55/minetest/c … 9f77a625e4