From fb51067c782fe2c42e0a873d204d41159cb706a7 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Fri, 23 Dec 2022 16:05:23 +0200 Subject: [PATCH 1/6] Created a shared function for planting a seed that can also be consumed. --- mods/ITEMS/mcl_farming/carrots.lua | 9 +-------- mods/ITEMS/mcl_farming/potatoes.lua | 9 +-------- mods/ITEMS/mcl_farming/shared_functions.lua | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index 1c3ebcdfa..b76606be2 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -89,14 +89,7 @@ minetest.register_craftitem("mcl_farming:carrot_item", { groups = {food = 2, eatable = 3, compostability = 65}, _mcl_saturation = 3.6, on_secondary_use = minetest.item_eat(3), - on_place = function(itemstack, placer, pointed_thing) - local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, "mcl_farming:carrot_1") - if new then - return new - else - return minetest.do_item_eat(3, nil, itemstack, placer, pointed_thing) - end - end, + on_place = mcl_farming:get_seed_or_eat_callback("mcl_farming:carrot_1", 3), }) minetest.register_craftitem("mcl_farming:carrot_item_gold", { diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index 78532c0c0..50bb66a3b 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -95,14 +95,7 @@ minetest.register_craftitem("mcl_farming:potato_item", { _mcl_saturation = 0.6, stack_max = 64, on_secondary_use = minetest.item_eat(1), - on_place = function(itemstack, placer, pointed_thing) - local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, "mcl_farming:potato_1") - if new then - return new - else - return minetest.do_item_eat(1, nil, itemstack, placer, pointed_thing) - end - end, + on_place = mcl_farming:get_seed_or_eat_callback("mcl_farming:potato_1", 1), }) minetest.register_craftitem("mcl_farming:potato_item_baked", { diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index e2e42dd25..989274c43 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -469,6 +469,21 @@ function mcl_farming:stem_color(startcolor, endcolor, step, step_count) return colorstring end +--[[Get a callback that either eats the item or plants it. + +Used for on_place callbacks for craft items which are seeds that can also be consumed. +--]] +function mcl_farming:get_seed_or_eat_callback(plantname, hp_change) + return function(itemstack, placer, pointed_thing) + local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname) + if new then + return new + else + return minetest.do_item_eat(hp_change, nil, itemstack, placer, pointed_thing) + end + end +end + minetest.register_lbm({ label = "Add growth for unloaded farming plants", name = "mcl_farming:growth", From 8a7fcfde82692a78e83c12f76e21518347194907 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Sat, 24 Dec 2022 19:38:55 +0200 Subject: [PATCH 2/6] Fixed sweet berries bugs. Now they can only be placed a tile's upper part. Also when destroyed bushes at stage 2 drop 1 or 2 berries, while bushes at stage 3 drop 2 or 3 (instead of fixed numbers of 1 and 3 respectively). Also harvesting sweet berries at stage 3 (final) brings them to stage 1 instead of just to stage 2. Number of dropped berries was adjusted. --- mods/ITEMS/mcl_farming/sweet_berry.lua | 34 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index aca5fadc2..4682447df 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -9,6 +9,9 @@ for i=0, 3 do if i > 0 then groups.sweet_berry_thorny = 1 end + local drop_berries = (i >= 2) + local berries_to_drop = drop_berries and {i - 1, i} or nil + minetest.register_node(node_name, { drawtype = "plantlike", tiles = {texture}, @@ -24,7 +27,14 @@ for i=0, 3 do liquid_renewable = false, liquid_range = 0, walkable = false, - drop = (i>=2) and ("mcl_farming:sweet_berry" .. (i==3 and " 3" or "")) or "", + -- Dont even create a table if no berries are dropped. + drop = not drop_berries and "" or { + max_items = 1, + items = { + { items = {"mcl_farming:sweet_berry " .. berries_to_drop[1] }, rarity = 2 }, + { items = {"mcl_farming:sweet_berry " .. berries_to_drop[2] } } + } + }, selection_box = { type = "fixed", fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, (-0.30 + (i*0.25)), 6 / 16}, @@ -46,17 +56,12 @@ for i=0, 3 do itemstack:take_item() return end - local stage - if node.name:find("_2") then - stage = 2 - elseif node.name:find("_3") then - stage = 3 - end - if stage then - for i=1,math.random(stage) do - minetest.add_item(pos,"mcl_farming:sweet_berry") + + if drop_berries then + for j=1, berries_to_drop[math.random(2)] do + minetest.add_item(pos, "mcl_farming:sweet_berry") end - minetest.swap_node(pos,{name = "mcl_farming:sweet_berry_bush_" .. stage - 1 }) + minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_" .. 1 }) end return itemstack end, @@ -76,8 +81,11 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { minetest.record_protection_violation(pointed_thing.above, pn) return itemstack end - if pointed_thing.type == "node" and table.indexof(planton,minetest.get_node(pointed_thing.under).name) ~= -1 and minetest.get_node(pointed_thing.above).name == "air" then - minetest.set_node(pointed_thing.above,{name="mcl_farming:sweet_berry_bush_0"}) + if pointed_thing.type == "node" and + table.indexof(planton, minetest.get_node(pointed_thing.under).name) ~= -1 and + pointed_thing.above.y > pointed_thing.under.y and + minetest.get_node(pointed_thing.above).name == "air" then + minetest.set_node(pointed_thing.above, {name="mcl_farming:sweet_berry_bush_0"}) if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end From 0f569fdbaad89768fec63ee506782164cf99a7ba Mon Sep 17 00:00:00 2001 From: CyberMango Date: Sat, 24 Dec 2022 20:38:32 +0200 Subject: [PATCH 3/6] Bone meal on sweet berries in creative mode is no longer wasted and minor fixes. removed an unnecessary -- in a comment. Removed a redundant concatination. --- mods/ITEMS/mcl_farming/shared_functions.lua | 2 +- mods/ITEMS/mcl_farming/sweet_berry.lua | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 989274c43..bbb5cdc20 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -472,7 +472,7 @@ end --[[Get a callback that either eats the item or plants it. Used for on_place callbacks for craft items which are seeds that can also be consumed. ---]] +]] function mcl_farming:get_seed_or_eat_callback(plantname, hp_change) return function(itemstack, placer, pointed_thing) local new = mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 4682447df..86c27c182 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -53,7 +53,9 @@ for i=0, 3 do end if mcl_dye and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then mcl_dye.apply_bone_meal({under=pos},clicker) - itemstack:take_item() + if not minetest.is_creative_enabled(pn) then + itemstack:take_item() + end return end @@ -61,7 +63,7 @@ for i=0, 3 do for j=1, berries_to_drop[math.random(2)] do minetest.add_item(pos, "mcl_farming:sweet_berry") end - minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_" .. 1 }) + minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"}) end return itemstack end, From fb28e192e6b39790aa3c4bbdd03ab6ad973e1c2e Mon Sep 17 00:00:00 2001 From: CyberMango Date: Sun, 1 Jan 2023 22:55:44 +0200 Subject: [PATCH 4/6] Bone meal applied on sweet berries only grows them by 1 stage now. The interface of the grow plant is a bit confusing since even with stages set to 0 the plant grows by 1 stage (if other conditions such as light are met). Therefore changing it to 0 makes the plant grow by 1. --- mods/ITEMS/mcl_dye/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 80219d298..16672b554 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -275,7 +275,7 @@ local function apply_bone_meal(pointed_thing,user) if n.name == "mcl_farming:sweet_berry_bush_3" then return minetest.add_item(vector.offset(pos,math.random()-0.5,math.random()-0.5,math.random()-0.5),"mcl_farming:sweet_berry") else - return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, n, 1, true) + return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, n, 0, true) end elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then mcl_dye.add_bone_meal_particle(pos) From 17e02aec3c96bbfd21e7ecfa1e13ca86977665fd Mon Sep 17 00:00:00 2001 From: CyberMango Date: Sun, 1 Jan 2023 23:02:38 +0200 Subject: [PATCH 5/6] Applying bone meal on a stage 3 sweet berry no longer grows it. It now ignores the bone meal and harvests the sweet berry as normal. --- mods/ITEMS/mcl_farming/sweet_berry.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 86c27c182..9033f5077 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -51,7 +51,8 @@ for i=0, 3 do minetest.record_protection_violation(pos, pn) return itemstack end - if mcl_dye and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then + if 3 ~= i and mcl_dye and + clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then mcl_dye.apply_bone_meal({under=pos},clicker) if not minetest.is_creative_enabled(pn) then itemstack:take_item() From 5e969ba9287c6328cdd387f8b9b4be9a9463101a Mon Sep 17 00:00:00 2001 From: CyberMango Date: Sun, 1 Jan 2023 23:52:35 +0200 Subject: [PATCH 6/6] Added sweet berries death messages. --- mods/HUD/mcl_death_messages/init.lua | 5 +++++ mods/ITEMS/mcl_farming/sweet_berry.lua | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 91e13995b..13ed23668 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -149,6 +149,11 @@ mcl_death_messages = { plain = "@1 went off with a bang", item = "@1 went off with a bang due to a firework fired from @3 by @2", -- order is intentional }, + sweet_berry = { + _translator = S, + plain = "@1 died a sweet death", + assist = "@1 was poked to death by a sweet berry bush whilst trying to escape @2", + }, -- Missing snowballs: The Minecraft wiki mentions them but the MC source code does not. }, } diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 9033f5077..8a91c0e79 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -51,7 +51,7 @@ for i=0, 3 do minetest.record_protection_violation(pos, pn) return itemstack end - if 3 ~= i and mcl_dye and + if 3 ~= i and mcl_dye and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then mcl_dye.apply_bone_meal({under=pos},clicker) if not minetest.is_creative_enabled(pn) then