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:
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
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.