From 11114c6847ed1eb90da964026395d24f559aba03 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 7 Apr 2021 23:54:36 +0200 Subject: [PATCH 1/5] fix add_bar function returning nil value --- mods/HUD/mcl_bossbars/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_bossbars/init.lua b/mods/HUD/mcl_bossbars/init.lua index 3a144aac4..5c6a883d9 100644 --- a/mods/HUD/mcl_bossbars/init.lua +++ b/mods/HUD/mcl_bossbars/init.lua @@ -60,7 +60,7 @@ function mcl_bossbars.add_bar(player, def) bar.id = last_id + 1 last_id = bar.id mcl_bossbars.static[bar.id] = bar - return id + return bar.id end end From f7ddfe289178064ba36b3f1b2e88b7c83a33c0e8 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 7 Apr 2021 23:54:40 +0200 Subject: [PATCH 2/5] Revert "fix add_bar function returning nil value" This reverts commit 11114c6847ed1eb90da964026395d24f559aba03. --- mods/HUD/mcl_bossbars/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_bossbars/init.lua b/mods/HUD/mcl_bossbars/init.lua index 5c6a883d9..3a144aac4 100644 --- a/mods/HUD/mcl_bossbars/init.lua +++ b/mods/HUD/mcl_bossbars/init.lua @@ -60,7 +60,7 @@ function mcl_bossbars.add_bar(player, def) bar.id = last_id + 1 last_id = bar.id mcl_bossbars.static[bar.id] = bar - return bar.id + return id end end From 2db0e176b315968363998f6c655920a174840a76 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 8 Apr 2021 12:04:29 +0800 Subject: [PATCH 3/5] Prevent param2 overflow when adding stems. Fix #1490 --- mods/ITEMS/mcl_ocean/kelp.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mods/ITEMS/mcl_ocean/kelp.lua b/mods/ITEMS/mcl_ocean/kelp.lua index 3aefe85f8..bbdae64ee 100644 --- a/mods/ITEMS/mcl_ocean/kelp.lua +++ b/mods/ITEMS/mcl_ocean/kelp.lua @@ -1,6 +1,9 @@ -- TODO: whenever it becomes possible to fully implement kelp without the -- plantlike_rooted limitation, please update accordingly. -- +-- TODO: whenever it becomes possible to make kelp grow infinitely without +-- resorting to making intermediate kelp stem node, please update accordingly. +-- -- TODO: In MC, you can't actually destroy kelp by bucket'ing water in the middle. -- However, because of the plantlike_rooted hack, we'll just allow it for now. @@ -191,17 +194,18 @@ end -- Converts param2 to kelp height. +-- For the special case where the max param2 is reached, interpret that as the +-- 16th kelp stem. function kelp.get_height(param2) - return math_floor(param2 / 16) + return param2 ~= 255 and math_floor(param2 / 16) or 16 -- 256/16 end -- Obtain pos and node of the tip of kelp. -function kelp.get_tip(pos, param2) - -- Optional params: param2 - local height = kelp.get_height(param2 or mt_get_node(pos).param2) - local pos_tip = {x=pos.x, y=pos.y, z=pos.z} - pos_tip.y = pos_tip.y + height + 1 +function kelp.get_tip(pos, height) + -- Optional params: height + local height = height or kelp.get_height(mt_get_node(pos).param2) + local pos_tip = {x=pos.x, y=pos.y+height+1, z=pos.z} return pos_tip, mt_get_node(pos_tip), height end @@ -227,7 +231,8 @@ end -- Obtain next param2. function kelp.next_param2(param2) - return param2+16 - param2 % 16 + -- param2 max value is 255, so adding to 256 causes overflow. + return math_min(param2+16 - param2 % 16, 255); end @@ -526,7 +531,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) -- When placed on kelp. if mt_get_item_group(nu_name, "kelp") == 1 then - pos_tip,node_tip = kelp.get_tip(pos_under, node_under.param2) + pos_tip,node_tip = kelp.get_tip(pos_under, kelp.get_height(node_under.param2)) def_tip = mt_registered_nodes[node_tip.name] -- When placed on surface. From 5ccb12586dd09405f42ca7c824a817cde8fdf435 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 8 Apr 2021 13:34:04 +0800 Subject: [PATCH 4/5] Fix bug where incorrect number of items are dropped. --- mods/ITEMS/mcl_ocean/kelp.lua | 46 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/mods/ITEMS/mcl_ocean/kelp.lua b/mods/ITEMS/mcl_ocean/kelp.lua index bbdae64ee..3d4c6b4b3 100644 --- a/mods/ITEMS/mcl_ocean/kelp.lua +++ b/mods/ITEMS/mcl_ocean/kelp.lua @@ -214,7 +214,7 @@ end function kelp.find_unsubmerged(pos, node, height) -- Optional params: node, height 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 y = pos.y @@ -316,7 +316,7 @@ function kelp.init_timer(pos, pos_hash) 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) -- Modified params: node -- Optional params: node, set_node, pos_tip, node_tip, submerged, downward_flowing @@ -372,9 +372,9 @@ end -- Drops the items for detached kelps. -function kelp.detach_drop(pos, param2) - -- Optional params: param2 - local height = kelp.get_height(param2 or mt_get_node(pos).param2) +function kelp.detach_drop(pos, height) + -- Optional params: height + local height = height or kelp.get_height(mt_get_node(pos).param2) local y = pos.y local walk_pos = {x=pos.x, z=pos.z} for i=1,height do @@ -389,17 +389,18 @@ end -- Synonymous to digging the kelp. -- NOTE: this is intended for whenever kelp truly becomes segmented plants -- instead of rooted to the floor. Don't try to remove dig_pos. -function kelp.detach_dig(dig_pos, pos, node, drop) - -- Optional params: drop +function kelp.detach_dig(dig_pos, pos, drop, node, height) + -- 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. local new_height = dig_pos.y - (pos.y+1) -- Digs the entire kelp. if new_height <= 0 then if drop then - kelp.detach_drop(dig_pos, param2) + kelp.detach_drop(dig_pos, height) end mt_set_node(pos, { 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. else 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 mt_swap_node(pos, {name=node.name, param=node.param, param2=16*new_height}) end @@ -421,7 +423,7 @@ end -------------------------------------------------------------------------------- function kelp.surface_on_dig(pos, node, digger) - kelp.detach_dig(pos, pos, node, true) + kelp.detach_dig(pos, pos, true, node) end @@ -435,11 +437,11 @@ function kelp.surface_on_timer(pos) local pos_hash -- Update detahed kelps - local dig_pos = kelp.find_unsubmerged(pos, node) + local dig_pos,_, height = kelp.find_unsubmerged(pos, node) if dig_pos then pos_hash = mt_hash_node_position(pos) 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) end @@ -468,7 +470,7 @@ function kelp.surface_on_destruct(pos) -- on_falling callback. Activated by pistons for falling nodes too. if kelp.is_falling(pos, node) then - kelp.detach_drop(pos, node.param2) + kelp.detach_drop(pos, kelp.get_height(node.param2)) end -- Removes position from queue @@ -479,7 +481,7 @@ end function kelp.surface_on_mvps_move(pos, node, oldpos, nodemeta) -- 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 @@ -523,7 +525,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) 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 if pos_under.y >= pos_above.y then return itemstack @@ -536,17 +538,17 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) -- When placed on surface. else - new_kelp = false + new_surface = false for _,surface in pairs(kelp.surfaces) do if nu_name == surface.nodename then node_under.name = "mcl_ocean:kelp_" ..surface.name node_under.param2 = 0 - new_kelp = true + new_surface = true break end end -- Surface must support kelp - if not new_kelp then + if not new_surface then return itemstack end @@ -555,7 +557,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) def_tip = mt_registered_nodes[node_tip.name] 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 submerged = kelp.is_submerged(node_tip) if not submerged then @@ -572,9 +574,9 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) itemstack:take_item() 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) - if new_kelp then + if new_surface then kelp.init_age(pos_under, nil, pos_hash) kelp.init_timer(pos_under, pos_hash) else From d50665d2d5e49d58317cffdaed50fd165e5d2315 Mon Sep 17 00:00:00 2001 From: iliekprogrammar Date: Thu, 8 Apr 2021 19:25:19 +0800 Subject: [PATCH 5/5] Allow kelp stems at half height to be treated like full-sized ones. Remove debug information --- mods/ITEMS/mcl_ocean/kelp.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_ocean/kelp.lua b/mods/ITEMS/mcl_ocean/kelp.lua index 3d4c6b4b3..9670943da 100644 --- a/mods/ITEMS/mcl_ocean/kelp.lua +++ b/mods/ITEMS/mcl_ocean/kelp.lua @@ -197,7 +197,7 @@ end -- For the special case where the max param2 is reached, interpret that as the -- 16th kelp stem. function kelp.get_height(param2) - return param2 ~= 255 and math_floor(param2 / 16) or 16 -- 256/16 + return math_floor(param2 / 16) + math_floor(param2 % 16 / 8) end @@ -411,7 +411,6 @@ function kelp.detach_dig(dig_pos, pos, drop, node, height) else if drop then kelp.detach_drop(dig_pos, height - new_height) - minetest.chat_send_all(node.param2 - new_height) end mt_swap_node(pos, {name=node.name, param=node.param, param2=16*new_height}) end @@ -525,7 +524,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) end - local pos_tip, node_tip, def_tip, new_surface + local pos_tip, node_tip, def_tip, new_surface, height -- Kelp must also be placed on the top/tip side of the surface/kelp if pos_under.y >= pos_above.y then return itemstack @@ -533,7 +532,8 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) -- When placed on kelp. if mt_get_item_group(nu_name, "kelp") == 1 then - pos_tip,node_tip = kelp.get_tip(pos_under, kelp.get_height(node_under.param2)) + height = kelp.get_height(node_under.param2) + pos_tip,node_tip = kelp.get_tip(pos_under, height) def_tip = mt_registered_nodes[node_tip.name] -- When placed on surface. @@ -555,6 +555,7 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) pos_tip = pos_above node_tip = mt_get_node(pos_above) def_tip = mt_registered_nodes[node_tip.name] + height = 0 end -- Next kelp must also be submerged in water. @@ -569,7 +570,12 @@ function kelp.kelp_on_place(itemstack, placer, pointed_thing) if def_node.sounds then mt_sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true) end - kelp.next_height(pos_under, node_under, pos_tip, node_tip, def_tip, submerged, downward_flowing) + -- TODO: get rid of rooted plantlike hack + if height < 16 then + kelp.next_height(pos_under, node_under, pos_tip, node_tip, def_tip, submerged, downward_flowing) + else + mt_add_item(pos_tip, "mcl_ocean:kelp") + end if not mt_is_creative_enabled(player_name) then itemstack:take_item() end