mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2025-01-08 09:37:32 +01:00
Refactor to remove drop_berries that was used exactly twice and had same function as another variable, refactor do_berry_drop to return boolean on whether berries were dropped, refactor right-click handler to make it more clear that the bonemealing check only happens if berries were not dropped
This commit is contained in:
parent
d7bb017dca
commit
e82496c812
@ -9,18 +9,18 @@ for i=0, 3 do
|
|||||||
if i > 0 then
|
if i > 0 then
|
||||||
groups.sweet_berry_thorny = 1
|
groups.sweet_berry_thorny = 1
|
||||||
end
|
end
|
||||||
local drop_berries = (i >= 2)
|
local berries_to_drop = (i >= 2) and {i - 1, i} or nil
|
||||||
local berries_to_drop = drop_berries and {i - 1, i} or nil
|
|
||||||
|
|
||||||
local on_bonemealing = nil
|
|
||||||
local function do_berry_drop(pos)
|
local function do_berry_drop(pos)
|
||||||
if not berries_to_drop then return end
|
if not berries_to_drop then return false end
|
||||||
|
|
||||||
for _=1, berries_to_drop[math.random(2)] do
|
for _=1, berries_to_drop[math.random(2)] do
|
||||||
minetest.add_item(pos, "mcl_farming:sweet_berry")
|
minetest.add_item(pos, "mcl_farming:sweet_berry")
|
||||||
end
|
end
|
||||||
minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"})
|
minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"})
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local on_bonemealing = nil
|
||||||
if i ~= 3 then
|
if i ~= 3 then
|
||||||
on_bonemealing = function(_, _, pointed_thing)
|
on_bonemealing = function(_, _, pointed_thing)
|
||||||
local pos = pointed_thing.under
|
local pos = pointed_thing.under
|
||||||
@ -49,13 +49,13 @@ for i=0, 3 do
|
|||||||
liquid_range = 0,
|
liquid_range = 0,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
-- Dont even create a table if no berries are dropped.
|
-- Dont even create a table if no berries are dropped.
|
||||||
drop = not drop_berries and "" or {
|
drop = berries_to_drop and {
|
||||||
max_items = 1,
|
max_items = 1,
|
||||||
items = {
|
items = {
|
||||||
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[1] }, rarity = 2 },
|
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[1] }, rarity = 2 },
|
||||||
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[2] } }
|
{ items = {"mcl_farming:sweet_berry " .. berries_to_drop[2] } }
|
||||||
}
|
}
|
||||||
},
|
} or "",
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, (-0.30 + (i*0.25)), 6 / 16},
|
fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, (-0.30 + (i*0.25)), 6 / 16},
|
||||||
@ -74,13 +74,11 @@ for i=0, 3 do
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if i >= 2 then
|
if do_berry_drop(pos) then return itemstack end
|
||||||
do_berry_drop(pos)
|
|
||||||
else
|
-- Use bonemeal
|
||||||
-- Use bonemeal
|
if mcl_bone_meal and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then
|
||||||
if mcl_bone_meal and clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then
|
return mcl_bone_meal.use_bone_meal(itemstack, clicker, pointed_thing)
|
||||||
return mcl_bone_meal.use_bone_meal(itemstack, clicker, pointed_thing)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
|
Loading…
Reference in New Issue
Block a user