1
0
Fork 0

Fix bug where incorrect number of items are dropped.

mineclone5
iliekprogrammar 2021-04-08 13:34:04 +08:00 committed by kay27
parent 70d1aba73e
commit ce66d99504
1 changed files with 24 additions and 22 deletions

View File

@ -214,7 +214,7 @@ end
function kelp.find_unsubmerged(pos, node, height) function kelp.find_unsubmerged(pos, node, height)
-- Optional params: node, height -- Optional params: node, height
local node = node or mt_get_node(pos) local node = node or mt_get_node(pos)
local height = height or kelp.get_height(node.param2) local height = height or ((node.param2 >= 0 and node.param2 < 16) and 1) or kelp.get_height(node.param2)
local walk_pos = {x=pos.x, z=pos.z} local walk_pos = {x=pos.x, z=pos.z}
local y = pos.y local y = pos.y
@ -316,7 +316,7 @@ function kelp.init_timer(pos, pos_hash)
end end
-- Apply next kelp height. -- Apply next kelp height. The surface is swapped. so on_construct is skipped.
function kelp.next_height(pos, node, pos_tip, node_tip, submerged, downward_flowing) function kelp.next_height(pos, node, pos_tip, node_tip, submerged, downward_flowing)
-- Modified params: node -- Modified params: node
-- Optional params: node, set_node, pos_tip, node_tip, submerged, downward_flowing -- Optional params: node, set_node, pos_tip, node_tip, submerged, downward_flowing
@ -372,9 +372,9 @@ end
-- Drops the items for detached kelps. -- Drops the items for detached kelps.
function kelp.detach_drop(pos, param2) function kelp.detach_drop(pos, height)
-- Optional params: param2 -- Optional params: height
local height = kelp.get_height(param2 or mt_get_node(pos).param2) local height = height or kelp.get_height(mt_get_node(pos).param2)
local y = pos.y local y = pos.y
local walk_pos = {x=pos.x, z=pos.z} local walk_pos = {x=pos.x, z=pos.z}
for i=1,height do for i=1,height do
@ -389,17 +389,18 @@ end
-- Synonymous to digging the kelp. -- Synonymous to digging the kelp.
-- NOTE: this is intended for whenever kelp truly becomes segmented plants -- NOTE: this is intended for whenever kelp truly becomes segmented plants
-- instead of rooted to the floor. Don't try to remove dig_pos. -- instead of rooted to the floor. Don't try to remove dig_pos.
function kelp.detach_dig(dig_pos, pos, node, drop) function kelp.detach_dig(dig_pos, pos, drop, node, height)
-- Optional params: drop -- Optional params: drop, node, height
local param2 = node.param2 local node = node or mt_get_node(pos)
local height = height or kelp.get_height(node.param2)
-- pos.y points to the surface, offset needed to point to the first kelp. -- pos.y points to the surface, offset needed to point to the first kelp.
local new_height = dig_pos.y - (pos.y+1) local new_height = dig_pos.y - (pos.y+1)
-- Digs the entire kelp. -- Digs the entire kelp.
if new_height <= 0 then if new_height <= 0 then
if drop then if drop then
kelp.detach_drop(dig_pos, param2) kelp.detach_drop(dig_pos, height)
end end
mt_set_node(pos, { mt_set_node(pos, {
name=mt_registered_nodes[node.name].node_dig_prediction, name=mt_registered_nodes[node.name].node_dig_prediction,
@ -409,7 +410,8 @@ function kelp.detach_dig(dig_pos, pos, node, drop)
-- Digs the kelp beginning at a height. -- Digs the kelp beginning at a height.
else else
if drop then if drop then
kelp.detach_drop(dig_pos, param2 - new_height) kelp.detach_drop(dig_pos, height - new_height)
minetest.chat_send_all(node.param2 - new_height)
end end
mt_swap_node(pos, {name=node.name, param=node.param, param2=16*new_height}) mt_swap_node(pos, {name=node.name, param=node.param, param2=16*new_height})
end end
@ -421,7 +423,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
function kelp.surface_on_dig(pos, node, digger) function kelp.surface_on_dig(pos, node, digger)
kelp.detach_dig(pos, pos, node, true) kelp.detach_dig(pos, pos, true, node)
end end
@ -435,11 +437,11 @@ function kelp.surface_on_timer(pos)
local pos_hash local pos_hash
-- Update detahed kelps -- Update detahed kelps
local dig_pos = kelp.find_unsubmerged(pos, node) local dig_pos,_, height = kelp.find_unsubmerged(pos, node)
if dig_pos then if dig_pos then
pos_hash = mt_hash_node_position(pos) pos_hash = mt_hash_node_position(pos)
mt_sound_play(mt_registered_nodes[node.name].sounds.dug, { gain = 0.5, pos = dig_pos }, true) mt_sound_play(mt_registered_nodes[node.name].sounds.dug, { gain = 0.5, pos = dig_pos }, true)
kelp.detach_dig(dig_pos, pos, node, true) kelp.detach_dig(dig_pos, pos, true, node, height)
kelp.store_age(kelp.roll_init_age(), pos, pos_hash) kelp.store_age(kelp.roll_init_age(), pos, pos_hash)
end end
@ -468,7 +470,7 @@ function kelp.surface_on_destruct(pos)
-- on_falling callback. Activated by pistons for falling nodes too. -- on_falling callback. Activated by pistons for falling nodes too.
if kelp.is_falling(pos, node) then if kelp.is_falling(pos, node) then
kelp.detach_drop(pos, node.param2) kelp.detach_drop(pos, kelp.get_height(node.param2))
end end
-- Removes position from queue -- Removes position from queue
@ -479,7 +481,7 @@ end
function kelp.surface_on_mvps_move(pos, node, oldpos, nodemeta) function kelp.surface_on_mvps_move(pos, node, oldpos, nodemeta)
-- Pistons moving falling nodes will have already activated on_falling callback. -- Pistons moving falling nodes will have already activated on_falling callback.
kelp.detach_dig(pos, pos, node, mt_get_item_group(node.name, "falling_node") ~= 1) kelp.detach_dig(pos, pos, mt_get_item_group(node.name, "falling_node") ~= 1, node)
end end
@ -523,7 +525,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing)
end end
local pos_tip, node_tip, def_tip, new_kelp local pos_tip, node_tip, def_tip, new_surface
-- Kelp must also be placed on the top/tip side of the surface/kelp -- Kelp must also be placed on the top/tip side of the surface/kelp
if pos_under.y >= pos_above.y then if pos_under.y >= pos_above.y then
return itemstack return itemstack
@ -536,17 +538,17 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing)
-- When placed on surface. -- When placed on surface.
else else
new_kelp = false new_surface = false
for _,surface in pairs(kelp.surfaces) do for _,surface in pairs(kelp.surfaces) do
if nu_name == surface.nodename then if nu_name == surface.nodename then
node_under.name = "mcl_ocean:kelp_" ..surface.name node_under.name = "mcl_ocean:kelp_" ..surface.name
node_under.param2 = 0 node_under.param2 = 0
new_kelp = true new_surface = true
break break
end end
end end
-- Surface must support kelp -- Surface must support kelp
if not new_kelp then if not new_surface then
return itemstack return itemstack
end end
@ -555,7 +557,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing)
def_tip = mt_registered_nodes[node_tip.name] def_tip = mt_registered_nodes[node_tip.name]
end end
-- New kelp must also be submerged in water. -- Next kelp must also be submerged in water.
local downward_flowing = kelp.is_downward_flowing(pos_tip, node_tip) local downward_flowing = kelp.is_downward_flowing(pos_tip, node_tip)
local submerged = kelp.is_submerged(node_tip) local submerged = kelp.is_submerged(node_tip)
if not submerged then if not submerged then
@ -572,9 +574,9 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing)
itemstack:take_item() itemstack:take_item()
end end
-- Initialize age and timer when it's a new kelp -- Initialize age and timer when it's planted on a new surface.
local pos_hash = mt_hash_node_position(pos_under) local pos_hash = mt_hash_node_position(pos_under)
if new_kelp then if new_surface then
kelp.init_age(pos_under, nil, pos_hash) kelp.init_age(pos_under, nil, pos_hash)
kelp.init_timer(pos_under, pos_hash) kelp.init_timer(pos_under, pos_hash)
else else