Skip to content

Commit 3c5da70

Browse files
committedNov 7, 2016
Builtin/../falling: Fix bugs caused by 'ignore' nodes
Original commit by t4im, rebased and developed by paramat. Fix CONTENT_IGNORE being replaced by falling nodes or causing large areas of sand to collapse into itself. Format some conditional code for clarity. Add and clarify some comments.
1 parent e82bd3f commit 3c5da70

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed
 

Diff for: ‎builtin/game/falling.lua

+19-14
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ core.register_entity(":__builtin:falling_node", {
4646
if not vector.equals(acceleration, {x = 0, y = -10, z = 0}) then
4747
self.object:setacceleration({x = 0, y = -10, z = 0})
4848
end
49-
-- Turn to actual sand when collides to ground or just move
49+
-- Turn to actual node when colliding with ground, or continue to move
5050
local pos = self.object:getpos()
51-
local bcp = {x = pos.x, y = pos.y - 0.7, z = pos.z} -- Position of bottom center point
52-
local bcn = core.get_node(bcp)
53-
local bcd = core.registered_nodes[bcn.name]
54-
-- Note: walkable is in the node definition, not in item groups
55-
if not bcd or bcd.walkable or
51+
-- Position of bottom center point
52+
local bcp = {x = pos.x, y = pos.y - 0.7, z = pos.z}
53+
-- Avoid bugs caused by an unloaded node below
54+
local bcn = core.get_node_or_nil(bcp)
55+
local bcd = bcn and core.registered_nodes[bcn.name]
56+
if bcn and
57+
(not bcd or bcd.walkable or
5658
(core.get_item_group(self.node.name, "float") ~= 0 and
57-
bcd.liquidtype ~= "none") then
59+
bcd.liquidtype ~= "none")) then
5860
if bcd and bcd.leveled and
5961
bcn.name == self.node.name then
6062
local addlevel = self.node.level
@@ -154,16 +156,19 @@ function nodeupdate_single(p)
154156
local n = core.get_node(p)
155157
if core.get_item_group(n.name, "falling_node") ~= 0 then
156158
local p_bottom = {x = p.x, y = p.y - 1, z = p.z}
157-
local n_bottom = core.get_node(p_bottom)
158-
local d_bottom = core.registered_nodes[n_bottom.name]
159-
-- Note: walkable is in the node definition, not in item groups
159+
-- Only spawn falling node if node below is loaded
160+
local n_bottom = core.get_node_or_nil(p_bottom)
161+
local d_bottom = n_bottom and core.registered_nodes[n_bottom.name]
160162
if d_bottom and
163+
161164
(core.get_item_group(n.name, "float") == 0 or
162-
d_bottom.liquidtype == "none") and
165+
d_bottom.liquidtype == "none") and
166+
163167
(n.name ~= n_bottom.name or (d_bottom.leveled and
164-
core.get_node_level(p_bottom) < core.get_node_max_level(p_bottom))) and
165-
(not d_bottom.walkable or
166-
d_bottom.buildable_to) then
168+
core.get_node_level(p_bottom) <
169+
core.get_node_max_level(p_bottom))) and
170+
171+
(not d_bottom.walkable or d_bottom.buildable_to) then
167172
n.level = core.get_node_level(p)
168173
core.remove_node(p)
169174
spawn_falling_node(p, n)

0 commit comments

Comments
 (0)
Please sign in to comment.