Simulate player dig/place

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

Simulate player dig/place

by Temperest » Tue Jun 05, 2012 02:47

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.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

User avatar
SegFault22
Member
 
Posts: 870
Joined: Mon May 21, 2012 03:17

by SegFault22 » Tue Jun 05, 2012 04:43

+1
Great idea! This might turn out to be something useful!
Resources are abundant; only money is scarce. People should not have to work hard and remain poor just to pay for the needs of survival.
Society can thrive without money - but only if productive members of society are rewarded for being productive.
 

User avatar
Stef
Member
 
Posts: 394
Joined: Wed Apr 04, 2012 10:46

by Stef » Tue Jun 05, 2012 05:23

why not building some gravity pistons and other ones
Sorry for my crappy english, im dutch :D
 

User avatar
darkrose
Member
 
Posts: 91
Joined: Mon Jun 04, 2012 04:25

by darkrose » Tue Jun 05, 2012 06:40

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 Minetest Classic, and it's updated Development Tree, also check out my server.
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Tue Jun 05, 2012 06:52

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.
 

Temperest As Guest
 

by Temperest As Guest » Tue Jun 05, 2012 14:47

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.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Tue Jun 05, 2012 15:14

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
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Tue Jun 05, 2012 20:16

place_node, dig_node and punch_node:

https://github.com/celeron55/minetest/commit/c3658e7c797cbf5b9d04a6d950505d37dcdd422b

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

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Tue Jun 05, 2012 20:24

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?
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Tue Jun 05, 2012 20:40

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.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Tue Jun 05, 2012 20:41

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.
Last edited by Temperest on Tue Jun 05, 2012 20:41, edited 1 time in total.
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

celeron55
Member
 
Posts: 430
Joined: Tue Apr 19, 2011 10:10

by celeron55 » Tue Jun 05, 2012 20:53

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/commit/3a0562bebcb91d05fceb5a1f9ded539f77a625e4
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 12 guests

cron