What is happening in falling.lua?

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

What is happening in falling.lua?

by sorcerykid » Post

Perhaps someone could be so kind as to explain what this code snippet in builtin/game/falling.lua does?

https://github.com/minetest/minetest/bl ... ng.lua#L92

Code: Select all

			local nd = core.registered_nodes[n2.name]
			-- If it's not air or liquid, remove node and replace it with
			-- it's drops
			if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then
				core.remove_node(np)
				if nd and nd.buildable_to == false then
					-- Add dropped items
					local drops = core.get_node_drops(n2, "")
					for _, dropped_item in pairs(drops) do
						core.add_item(np, dropped_item)
					end
				end
Based upon my tests and tests of an independent volunteer on my server, it seems that a falling node can grief any node that is directly above a walkable node -- even if it is in a protected area (I can't find any checks for protection violations). The following scenarios have been tested on different public servers:
  • Falling node on rail = The rail is dropped as item even if protected.
  • Falling node on sapling = The sapling is dropped as item even if protected.
  • Falling node on flower = The flower is dropped as item even if protected.
  • Falling node on steel ladder = The ladder is dropped as item even if protected.
  • Falling node on wood sign = The sign is dropped as item even if protected.
This certainly can't be the desired behavior, otherwise it would be a serious exploit. Perhaps I am misunderstanding the fundamental mechanics for how falling nodes work in Minetest? My apologies if there is an obvious explanation. It is late, and I'm tired :-S

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: What is happening in falling.lua?

by rubenwardy » Post

I've disabled falling on my CTF server due to this functionality. It allows players to cause the flag to be dropped as an item, which they can then place again. Very annoying. It should respect item groups by only dropping things which are diggable according to the groups (they have one of the dig types). I'm not sure what to do about protected areas

Related issue: https://github.com/minetest/minetest/issues/4781
Although that's only related to protection, not the fact that it doesn't respect dig groups
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: What is happening in falling.lua?

by sorcerykid » Post

Ah okay, thanks. I'm wondering if the simplest solution would be to finally do away with the spawning of "falling nodes" altogether and simply the drop items directly? This was suggested by a player on my server, and it seems entirely sensible.

It would solve a whole variety of issues, including the one mentioned above. Add to the fact, I think that such a solution makes more sense from the perspective of a voxel-based universe (dare I say, the very notion of a falling node is almost an oxymoron). Also consider that TNT blasts only drop items. They don't cause a gigantic cave-in of falling nodes. So it is in fitting with existing game mechanics too.

On my server, I went ahead and patched falling.lua as follows:

Code: Select all

function spawn_falling_node(p, node)
--      local obj = core.add_entity(p, "__builtin:falling_node")
--      obj:get_luaentity():set_node(node)

        -- avoid the numerous exploits of falling nodes by
        -- simply dropping items instead
        local drops = core.get_node_drops(node.name, "")
        for _, item in ipairs(drops) do
                core.add_item(p, item)
        end
end
This seems to work for all use cases that I've tried thus far. Of course, I'm open to suggestions of other alternatives.

Shara
Moderator
Posts: 179
Joined: Sat Aug 20, 2016 15:18
GitHub: ezhh
IRC: Shara

Re: What is happening in falling.lua?

by Shara » Post

It seems like that would breaks some things - for example, some servers have suffocation if nodes fall on you as a feature.

I'm talking to a few people at the moment about possible solutions and might see if I can come up with something, but no promises.

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: What is happening in falling.lua?

by sorcerykid » Post

It seems to me (and this is only my opinion) that if certain subgames rely on actual falling nodes as a feature, then they should be implemented as a mod not as part of builtin. Given the fact that falling nodes are riddled with so many vulnerabilities, even to the point that a core developer has disabled them, then that's evidence that they aren't really suitable for inclusion as core functionality for Minetest.

EDIT: Come to think of it, couldn't the implementation for falling nodes be similar to that of minetest.is_protected( ), where mods can override the builtin behavior, perhaps with a new minetest.spawn_falling_node( ) function?

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: What is happening in falling.lua?

by Sokomine » Post

I have some issues with falling nodes in my moresnow and mg_villages mod as well. Throwing a snowball at a field with snow-covered wheat will cause a chain reaction. Uprooting a plant by throwing a snowball on the node next to the plant (or even the plant itself) is not exactly how things ought to work. For falling snowballs and snow covers, removing the node below should never happen. Falling sand or gravel is diffrent in that regard. It would look wrong if a cubic meter of sand could be held in the air by a fragile plant not even a meter in height. Perhaps in such a case the sand ought to turn into an inventory cube (like something the player dropped) and just fall to the ground instead of manifesting as a solid block on the map again. (Just in case someone finds the time to redo/repair the falling code.)
A list of my mods can be found here.

Astrobe
Member
Posts: 571
Joined: Sun Apr 01, 2018 10:46

Re: What is happening in falling.lua?

by Astrobe » Post

I've just discovered the issue by accident...

When considering solutions, one should keep in mind which one is worse:

1. no fix means that players can steal potentially precious nodes like powered rails despite protections.

2. stop the fall when the node below is protected: a protected flower could hold a whole column of sand in the air. This is an aesthetic problem. The even more simplistic fix that consists in reverting falling nodes to nodes in protected areas (and of course to not start any fall) could be a bit more inconvenient sometimes, but could also be viewed as a feature (prevents gardens and wheat fields from being "undermined")

3. Remove a falling node which is about to "overwrite" a protected node: it could be used as an "atom smasher" but most games have a trash can for this already; it could be used as an exploit in some cases if placing a protection is cheap (destroy easily annoying gravel blobs in mines), or it could be a minor issue in the case of an accidental node placement (loss of usually worthless material like gravel).

4. fallback to dropping the falling node when there's something protected where it lands: more or less same as above.

5. sorcerykid's solution: Fast and easy fix, same drawbacks as 4 but more acute.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: What is happening in falling.lua?

by sofar » Post

The code, which I drastically rewrote a while back, is a compromise. Although I don't think I touched the decision tree when I did.

Essentially this code shouldn't be in the `builtin` code at all, but move out to the game, or even into mods, so it could be modified better to account for things like protection in games where that matters. Sadly, I don't think the code can be ported out easily like that. Worth doing, though.

The adjacent node scanner is highly efficient, and should probably be an exported function that mods can build their own decision tree on top of.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: What is happening in falling.lua?

by texmex » Post

Isn’t there a mod out there called falling_extras?

Edit: It's called falling_item, https://notabug.org/TenPlus1/falling_item

Astrobe
Member
Posts: 571
Joined: Sun Apr 01, 2018 10:46

Re: What is happening in falling.lua?

by Astrobe » Post

Since granular materials like gravel and sand behave like liquids sometimes, a consistent treatment in the game would be to treat it like flooding is?

I don't think that there's better options for modders than either block a large stack of sand with a protected torch or detach/disintegrate unprotected torches.

Besides, the problem probably has been there forever and only have been reported recently so it's maybe not a big deal enough to trigger a large rewrite. Maybe the existing on_flood() message could apply in this case?

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: What is happening in falling.lua?

by Hybrid Dog » Post

Some time ago I played on a server where bones were walkable. I noticed that when sand falls into my bones, my items disappear because the bones node was turned into an item object although it's not buildable_to.
I then made this mod to fix the problem (at least in singleplayer): https://github.com/HybridDog/falling_ex ... t.lua#L138

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: What is happening in falling.lua?

by TenPlus1 » Post

falling nodes do have issues, especially on server and that's why I have rewritten it.. https://notabug.org/TenPlus1/falling_item

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: What is happening in falling.lua?

by texmex » Post

So we’ve two mods solving the same problem? What other features do they have, respectively?

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: What is happening in falling.lua?

by TenPlus1 » Post


User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: What is happening in falling.lua?

by sorcerykid » Post

Just to reiterate, I still think the more flexible and secure solution is to remove falling.lua from builtin and implement the desired behavior (with needed bug fixes) entirely as a mod. TenPlus1 has even shared a very elegant proof of concept above.

To me (and this is just my opinion) falling nodes are not a particularly essential or universal game mechanic for a voxel-based world which already distinguishes between nodes and entities. And personally, I can see many more benefits for game developers and server operators having a specialized hook for this purpose (similar to what is provided for protection), rather than attempting to shoehorn a highly specialized feature like this into the engine with no means of per-game customization. Hope that makes sense :)

User avatar
Piezo_
Member
Posts: 219
Joined: Fri Jul 20, 2018 21:36
GitHub: is proprietary I use NotABug
Location: (x,y,z)

Re: What is happening in falling.lua?

by Piezo_ » Post

I have a better solution: Instead of griefing the node the falling node lands in, the falling node should simply drop itself as an item if it can not be placed. (This could apply for protected areas, as well, and would still allow for suffocation, given the node's destination was unprotected and unobstructed)
while (true) { suffer(); }

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: What is happening in falling.lua?

by texmex » Post

Come to think of it, is there a way to have nodes falling _without_ entities? It would keep the mechanics of nodes dropping but not show the falling animation itself. Sound could work in its place, indicating falling.

User avatar
Piezo_
Member
Posts: 219
Joined: Fri Jul 20, 2018 21:36
GitHub: is proprietary I use NotABug
Location: (x,y,z)

Re: What is happening in falling.lua?

by Piezo_ » Post

It might also be a good idea to check for buildable_to...
while (true) { suffer(); }

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: What is happening in falling.lua?

by Hybrid Dog » Post

Piezo_, this would break mesecons constructions where falling nodes are used on purpose.
However, you can do this only in specific areas, e.g. a special protection block for the spawn where even fire is disabled.

texmex, if you do this, you'd still have the same griefing problem.
Still, you could test where the node would land before spawning the falling node entity and forbid falling if the target is in an area protected by someone else. This test would be executed often and thereby take some time if there's lots of air below.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Piezo_
Member
Posts: 219
Joined: Fri Jul 20, 2018 21:36
GitHub: is proprietary I use NotABug
Location: (x,y,z)

Re: What is happening in falling.lua?

by Piezo_ » Post

Hybrid Dog wrote:Piezo_, this would break mesecons constructions where falling nodes are used on purpose.
Then a "falling_destroys" attribute could be added to nodes, and the developer(s) of mesecons could simply set it to true.

Nothing broken, just an update needed.
while (true) { suffer(); }

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: What is happening in falling.lua?

by Hybrid Dog » Post

I was referring to nodes falling into protected areas.
If a mesecons piston powered by a blinky plant pushes sand so that it falls into somebody's area, the player who is responsible for this falling node is not known.
If the falling node turns into an item object instead of a node in protected areas, a piston which pushes sand up and then contracts so that the sand falls down can do this only once because the sand node does not appear.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Piezo_
Member
Posts: 219
Joined: Fri Jul 20, 2018 21:36
GitHub: is proprietary I use NotABug
Location: (x,y,z)

Re: What is happening in falling.lua?

by Piezo_ » Post

After some thinking, here's what I have in the code of a work-in-progress protection modpack that's running on my server (License: GNU GPLv3)

wardzones/wardzones_falling/init.lua

Code: Select all

local oacti = minetest.registered_entities["__builtin:falling_node"].on_activate
local ostep = minetest.registered_entities["__builtin:falling_node"].on_step

minetest.registered_entities["__builtin:falling_node"].initial_zones = {}

minetest.registered_entities["__builtin:falling_node"].on_activate = function(self, staticdata)
	self.initial_zones = wardzones.getAllZones(self.object:get_pos())
	return oacti(self, staticdata)
end

minetest.registered_entities["__builtin:falling_node"].on_step = function(self, dtime)
	local zone = wardzones.getZone(self.object:get_pos())
	if not zone then
		return ostep(self, dtime)
	end
	if not self.initial_zones[zone.name] then
		if not zone.data["nodes_fall_into"] then --Falling into a new protected area uninvited? That's a droppin'
			minetest.add_item(self.object:get_pos(), self.node)
			self.object:remove()
			return
		else --We're allowed to fall into here, so stop checking.
			self.initial_zones[zone.name] = zone
		end
	end
	return ostep(self, dtime)
end
In English, that's "If a node falls into a protected zone from outside of that zone, and the zone doesn't allow fall-griefing from outside, then drop as an item upon entry". Areas could also implement something like this, I suppose.

In other words, the solution to the problem, for now, is to implement smarter protection within our mods.

EDIT: Added return statement after removing entity.
Last edited by Piezo_ on Fri Dec 21, 2018 18:42, edited 2 times in total.
while (true) { suffer(); }

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: What is happening in falling.lua?

by sorcerykid » Post

Interesting solution. However, my concern like before is that the game mechanics aren't very consistent. For example, TNT mod always drops items after an explosion. When a player with a full inventory digs a node, the item always drops. And when a player digs a node with an attached node above (such as flowers), the item always drops. Dare I say, the entire "falling node" concept is just very peculiar for a voxel world. About the only situation that potentially makes sense is snow for a variety of reasons (also I like how the falling snow incorporates a unique looking entity).

Don't get me wrong, falling nodes certainly have their place. I just feel they are better suited as a mod rather than part of the engine. After all, in some games players are dealt damage by gravel and sand cave-ins. So a mod just makes more sense, from the perspective of customization and extensibility. Just some thoughts.

User avatar
Piezo_
Member
Posts: 219
Joined: Fri Jul 20, 2018 21:36
GitHub: is proprietary I use NotABug
Location: (x,y,z)

Re: What is happening in falling.lua?

by Piezo_ » Post

sorcerykid wrote:TNT mod always drops items after an explosion. When a player with a full inventory digs a node, the item always drops.
I remember seeing a "raycasted TNT" mod before that used raycasting to make the explosions, but also blew nodes out as falling nodes.

The effect was very nice-looking, but I can't find that exact mod any more.
while (true) { suffer(); }

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: What is happening in falling.lua?

by Hybrid Dog » Post

Piezo_ wrote:The effect was very nice-looking, but I can't find that exact mod any more.
viewtopic.php?f=11&t=20654

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests