Fix redstone comparator flooding crash
Redstone comparators have two modes, comparison mode & subtraction mode. Before this patch, the functions to turn comparators on or off attempted to swap nodes with comparators in the same mode, but failed to determine the correct replacement node, if the existing node was not a comparator. When a comparator in an on state (e.g. powered by a filled cauldron) was flooded, the flooding dropped the comparator and replaced the comparator node that was to be swapped out with air, which lead to a server crash. This patch changes the functions that turn comparators on or off so they only swap existing nodes with comparators in the same mode if the name of the replacement node can be determined – i.e. if it is not nil.
This commit is contained in:
parent
a4e541bcd2
commit
41550da87b
|
@ -43,14 +43,20 @@ end
|
|||
|
||||
local function comparator_activate(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
minetest.swap_node(pos, { name = def.comparator_onstate, param2 = node.param2 })
|
||||
local onstate = def.comparator_onstate
|
||||
if onstate then
|
||||
minetest.swap_node(pos, { name = onstate, param2 = node.param2 })
|
||||
end
|
||||
minetest.after(0.1, comparator_turnon , {pos = pos, node = node})
|
||||
end
|
||||
|
||||
|
||||
local function comparator_deactivate(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
minetest.swap_node(pos, { name = def.comparator_offstate, param2 = node.param2 })
|
||||
local offstate = def.comparator_offstate
|
||||
if offstate then
|
||||
minetest.swap_node(pos, { name = offstate, param2 = node.param2 })
|
||||
end
|
||||
minetest.after(0.1, comparator_turnoff, {pos = pos, node = node})
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue