[Core request] on_neighborchange callback

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

[Core request] on_neighborchange callback

by orwell » Tue Jan 12, 2016 14:24

I remember the times when I was modding Minecraft. There was a function that was called when a neighboring node was changing (digged, placed a.s.o.). It would be useful to have something like this in MT.

What could be done with this?
- Nodes that can only exist when other nodes are near, like doors.
- Nodes that should update something, for example liquid flow, when something in their environment changed.
- Nodes that adjust their shape according to the environment.

Advantages:
- Many ABM's would be obsolete.
-> CPU / memory / performance improvement!
- Could prevent some -b-u-g-s- features.

When mods need sort of a "temporary ABM", something behaving like an ABM but ending when certain conditions are met and activated on a changing neighbor, they can use timers (minetest.after()), this has already been implemented and works.
EDIT: Hey, there are even node timers!

My suggestion:

in node definition:
on_neighborchange=function(pos, node, neighborpos, player)

- neighborpos is the position of the node that changed.
- the given player digged/placed the node, can be nil.
- minetest.set_node() does not call this function.
- VoxelManip operations do not call this function.
- The return value is used to determine further actions:
> true: the neighbors of this node should be notified too because something changed
> other: do nothing.
- introduce another function:
minetest.notify_neighbors(pos, player)
to manually trigger neighbor updates.
(player is just passed to the on_neighborchange function)
Last edited by orwell on Thu Jan 28, 2016 16:43, edited 2 times in total.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: [Core request] on_neighborchange callback

by BrandonReese » Tue Jan 12, 2016 15:55

You could write a mod to accomplish the same thing using the on_dig and after_place callbacks in a node definition or registering a callback with minetest.register_on_dignode and minetest.register_on_placenode.
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: [Core request] on_neighborchange callback

by orwell » Tue Jan 12, 2016 21:35

Of course you can, but it wouldn't be acknowledged if for example the node is rotated using a screwdriver, or a node is self-removing because of an ABM. It would be nice to provide a way for this inside the engine.

I know pipeworks has implemented stuff like this, but it fails when rotating an airtight tube segment using a screwdriver to getting it to face up/down.

Of course, this modification would require the screwdriver to actually call the callbacks, but it's better to have one function for this than having a couple of different mods implementing their own system.

And, liquids flowing along nodes don't do anything on them. Nodes could be destroyed or trigger other actions when suddenly a liquid is flowing along them.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 4 guests

cron