code review feedback

This commit is contained in:
kno10 2024-10-15 10:18:22 +02:00 committed by the-real-herowl
parent 540a070c59
commit 220a7b06e6
2 changed files with 7 additions and 8 deletions

@ -45,7 +45,7 @@ local function get_moisture_level(pos)
local ndef = minetest.registered_nodes[minetest.get_node(n).name] local ndef = minetest.registered_nodes[minetest.get_node(n).name]
local soil = ndef and ndef.groups.soil local soil = ndef and ndef.groups.soil
if soil and soil >= 2 then if soil and soil >= 2 then
local m = (soil > 2 or soil == 2 and (minetest.get_meta(n):get_int("wet") or 0) > 0) and 3 or 1 local m = (soil > 2 or (soil == 2 and minetest.get_meta(n):get_int("wet") > 0)) and 3 or 1
-- corners have less weight -- corners have less weight
if x ~= 0 and z ~= 0 then m = m * 0.25 end if x ~= 0 and z ~= 0 then m = m * 0.25 end
totalm = totalm + m totalm = totalm + m
@ -63,7 +63,7 @@ end
local function get_same_crop_penalty(pos) local function get_same_crop_penalty(pos)
local name = minetest.get_node(pos).name local name = minetest.get_node(pos).name
local plant = plant_nodename_to_id[name] local plant = plant_nodename_to_id[name]
if not plant then return "unregistered plant" end if not plant then return end
local n = vector.copy(pos) local n = vector.copy(pos)
-- check adjacent positions, avoid vector allocations and reduce node accesses -- check adjacent positions, avoid vector allocations and reduce node accesses
n.x = pos.x - 1 n.x = pos.x - 1
@ -135,7 +135,7 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_wate
if not ignore_light_water then if not ignore_light_water then
local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1 local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1
for i = 1,stages do for i = 1,stages do
-- compared to MC, our ABM runs half as often, hence we use double the chance -- compared to info from the MC wiki, our ABM runs half as often, hence we use double the chance
if random() * odds >= 2 then stages = stages - 1 end if random() * odds >= 2 then stages = stages - 1 end
end end
end end
@ -145,7 +145,8 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_wate
if step == nil then return false end if step == nil then return false end
minetest.set_node(pos, { minetest.set_node(pos, {
name = plant_info.names[step + stages] or plant_info.full_grown, name = plant_info.names[step + stages] or plant_info.full_grown,
param = node.param, param2 = node.param2, param = node.param,
param2 = node.param2,
}) })
return true return true
end end

@ -91,10 +91,8 @@ minetest.register_abm({
end end
-- Revert to dirt if wetness is 0, and no plant above -- Revert to dirt if wetness is 0, and no plant above
local nn = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0)) local nn = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0))
local nn_def = nn and minetest.registered_nodes[nn.name] or nil local nn_def = nn and minetest.registered_nodes[nn.name]
if nn_def and (nn_def.groups.plant or 0) > 0 then if nn_def and (nn_def.groups.plant or 0) > 0 then return end
return
end
node.name = "mcl_core:dirt" node.name = "mcl_core:dirt"
minetest.set_node(pos, node) -- also removes "wet" metadata minetest.set_node(pos, node) -- also removes "wet" metadata
end, end,