Merge pull request 'Fix a few issues with sweet berries.' (#3187) from CyberMango/MineClone2:bug/mango/sweet_berry_fixes into master

Reviewed-on: MineClone2/MineClone2#3187
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
This commit is contained in:
ancientmarinerdev 2023-01-06 00:09:41 +00:00
commit 856a60bcc2
6 changed files with 49 additions and 32 deletions

View File

@ -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.
},
}

View File

@ -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)

View File

@ -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", {

View File

@ -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", {

View File

@ -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",

View File

@ -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},
@ -41,22 +51,20 @@ 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()
end
return
end
local stage
if node.name:find("_2") then
stage = 2
elseif node.name:find("_3") then
stage = 3
if drop_berries then
for j=1, berries_to_drop[math.random(2)] do
minetest.add_item(pos, "mcl_farming:sweet_berry")
end
if stage then
for i=1,math.random(stage) 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 +84,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