Fix two kelp-related crashes, add kelp detach logging

This commit is contained in:
teknomunk 2024-04-29 07:19:10 +00:00
parent 5f70189e08
commit d34f607f23
1 changed files with 18 additions and 6 deletions

View File

@ -185,6 +185,7 @@ end
-- Obtain position of the first kelp unsubmerged.
-- Returns: pos, node, height, break_height
function kelp.find_unsubmerged(pos, node, height)
-- Optional params: node, height
local node = node or mt_get_node(pos)
@ -332,10 +333,15 @@ function kelp.detach_dig(dig_pos, pos, drop, node, height)
if drop then
kelp.detach_drop(dig_pos, height)
end
mt_set_node(pos, {
name=mt_registered_nodes[node.name].node_dig_prediction,
param=node.param,
param2=0 })
-- Only set the node if the node would be changed
local dig_prediction = mt_registered_nodes[node.name].node_dig_prediction
if dig_prediction and dig_prediction ~= node.name then
mt_set_node(pos, {
name=dig_prediction,
param=node.param,
param2=0 })
end
-- Digs the kelp beginning at a height.
else
@ -363,9 +369,15 @@ end
local function detach_unsubmerged(pos)
local node = mt_get_node(pos)
local dig_pos,_, height = kelp.find_unsubmerged(pos, node)
local dig_pos,node, height, break_height = kelp.find_unsubmerged(pos, node)
if dig_pos then
mt_sound_play(mt_registered_nodes[node.name].sounds.dug, { gain = 0.5, pos = dig_pos }, true)
if node then
minetest.log("info","Detaching kelp because of "..node.name.." at "..vector.to_string(vector.offset(dig_pos,0,break_height,0)))
end
local node_def = mt_registered_nodes[node.name]
if node_def and node_def.sounds then
mt_sound_play(node_def.sounds.dug, { gain = 0.5, pos = dig_pos }, true)
end
kelp.detach_dig(dig_pos, pos, true, node, height)
local new_age = kelp.roll_init_age()
store_age(pos, new_age)