Skip to content

Commit a468acc

Browse files
tenplus1paramat
authored andcommittedOct 14, 2016
Builtin/../falling.lua: Code optimisation
1 parent 0ad40fd commit a468acc

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed
 

‎builtin/game/falling.lua

+15-15
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ core.register_entity(":__builtin:falling_node", {
4141
end,
4242

4343
on_step = function(self, dtime)
44-
-- Set gravity
44+
-- Set gravity
4545
local acceleration = self.object:getacceleration()
4646
if not vector.equals(acceleration, {x = 0, y = -10, z = 0}) then
4747
self.object:setacceleration({x = 0, y = -10, z = 0})
@@ -52,10 +52,9 @@ core.register_entity(":__builtin:falling_node", {
5252
local bcn = core.get_node(bcp)
5353
local bcd = core.registered_nodes[bcn.name]
5454
-- Note: walkable is in the node definition, not in item groups
55-
if not bcd or
56-
(bcd.walkable or
55+
if not bcd or bcd.walkable or
5756
(core.get_item_group(self.node.name, "float") ~= 0 and
58-
bcd.liquidtype ~= "none")) then
57+
bcd.liquidtype ~= "none") then
5958
if bcd and bcd.leveled and
6059
bcn.name == self.node.name then
6160
local addlevel = self.node.level
@@ -75,20 +74,20 @@ core.register_entity(":__builtin:falling_node", {
7574
local np = {x = bcp.x, y = bcp.y + 1, z = bcp.z}
7675
-- Check what's here
7776
local n2 = core.get_node(np)
77+
local nd = core.registered_nodes[n2.name]
7878
-- If it's not air or liquid, remove node and replace it with
7979
-- it's drops
80-
if n2.name ~= "air" and (not core.registered_nodes[n2.name] or
81-
core.registered_nodes[n2.name].liquidtype == "none") then
80+
if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then
8281
core.remove_node(np)
83-
if core.registered_nodes[n2.name].buildable_to == false then
82+
if nd.buildable_to == false then
8483
-- Add dropped items
8584
local drops = core.get_node_drops(n2.name, "")
86-
for _, dropped_item in ipairs(drops) do
85+
for _, dropped_item in pairs(drops) do
8786
core.add_item(np, dropped_item)
8887
end
8988
end
9089
-- Run script hook
91-
for _, callback in ipairs(core.registered_on_dignodes) do
90+
for _, callback in pairs(core.registered_on_dignodes) do
9291
callback(np, n2)
9392
end
9493
end
@@ -116,7 +115,7 @@ end
116115
function drop_attached_node(p)
117116
local nn = core.get_node(p).name
118117
core.remove_node(p)
119-
for _, item in ipairs(core.get_node_drops(nn, "")) do
118+
for _, item in pairs(core.get_node_drops(nn, "")) do
120119
local pos = {
121120
x = p.x + math.random()/2 - 0.25,
122121
y = p.y + math.random()/2 - 0.25,
@@ -156,14 +155,15 @@ function nodeupdate_single(p)
156155
if core.get_item_group(n.name, "falling_node") ~= 0 then
157156
local p_bottom = {x = p.x, y = p.y - 1, z = p.z}
158157
local n_bottom = core.get_node(p_bottom)
158+
local d_bottom = core.registered_nodes[n_bottom.name]
159159
-- Note: walkable is in the node definition, not in item groups
160-
if core.registered_nodes[n_bottom.name] and
160+
if d_bottom and
161161
(core.get_item_group(n.name, "float") == 0 or
162-
core.registered_nodes[n_bottom.name].liquidtype == "none") and
163-
(n.name ~= n_bottom.name or (core.registered_nodes[n_bottom.name].leveled and
162+
d_bottom.liquidtype == "none") and
163+
(n.name ~= n_bottom.name or (d_bottom.leveled and
164164
core.get_node_level(p_bottom) < core.get_node_max_level(p_bottom))) and
165-
(not core.registered_nodes[n_bottom.name].walkable or
166-
core.registered_nodes[n_bottom.name].buildable_to) then
165+
(not d_bottom.walkable or
166+
d_bottom.buildable_to) then
167167
n.level = core.get_node_level(p)
168168
core.remove_node(p)
169169
spawn_falling_node(p, n)

0 commit comments

Comments
 (0)
Please sign in to comment.