From cffc8e0145e0323fbdc82ece64aa2aa052fe6d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 19:50:03 +0100 Subject: [PATCH 01/93] Fix loosing interact bug in mcl_shields --- mods/ITEMS/mcl_shields/init.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 6edee7e89..2d40db2f0 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -211,16 +211,36 @@ local function set_interact(player, interact) return end local meta = player:get_meta() - if meta:get_int("mcl_privs:interact_revoked") ~= 1 then - privs.interact = interact - minetest.set_player_privs(player_name, privs) - meta:set_int("mcl_privs:interact_revoked",0) + + if interact and meta:get_int("mcl_shields:interact_revoked") ~= 0 then + meta:set_int("mcl_shields:interact_revoked", 0) + privs.interact = true + elseif not interact then + meta:set_int("mcl_shields:interact_revoked", privs.interact and 1 or 0) + privs.interact = nil end + + minetest.set_player_privs(player_name, privs) end +-- Prevent player from being able to circumvent interact privilage removal by +-- using shield. +minetest.register_on_priv_revoke(function(name, revoker, priv) + if priv == "interact" and revoker then + local player = minetest.get_player_by_name(name) + if not player then + return + end + local meta = player:get_meta() + meta:set_int("mcl_shields:interact_revoked", 0) + end +end) + local shield_hud = {} local function remove_shield_hud(player) + set_interact(player, true) + if not shield_hud[player] then return end --this function takes a long time. only run it when necessary player:hud_remove(shield_hud[player]) shield_hud[player] = nil @@ -233,7 +253,6 @@ local function remove_shield_hud(player) end playerphysics.remove_physics_factor(player, "speed", "shield_speed") - set_interact(player, true) end local function add_shield_entity(player, i) @@ -344,7 +363,7 @@ local function add_shield_hud(shieldstack, player, blocking) z_index = -200, }) playerphysics.add_physics_factor(player, "speed", "shield_speed", 0.5) - set_interact(player, nil) + set_interact(player, false) end local function update_shield_hud(player, blocking, shieldstack) From d0d1217dec16938806c6cfbff561ac34e22cfccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 20:05:53 +0100 Subject: [PATCH 02/93] Remove unused code in mcl_privs --- mods/MISC/mcl_privs/init.lua | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index ddca9f946..09239390a 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -30,17 +30,5 @@ for _, action in pairs({"grant", "revoke"}) do if priv == "fly" then meta:set_int("mcl_privs:fly_changed", 1) end - - --[[ - so e.g. hackers who have been revoked of the interact privilege - will not automatically get the interact privilege through the mcl shields code back - ]] - if priv == "interact" then - if action == "revoke" then - meta:set_int("mcl_privs:interact_revoked", 1) - else - meta:set_int("mcl_privs:interact_revoked", 0) - end - end end) -end \ No newline at end of file +end From 45ae17044726cf1541c3168c8690301beccfd6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20=C3=85str=C3=B6m?= Date: Mon, 26 Feb 2024 20:09:41 +0100 Subject: [PATCH 03/93] Deduplicate shield slowdown removal code --- mods/ITEMS/mcl_shields/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 2d40db2f0..9a1458b85 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -240,6 +240,7 @@ local shield_hud = {} local function remove_shield_hud(player) set_interact(player, true) + playerphysics.remove_physics_factor(player, "speed", "shield_speed") if not shield_hud[player] then return end --this function takes a long time. only run it when necessary player:hud_remove(shield_hud[player]) @@ -251,8 +252,6 @@ local function remove_shield_hud(player) if not hf.wielditem then player:hud_set_flags({wielditem = true}) end - - playerphysics.remove_physics_factor(player, "speed", "shield_speed") end local function add_shield_entity(player, i) From 04e29c5796910fd0dd3035c43fcec7b3af956716 Mon Sep 17 00:00:00 2001 From: Loveaabb Date: Wed, 22 May 2024 10:20:26 +0000 Subject: [PATCH 04/93] Several improvements to the Shield --- mods/ITEMS/mcl_shields/init.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 9a1458b85..0bc0a18ba 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -269,6 +269,15 @@ local function remove_shield_entity(player, i) end end +local function is_node_stack(itemstack) + return itemstack:get_definition().drawtype -- only node's definition table contains element "drawtype" +end + +local function is_rmb_conflicting_node(nodename) + nodedef = minetest.registered_nodes[nodename] + return nodedef.on_rightclick +end + local function handle_blocking(player) local player_shield = mcl_shields.players[player] local rmb = player:get_player_control().RMB @@ -284,7 +293,7 @@ local function handle_blocking(player) local pos = player:get_pos() if shield_in_hand then if not_blocking then - minetest.after(0.25, function() + minetest.after(0.05, function() if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then player_shield.blocking = 2 set_shield(player, true, 2) @@ -295,11 +304,16 @@ local function handle_blocking(player) end elseif shield_in_offhand then local pointed_thing = mcl_util.get_pointed_thing(player, true) - local offhand_can_block = (wielded_item(player) == "" or not pointed_thing) - and (minetest.get_item_group(wielded_item(player), "bow") ~= 1 and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1) + local wielded_stack = player:get_wielded_item() + local offhand_can_block = (minetest.get_item_group(wielded_item(player), "bow") ~= 1 + and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1) if pointed_thing and pointed_thing.type == "node" then - if minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "container") > 1 then + local pointed_node = minetest.get_node(pointed_thing.under) + if minetest.get_item_group(pointed_node.name, "container") > 1 + or is_rmb_conflicting_node(pointed_node.name) + or is_node_stack(wielded_stack) + then return end end @@ -308,7 +322,7 @@ local function handle_blocking(player) return end if not_blocking then - minetest.after(0.25, function() + minetest.after(0.05, function() if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then player_shield.blocking = 1 set_shield(player, true, 1) From f26c34e65f507230ac64baffa417abd4e8e142c1 Mon Sep 17 00:00:00 2001 From: Loveaabb Date: Tue, 21 May 2024 14:51:43 +0000 Subject: [PATCH 05/93] Bugfix: Shield fails to block arrows --- mods/ITEMS/mcl_bows/arrow.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 652819aa6..14d289c10 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -257,10 +257,10 @@ function ARROW_ENTITY.on_step(self, dtime) mcl_burning.set_on_fire(obj, 5) end if not self._in_player and not self._blocked then - obj:punch(self.object, 1.0, { - full_punch_interval=1.0, - damage_groups={fleshy=self._damage}, - }, self.object:get_velocity()) + mcl_util.deal_damage(obj, self._damage, {type = "arrow", source = self._shooter, direct = self.object}) + if self._extra_hit_func then + self._extra_hit_func(obj) + end if obj:is_player() then if not mcl_shields.is_blocking(obj) then local placement From d5bc0613d8aba3b0febcbcaf088bdab50d9f70a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Fri, 9 Aug 2024 16:12:15 +0700 Subject: [PATCH 06/93] Make node itemstack check in mcl_shields less hacky --- mods/ITEMS/mcl_shields/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 0bc0a18ba..62904aa1d 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -270,7 +270,7 @@ local function remove_shield_entity(player, i) end local function is_node_stack(itemstack) - return itemstack:get_definition().drawtype -- only node's definition table contains element "drawtype" + return (itemstack:get_definition().type == "node") end local function is_rmb_conflicting_node(nodename) From 084741b733157af951bae9962ba65cffc9f6b19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Fri, 16 Aug 2024 10:54:21 +0700 Subject: [PATCH 07/93] Fix using shield on unknown nodes and cleanup --- mods/ITEMS/mcl_shields/init.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index 62904aa1d..b3323bd3f 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -269,12 +269,8 @@ local function remove_shield_entity(player, i) end end -local function is_node_stack(itemstack) - return (itemstack:get_definition().type == "node") -end - local function is_rmb_conflicting_node(nodename) - nodedef = minetest.registered_nodes[nodename] + nodedef = minetest.registered_nodes[nodename] or {} return nodedef.on_rightclick end @@ -312,7 +308,7 @@ local function handle_blocking(player) local pointed_node = minetest.get_node(pointed_thing.under) if minetest.get_item_group(pointed_node.name, "container") > 1 or is_rmb_conflicting_node(pointed_node.name) - or is_node_stack(wielded_stack) + or wielded_stack:get_definition().type == "node" then return end From f86a641dfa82039d206293a76a16fa15dd39815e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Tue, 17 Sep 2024 12:22:05 +0700 Subject: [PATCH 08/93] Improve shield block code and unhardcode offhand group --- mods/ITEMS/mcl_bows/bow.lua | 4 ++-- mods/ITEMS/mcl_bows/crossbow.lua | 6 +++--- mods/ITEMS/mcl_shields/init.lua | 33 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 9f381f501..34784ab07 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -168,7 +168,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula itemstack:get_meta():set_string("active", "true") return itemstack end, - groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1}, + groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1}, _mcl_uses = 385, }) @@ -216,7 +216,7 @@ for level=0, 2 do wield_scale = mcl_vars.tool_wield_scale, stack_max = 1, range = 0, -- Pointing range to 0 to prevent punching with bow :D - groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1}, + groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, cannot_block=1, enchantability=1}, -- Trick to disable digging as well on_use = function() return end, on_drop = function(itemstack, dropper, pos) diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index c1cb7f8be..b6dc31dd0 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -158,7 +158,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula itemstack:get_meta():set_string("active", "true") return itemstack end, - groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1}, + groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1}, _mcl_uses = 326, }) @@ -193,7 +193,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula itemstack:get_meta():set_string("active", "true") return itemstack end, - groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1,not_in_creative_inventory=1}, + groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1}, _mcl_uses = 326, }) @@ -238,7 +238,7 @@ for level=0, 2 do wield_scale = mcl_vars.tool_wield_scale, stack_max = 1, range = 0, -- Pointing range to 0 to prevent punching with bow :D - groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1}, + groups = {not_in_creative_inventory=1, not_in_craft_guide=1, cannot_block=1, bow=1, enchantability=1}, -- Trick to disable digging as well on_use = function() return end, on_drop = function(itemstack, dropper, pos) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index b3323bd3f..e1b790049 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -270,7 +270,7 @@ local function remove_shield_entity(player, i) end local function is_rmb_conflicting_node(nodename) - nodedef = minetest.registered_nodes[nodename] or {} + local nodedef = minetest.registered_nodes[nodename] or {} return nodedef.on_rightclick end @@ -282,11 +282,22 @@ local function handle_blocking(player) return end + local pointed_thing = mcl_util.get_pointed_thing(player, true) + local wielded_stack = player:get_wielded_item() + local shield_in_offhand = mcl_shields.wielding_shield(player, 1) local shield_in_hand = mcl_shields.wielding_shield(player) local not_blocking = player_shield.blocking == 0 - local pos = player:get_pos() + if pointed_thing and pointed_thing.type == "node" then + local pointed_node = minetest.get_node(pointed_thing.under) + if minetest.get_item_group(pointed_node.name, "container") > 1 + or is_rmb_conflicting_node(pointed_node.name) + or wielded_stack:get_definition().type == "node" then + return + end + end + if shield_in_hand then if not_blocking then minetest.after(0.05, function() @@ -299,27 +310,15 @@ local function handle_blocking(player) player_shield.blocking = 2 end elseif shield_in_offhand then - local pointed_thing = mcl_util.get_pointed_thing(player, true) - local wielded_stack = player:get_wielded_item() - local offhand_can_block = (minetest.get_item_group(wielded_item(player), "bow") ~= 1 - and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1) - - if pointed_thing and pointed_thing.type == "node" then - local pointed_node = minetest.get_node(pointed_thing.under) - if minetest.get_item_group(pointed_node.name, "container") > 1 - or is_rmb_conflicting_node(pointed_node.name) - or wielded_stack:get_definition().type == "node" - then - return - end - end + local offhand_can_block = minetest.get_item_group(wielded_item(player), "cannot_block") ~= 1 if not offhand_can_block then return end if not_blocking then minetest.after(0.05, function() - if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then + if (not_blocking or not shield_in_hand) and shield_in_offhand + and rmb and offhand_can_block then player_shield.blocking = 1 set_shield(player, true, 1) end From e1ace4ad01d12dad95b4e2b37919d644292da013 Mon Sep 17 00:00:00 2001 From: kno10 Date: Wed, 9 Oct 2024 18:01:20 +0200 Subject: [PATCH 09/93] pumpkin/melon growth only tests one neighbor every time --- mods/ITEMS/mcl_farming/shared_functions.lua | 99 ++++----------------- 1 file changed, 15 insertions(+), 84 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 241e61c56..3264287ae 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -89,7 +89,7 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light, low stages = stages or 1 local plant_info = plant_lists[identifier] local intervals_counter = get_intervals_counter(pos, plant_info.interval, plant_info.chance) - if stages > 0 then intervals_counters = intervals_counter - 1 end + if stages > 0 then intervals_counter = intervals_counter - 1 end if low_speed then -- 10% speed approximately if intervals_counter < 1.01 and math.random(0, 9) > 0 then return false end intervals_counter = intervals_counter / 10 @@ -163,34 +163,6 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s connected_stem_basename .. "_t", connected_stem_basename .. "_b" } - -- Connect the stem at stempos to the first neighboring gourd block. - -- No-op if not a stem or no gourd block found - local function try_connect_stem(stempos) - local stem = minetest.get_node(stempos) - if stem.name ~= full_unconnected_stem then return false end - -- four directions, but avoid table allocation - local neighbor = vector.offset(stempos, 1, 0, 0) - if minetest.get_node(neighbor).name == gourd_itemstring then - minetest.swap_node(stempos, { name = connected_stem_names[1] }) - return true - end - local neighbor = vector.offset(stempos, -1, 0, 0) - if minetest.get_node(neighbor).name == gourd_itemstring then - minetest.swap_node(stempos, { name = connected_stem_names[2] }) - return true - end - local neighbor = vector.offset(stempos, 0, 0, 1) - if minetest.get_node(neighbor).name == gourd_itemstring then - minetest.swap_node(stempos, { name = connected_stem_names[3] }) - return true - end - local neighbor = vector.offset(stempos, 0, 0, -1) - if minetest.get_node(neighbor).name == gourd_itemstring then - minetest.swap_node(stempos, { name = connected_stem_names[4] }) - return true - end - end - -- Register gourd if not gourd_def.after_destruct then gourd_def.after_destruct = function(blockpos, oldnode) @@ -200,34 +172,21 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s local stempos = vector.offset(blockpos, -1, 0, 0) if minetest.get_node(stempos).name == connected_stem_names[1] then minetest.swap_node(stempos, { name = full_unconnected_stem }) - try_connect_stem(stempos) end local stempos = vector.offset(blockpos, 1, 0, 0) if minetest.get_node(stempos).name == connected_stem_names[2] then minetest.swap_node(stempos, { name = full_unconnected_stem }) - try_connect_stem(stempos) end local stempos = vector.offset(blockpos, 0, 0, -1) if minetest.get_node(stempos).name == connected_stem_names[3] then minetest.swap_node(stempos, { name = full_unconnected_stem }) - try_connect_stem(stempos) end local stempos = vector.offset(blockpos, 0, 0, 1) if minetest.get_node(stempos).name == connected_stem_names[4] then minetest.swap_node(stempos, { name = full_unconnected_stem }) - try_connect_stem(stempos) end end end - if not gourd_def.on_construct then - function gourd_def.on_construct(blockpos) - -- Connect all unconnected stems at full size - try_connect_stem(vector.offset(blockpos, 1, 0, 0)) - try_connect_stem(vector.offset(blockpos, -1, 0, 0)) - try_connect_stem(vector.offset(blockpos, 0, 0, 1)) - try_connect_stem(vector.offset(blockpos, 0, 0, -1)) - end - end minetest.register_node(gourd_itemstring, gourd_def) -- Register unconnected stem @@ -243,7 +202,6 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s stem_def.drop = stem_def.drop or stem_drop stem_def.groups = stem_def.groups or { dig_immediate = 3, not_in_creative_inventory = 1, plant = 1, attached_node = 1, dig_by_water = 1, destroy_by_lava_flow = 1 } stem_def.sounds = stem_def.sounds or mcl_sounds.node_sound_leaves_defaults() - stem_def.on_construct = stem_def.on_construct or try_connect_stem minetest.register_node(stem_itemstring, stem_def) -- Register connected stems @@ -313,16 +271,6 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s end end - -- Check for a suitable spot to grow - local function check_neighbor_soil(blockpos) - if minetest.get_node(blockpos).name ~= "air" then return false end - local floorpos = vector.offset(blockpos, 0, -1, 0) - local floorname = minetest.get_node(floorpos).name - if floorname == "mcl_core:dirt" then return true end - local floordef = minetest.registered_nodes[floorname] - return floordef.groups.grass_block or floordef.groups.dirt or (floordef.groups.soil or 0) >= 2 - end - minetest.register_abm({ label = "Grow gourd stem to gourd (" .. full_unconnected_stem .. " → " .. gourd_itemstring .. ")", nodenames = { full_unconnected_stem }, @@ -332,37 +280,21 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s action = function(stempos) local light = minetest.get_node_light(stempos) if not light or light <= 10 then return end - -- Check the four neighbors and filter out neighbors where gourds can't grow - local neighbor, dir, nchance = nil, -1, 1 -- reservoir sampling - if nchance == 1 or math.random(1, nchance) == 1 then - local blockpos = vector.offset(stempos, 1, 0, 0) - if check_neighbor_soil(blockpos) then - neighbor, dir, nchance = blockpos, 1, nchance + 1 - end - end - if nchance == 1 or math.random(1, nchance) == 1 then - local blockpos = vector.offset(stempos, -1, 0, 0) - if check_neighbor_soil(blockpos) then - neighbor, dir, nchance = blockpos, 2, nchance + 1 - end - end - if nchance == 1 or math.random(1, nchance) == 1 then - local blockpos = vector.offset(stempos, 0, 0, 1) - if check_neighbor_soil(blockpos) then - neighbor, dir, nchance = blockpos, 3, nchance + 1 - end - end - if nchance == 1 or math.random(1, nchance) == 1 then - local blockpos = vector.offset(stempos, 0, 0, -1) - if check_neighbor_soil(blockpos) then - neighbor, dir, nchance = blockpos, 4, nchance + 1 - end - end + -- Pick one neighbor and check if it can be used to grow + local dir = math.random(1, 4) -- pick direction at random + local neighbor = (dir == 1 and vector.offset(stempos, 1, 0, 0)) + or (dir == 2 and vector.offset(stempos, -1, 0, 0)) + or (dir == 3 and vector.offset(stempos, 0, 0, 1)) + or vector.offset(stempos, 0, 0, -1) + if minetest.get_node(neighbor).name ~= "air" then return end -- occupied + -- check for suitable floor: grass, dirt, or soil + local floorpos = vector.offset(neighbor, 0, -1, 0) + local floorname = minetest.get_node(floorpos).name + local floordef = minetest.registered_nodes[floorname] + if not floordef then return end + if (floordef.groups.grass_block or 0) == 0 and (floordef.groups.dirt or 0) == 0 and (floordef.groups.soil or 0) < 2 then return end -- not suitable for growing - -- Gourd needs at least 1 free neighbor to grow - if not neighbor then return end minetest.swap_node(stempos, { name = connected_stem_names[dir] }) - -- Place the gourd if gourd_def.paramtype2 == "facedir" then local p2 = (dir == 1 and 3) or (dir == 2 and 1) or (dir == 3 and 2) or 0 minetest.add_node(neighbor, { name = gourd_itemstring, param2 = p2 }) @@ -371,8 +303,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s end -- Reset farmland, etc. to dirt when the gourd grows on top - local floorpos = vector.offset(neighbor, 0, -1, 0) - if minetest.get_item_group(minetest.get_node(floorpos).name, "dirtifies_below_solid") == 1 then + if (floordef.groups.dirtifies_below_solid or 0) > 0 then minetest.set_node(floorpos, { name = "mcl_core:dirt" }) end end, From c4030115c4ecfb599a4596d7a597c941a960aa9a Mon Sep 17 00:00:00 2001 From: kno10 Date: Wed, 9 Oct 2024 22:15:30 +0200 Subject: [PATCH 10/93] improve moisture logic --- mods/ITEMS/mcl_farming/shared_functions.lua | 72 ++++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 3264287ae..5d4d5d49e 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -50,6 +50,55 @@ local function get_avg_light_level(pos) return math.ceil(summary / counter) end +local function get_moisture_level(pos) + local n = vector.offset(pos, 0, -1, 0) + local totalm = 1 + for z = -1,1 do + n.z = pos.z + z + for x = -1,1 do + n.x = pos.x + x + local ndef = minetest.registered_nodes[minetest.get_node(n).name] + local soil = ndef and ndef.groups.soil or 0 + local m = (soil == 2 and 2) or (soil >= 3 and 4) or 0 + if x ~= 0 and z ~= 0 then m = m * 0.25 end + totalm = totalm + m + end + end + return totalm +end + +-- moisture penalty function: +-- 0.5 if both on the x axis and the z axis the same plant growth +-- 0.5 if one diagonal neighbor is the same +-- 1.0 otherwise +local function get_moisture_penalty(pos) + local name = minetest.get_node(pos).name + local n, p = vector.copy(pos), 1 + -- check adjacent points, avoid vector allocations and reduce node accesses + n.x = pos.x - 1 + local dx = minetest.get_node(n).name == name + n.x = pos.x + 1 + dx = dx or minetest.get_node(n).name == name + if dx then + n.x = pos.x + n.z = pos.z - 1 + local dz = minetest.get_node(n).name == name + n.z = pos.z + 1 + dz = dz or minetest.get_node(n).name == name + if dz then return 0.5 end + end + -- check diagonals, clockwise + n.x, n.z = pos.x - 1, pos.z - 1 + if minetest.get_node(n).name == name then return 0.5 end + n.x = pos.x + 1 + if minetest.get_node(n).name == name then return 0.5 end + n.z = pos.z + 1 + if minetest.get_node(n).name == name then return 0.5 end + n.x = pos.x - 1 + if minetest.get_node(n).name == name then return 0.5 end + return 1 +end + function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) local plant_info = {} plant_info.full_grown = full_grown @@ -70,8 +119,7 @@ function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) interval = interval, chance = chance, action = function(pos, node) - local low_speed = minetest.get_node(vector.offset(pos, 0, -1, 0)).name ~= "mcl_farming:soil_wet" - mcl_farming:grow_plant(identifier, pos, node, 1, false, low_speed) + mcl_farming:grow_plant(identifier, pos, node, 1, false) end, }) end @@ -82,7 +130,7 @@ end -- node: Node table -- stages: Number of stages to advance (optional, defaults to 1) -- ignore_light: if true, ignore light requirements for growing --- low_speed: grow more slowly (not wet), default false +-- low_speed: grow more slowly (not wet), default false -- OBSOLETE -- Returns true if plant has been grown by 1 or more stages. -- Returns false if nothing changed. function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light, low_speed) @@ -96,17 +144,22 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light, low end if not ignore_light and intervals_counter < 1.5 then local light = minetest.get_node_light(pos) - if not light or light < 10 then return false end + if not light or light < 9 then return false end end if intervals_counter >= 1.5 then local average_light_level = get_avg_light_level(pos) if average_light_level < 0.1 then return false end - if average_light_level < 10 then + if average_light_level < 9 then intervals_counter = intervals_counter * average_light_level / 10 end end + if low_speed == nil then + local moisture = get_moisture_level(pos) * get_moisture_penalty(pos) + if math.random(1, math.floor(25 / moisture) + 1) ~= 1 then return end + end + local step = plant_info.step_from_name[node.name] if step == nil then return false end stages = stages + math.floor(intervals_counter) @@ -279,7 +332,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s chance = grow_chance, action = function(stempos) local light = minetest.get_node_light(stempos) - if not light or light <= 10 then return end + if not light or light < 9 then return end -- Pick one neighbor and check if it can be used to grow local dir = math.random(1, 4) -- pick direction at random local neighbor = (dir == 1 and vector.offset(stempos, 1, 0, 0)) @@ -294,6 +347,10 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s if not floordef then return end if (floordef.groups.grass_block or 0) == 0 and (floordef.groups.dirt or 0) == 0 and (floordef.groups.soil or 0) < 2 then return end -- not suitable for growing + -- check moisture level + local moisture = get_moisture_level(stempos) * get_moisture_penalty(stempos) + if math.random(1, math.floor(25 / moisture) + 1) ~= 1 then return end + minetest.swap_node(stempos, { name = connected_stem_names[dir] }) if gourd_def.paramtype2 == "facedir" then local p2 = (dir == 1 and 3) or (dir == 2 and 1) or (dir == 3 and 2) or 0 @@ -342,8 +399,7 @@ minetest.register_lbm({ action = function(pos, node, dtime_s) local identifier = plant_nodename_to_id_list[node.name] if not identifier then return end - local low_speed = minetest.get_node(vector.offset(pos, 0, -1, 0)).name ~= "mcl_farming:soil_wet" - mcl_farming:grow_plant(identifier, pos, node, 0, false, low_speed) + mcl_farming:grow_plant(identifier, pos, node, 0, false) end, }) From 9376cf92b134ad48f82d97daa02ad6768f217f4c Mon Sep 17 00:00:00 2001 From: kno10 Date: Thu, 10 Oct 2024 14:37:01 +0200 Subject: [PATCH 11/93] Adjust growth speeds --- mods/ITEMS/mcl_farming/beetroot.lua | 3 ++- mods/ITEMS/mcl_farming/carrots.lua | 2 +- mods/ITEMS/mcl_farming/melon.lua | 4 ++-- mods/ITEMS/mcl_farming/potatoes.lua | 2 +- mods/ITEMS/mcl_farming/pumpkin.lua | 4 ++-- mods/ITEMS/mcl_farming/sweet_berry.lua | 2 +- mods/ITEMS/mcl_farming/wheat.lua | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 962fb100e..01a572355 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -171,7 +171,8 @@ minetest.register_craft({ }, }) -mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 68, 3) +-- beetroots grow 1/3rd of the default speed +mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 13.512, 15) if minetest.get_modpath("doc") then for i = 1, 2 do diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index e8e295d8b..fe68767f2 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -118,7 +118,7 @@ minetest.register_craft({ } }) -mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 25, 20) +mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 13.513, 5) if minetest.get_modpath("doc") then for i=2,7 do diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index d62288333..b8242f112 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -123,10 +123,10 @@ local stem_def = { } -- Register stem growth -mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 30, 5) +mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 13.514, 5) -- Register actual melon, connected stems and stem-to-melon growth -mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 25, 15, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 13.515, 5, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") -- Items and crafting minetest.register_craftitem("mcl_farming:melon_item", { diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index 66c5169c4..a19070d1e 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -135,7 +135,7 @@ minetest.register_craft({ cooktime = 10, }) -mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 19.75, 20) +mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 13.516, 5) minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 5bcf5e8a3..d33e73f16 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -180,10 +180,10 @@ if minetest.get_modpath("mcl_armor") then end -- Register stem growth -mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 30, 5) +mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 13.517, 5) -- Register actual pumpkin, connected stems and stem-to-pumpkin growth -mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 30, 15, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 13.518, 5, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") -- Steal function to properly disconnect a carved pumpkin pumpkin_face_base_def.after_destruct = minetest.registered_nodes["mcl_farming:pumpkin"].after_destruct diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index fdcc460df..328339f01 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -100,7 +100,7 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { minetest.register_alias("mcl_sweet_berry:sweet_berry", "mcl_farming:sweet_berry") -- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages. -mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 68, 3) +mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 13.519, 15) local function berry_damage_check(obj) local p = obj:get_pos() diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index 051c5a8d6..d30cc77a7 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -99,7 +99,7 @@ minetest.register_node("mcl_farming:wheat", { } }) -mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 25, 20) +mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 13.520, 5) minetest.register_craftitem("mcl_farming:wheat_item", { description = S("Wheat"), From e9453d62103e2e61389092adac1dd14980c765e0 Mon Sep 17 00:00:00 2001 From: kno10 Date: Thu, 10 Oct 2024 16:23:54 +0200 Subject: [PATCH 12/93] Add plant growth speed option, drop average light level Closes: #4683 by removal --- mods/ITEMS/mcl_farming/shared_functions.lua | 94 +++++++++------------ settingtypes.txt | 3 + 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 5d4d5d49e..f31272dc9 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -8,7 +8,10 @@ local vector = vector local plant_lists = {} mcl_farming.plant_lists = plant_lists -- export -local plant_nodename_to_id_list = {} +local plant_nodename_to_id_list = {} -- map nodes to plants +local plant_step_from_name = {} -- map nodes to growth steps + +local growth_factor = tonumber(minetest.settings:get("vl_plant_growth")) or 1.0 local time_speed = tonumber(minetest.settings:get("time_speed")) or 72 local time_multiplier = time_speed > 0 and (86400 / time_speed) or 0 @@ -30,26 +33,6 @@ local function get_intervals_counter(pos, interval, chance) return (current_game_time - last_game_time) / approx_interval end -local function get_avg_light_level(pos) - local meta = minetest.get_meta(pos) - -- EWMA would use a single variable: - -- local avg = meta:get_float("avg_light") - -- avg = avg + (node_light - avg) * 0.985 - -- meta.set_float("avg_light", avg) - local summary = meta:get_int("avg_light_summary") - local counter = meta:get_int("avg_light_count") - if counter > 99 then - summary, counter = math.ceil(summary * 0.5), 50 - end - local node_light = minetest.get_node_light(pos) - if node_light ~= nil then - summary, counter = summary + node_light, counter + 1 - meta:set_int("avg_light_summary", summary) - meta:set_int("avg_light_count", counter) - end - return math.ceil(summary / counter) -end - local function get_moisture_level(pos) local n = vector.offset(pos, 0, -1, 0) local totalm = 1 @@ -100,6 +83,7 @@ local function get_moisture_penalty(pos) end function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) + interval = growth_factor > 0 and (interval / growth_factor) or 0 local plant_info = {} plant_info.full_grown = full_grown plant_info.names = names @@ -108,11 +92,11 @@ function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) for _, nodename in pairs(names) do plant_nodename_to_id_list[nodename] = identifier end - plant_info.step_from_name = {} for i, name in ipairs(names) do - plant_info.step_from_name[name] = i + plant_step_from_name[name] = i end plant_lists[identifier] = plant_info + if interval == 0 then return end -- growth disabled minetest.register_abm({ label = string.format("Farming plant growth (%s)", identifier), nodenames = names, @@ -129,45 +113,32 @@ end -- pos: Position -- node: Node table -- stages: Number of stages to advance (optional, defaults to 1) --- ignore_light: if true, ignore light requirements for growing --- low_speed: grow more slowly (not wet), default false -- OBSOLETE +-- ignore_light_water: if true, ignore light and water requirements for growing -- Returns true if plant has been grown by 1 or more stages. -- Returns false if nothing changed. -function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light, low_speed) - stages = stages or 1 +function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_water) + stages = stages or 1 -- 0 when run from block loading + -- check light + if not ignore_light_water and (minetest.get_node_light(pos) or 0) < 0 then return false end + -- number of missed interval ticks, for catch-up in block loading local plant_info = plant_lists[identifier] - local intervals_counter = get_intervals_counter(pos, plant_info.interval, plant_info.chance) - if stages > 0 then intervals_counter = intervals_counter - 1 end - if low_speed then -- 10% speed approximately - if intervals_counter < 1.01 and math.random(0, 9) > 0 then return false end - intervals_counter = intervals_counter / 10 + if plant_info then + stages = stages + math.floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) end - if not ignore_light and intervals_counter < 1.5 then - local light = minetest.get_node_light(pos) - if not light or light < 9 then return false end - end - - if intervals_counter >= 1.5 then - local average_light_level = get_avg_light_level(pos) - if average_light_level < 0.1 then return false end - if average_light_level < 9 then - intervals_counter = intervals_counter * average_light_level / 10 + if not ignore_light_water then + local odds = math.floor(25 / (get_moisture_level(pos) * get_moisture_penalty(pos))) + 1 + for i = 1,stages do + if math.random(1, odds) ~= 1 then stages = stages - 1 end end end - if low_speed == nil then - local moisture = get_moisture_level(pos) * get_moisture_penalty(pos) - if math.random(1, math.floor(25 / moisture) + 1) ~= 1 then return end - end - - local step = plant_info.step_from_name[node.name] - if step == nil then return false end - stages = stages + math.floor(intervals_counter) if stages == 0 then return false end - local new_node = { name = plant_info.names[step + stages] or plant_info.full_grown } - new_node.param = node.param - new_node.param2 = node.param2 - minetest.set_node(pos, new_node) + local step = plant_step_from_name[node.name] + if step == nil then return false end + minetest.set_node(pos, { + name = plant_info.names[step + stages] or plant_info.full_grown, + param = node.param, param2 = node.param2, + }) return true end @@ -210,6 +181,7 @@ end function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, stem_itemstring, stem_def, stem_drop, gourd_itemstring, gourd_def, grow_interval, grow_chance, connected_stem_texture) + grow_interval = growth_factor > 0 and (grow_interval / growth_factor) or 0 local connected_stem_names = { connected_stem_basename .. "_r", connected_stem_basename .. "_l", @@ -324,6 +296,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s end end + if grow_interval == 0 then return end minetest.register_abm({ label = "Grow gourd stem to gourd (" .. full_unconnected_stem .. " → " .. gourd_itemstring .. ")", nodenames = { full_unconnected_stem }, @@ -403,3 +376,16 @@ minetest.register_lbm({ end, }) +-- The average light levels were unreliable +minetest.register_lbm({ + label = "Drop legacy average lighting data", + name = "mcl_farming:drop_average_light_meta", + nodenames = { "group:plant" }, + run_at_every_load = false, -- only convert once + action = function(pos, node, dtime_s) + local meta = minetest.get_meta(pos) + meta:set_string("avg_light_summary", "") -- drop + meta:set_string("avg_light_count", "") -- drop + end, +}) + diff --git a/settingtypes.txt b/settingtypes.txt index 7cfa03ce2..86c635582 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -45,6 +45,9 @@ mcl_disabled_structures (Disabled structures) string # Comma separated list of disabled event names mcl_disabled_events (Disabled events) string +# Control the relative plant growth speed (default: 1) +vl_plant_growth (Plant growth factor) float 1.0 0 100 + [Players] # If enabled, players respawn at the bed they last lay on instead of normal # spawn. From 78a958db4e548b03618aaa9b2dd604d7a07a55c7 Mon Sep 17 00:00:00 2001 From: kno10 Date: Thu, 10 Oct 2024 17:32:36 +0200 Subject: [PATCH 13/93] Double the odds, to halve the ABM frequencies. --- mods/ITEMS/mcl_farming/beetroot.lua | 2 +- mods/ITEMS/mcl_farming/carrots.lua | 2 +- mods/ITEMS/mcl_farming/melon.lua | 4 ++-- mods/ITEMS/mcl_farming/potatoes.lua | 2 +- mods/ITEMS/mcl_farming/pumpkin.lua | 4 ++-- mods/ITEMS/mcl_farming/shared_functions.lua | 14 +++++++++----- mods/ITEMS/mcl_farming/sweet_berry.lua | 4 ++-- mods/ITEMS/mcl_farming/wheat.lua | 2 +- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 01a572355..904274b8e 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -172,7 +172,7 @@ minetest.register_craft({ }) -- beetroots grow 1/3rd of the default speed -mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 13.512, 15) +mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 16.2012, 25) if minetest.get_modpath("doc") then for i = 1, 2 do diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index fe68767f2..580e4da5a 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -118,7 +118,7 @@ minetest.register_craft({ } }) -mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 13.513, 5) +mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 5.4013, 25) if minetest.get_modpath("doc") then for i=2,7 do diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index b8242f112..74c95e686 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -123,10 +123,10 @@ local stem_def = { } -- Register stem growth -mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 13.514, 5) +mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 5.4014, 25) -- Register actual melon, connected stems and stem-to-melon growth -mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 13.515, 5, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 5.4015, 25, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") -- Items and crafting minetest.register_craftitem("mcl_farming:melon_item", { diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index a19070d1e..455befa7d 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -135,7 +135,7 @@ minetest.register_craft({ cooktime = 10, }) -mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 13.516, 5) +mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 5.4016, 25) minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index d33e73f16..e06ce7774 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -180,10 +180,10 @@ if minetest.get_modpath("mcl_armor") then end -- Register stem growth -mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 13.517, 5) +mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 5.4017, 25) -- Register actual pumpkin, connected stems and stem-to-pumpkin growth -mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 13.518, 5, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 5.4018, 25, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") -- Steal function to properly disconnect a carved pumpkin pumpkin_face_base_def.after_destruct = minetest.registered_nodes["mcl_farming:pumpkin"].after_destruct diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index f31272dc9..80c1ce1fa 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -5,6 +5,8 @@ -- local math = math local vector = vector +local random = math.random +local floor = math.floor local plant_lists = {} mcl_farming.plant_lists = plant_lists -- export @@ -123,12 +125,13 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_wate -- number of missed interval ticks, for catch-up in block loading local plant_info = plant_lists[identifier] if plant_info then - stages = stages + math.floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) + stages = stages + floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) end if not ignore_light_water then - local odds = math.floor(25 / (get_moisture_level(pos) * get_moisture_penalty(pos))) + 1 + local odds = floor(25 / (get_moisture_level(pos) * get_moisture_penalty(pos))) + 1 for i = 1,stages do - if math.random(1, odds) ~= 1 then stages = stages - 1 end + -- we double the odds, and rather call the ABM less often + if random() * odds >= 2 then stages = stages - 1 end end end @@ -307,7 +310,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s local light = minetest.get_node_light(stempos) if not light or light < 9 then return end -- Pick one neighbor and check if it can be used to grow - local dir = math.random(1, 4) -- pick direction at random + local dir = random(1, 4) -- pick direction at random local neighbor = (dir == 1 and vector.offset(stempos, 1, 0, 0)) or (dir == 2 and vector.offset(stempos, -1, 0, 0)) or (dir == 3 and vector.offset(stempos, 0, 0, 1)) @@ -322,7 +325,8 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s -- check moisture level local moisture = get_moisture_level(stempos) * get_moisture_penalty(stempos) - if math.random(1, math.floor(25 / moisture) + 1) ~= 1 then return end + -- we double the odds, and rather call the ABM less often + if random() * (math.floor(25 / moisture) + 1) >= 2 then return end minetest.swap_node(stempos, { name = connected_stem_names[dir] }) if gourd_def.paramtype2 == "facedir" then diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 328339f01..7f565e97b 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -99,8 +99,8 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { }) minetest.register_alias("mcl_sweet_berry:sweet_berry", "mcl_farming:sweet_berry") --- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages. -mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 13.519, 15) +-- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages, 1/3rd of the default. +mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 16.2019, 25) local function berry_damage_check(obj) local p = obj:get_pos() diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index d30cc77a7..b68ac4ce4 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -99,7 +99,7 @@ minetest.register_node("mcl_farming:wheat", { } }) -mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 13.520, 5) +mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 5.4020, 25) minetest.register_craftitem("mcl_farming:wheat_item", { description = S("Wheat"), From 540a070c596bdac9bcf70adff6f7198a5206b3d5 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 13 Oct 2024 21:42:42 +0200 Subject: [PATCH 14/93] always use day light level, more fixes --- mods/ITEMS/mcl_farming/shared_functions.lua | 80 +++++++------- mods/ITEMS/mcl_farming/soil.lua | 112 ++++++++------------ 2 files changed, 87 insertions(+), 105 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 80c1ce1fa..94450acbd 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -10,7 +10,7 @@ local floor = math.floor local plant_lists = {} mcl_farming.plant_lists = plant_lists -- export -local plant_nodename_to_id_list = {} -- map nodes to plants +local plant_nodename_to_id = {} -- map nodes to plants local plant_step_from_name = {} -- map nodes to growth steps local growth_factor = tonumber(minetest.settings:get("vl_plant_growth")) or 1.0 @@ -22,19 +22,19 @@ local function get_intervals_counter(pos, interval, chance) if time_multiplier == 0 then return 0 end -- "wall clock time", so plants continue to grow while sleeping local current_game_time = (minetest.get_day_count() + minetest.get_timeofday()) * time_multiplier - local approx_interval = math.max(interval, 1) * math.max(chance, 1) local meta = minetest.get_meta(pos) local last_game_time = meta:get_float("last_gametime") - if last_game_time < 1 then - last_game_time = current_game_time - approx_interval * 0.5 - elseif last_game_time == current_game_time then - current_game_time = current_game_time + approx_interval - end meta:set_float("last_gametime", current_game_time) - return (current_game_time - last_game_time) / approx_interval + if last_game_time < 1 then return 0 end + return (current_game_time - last_game_time) / (interval * chance) end +-- wetness of the surroundings +-- dry farmland = 1 point +-- wet farmland = 3 points +-- diagonal neighbors only 25% +-- center point gives + 1 point local function get_moisture_level(pos) local n = vector.offset(pos, 0, -1, 0) local totalm = 1 @@ -43,44 +43,50 @@ local function get_moisture_level(pos) for x = -1,1 do n.x = pos.x + x local ndef = minetest.registered_nodes[minetest.get_node(n).name] - local soil = ndef and ndef.groups.soil or 0 - local m = (soil == 2 and 2) or (soil >= 3 and 4) or 0 - if x ~= 0 and z ~= 0 then m = m * 0.25 end - totalm = totalm + m + local soil = ndef and ndef.groups.soil + 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 + -- corners have less weight + if x ~= 0 and z ~= 0 then m = m * 0.25 end + totalm = totalm + m + end end end return totalm end -- moisture penalty function: --- 0.5 if both on the x axis and the z axis the same plant growth --- 0.5 if one diagonal neighbor is the same +-- 0.5 if both on the x axis and the z axis at least one of the same plants grows +-- 0.5 if at least one diagonal neighbor is the same -- 1.0 otherwise -local function get_moisture_penalty(pos) +-- we cannot use the names directly, because growth is encoded in the names +local function get_same_crop_penalty(pos) local name = minetest.get_node(pos).name - local n, p = vector.copy(pos), 1 - -- check adjacent points, avoid vector allocations and reduce node accesses + local plant = plant_nodename_to_id[name] + if not plant then return "unregistered plant" end + local n = vector.copy(pos) + -- check adjacent positions, avoid vector allocations and reduce node accesses n.x = pos.x - 1 - local dx = minetest.get_node(n).name == name + local dx = plant_nodename_to_id[minetest.get_node(n).name] == plant n.x = pos.x + 1 - dx = dx or minetest.get_node(n).name == name - if dx then + dx = dx or plant_nodename_to_id[minetest.get_node(n).name] == plant + if dx then -- no need to check z otherwise n.x = pos.x n.z = pos.z - 1 - local dz = minetest.get_node(n).name == name + local dz = plant_nodename_to_id[minetest.get_node(n).name] == plant n.z = pos.z + 1 - dz = dz or minetest.get_node(n).name == name + dz = dz or plant_nodename_to_id[minetest.get_node(n).name] == plant if dz then return 0.5 end end -- check diagonals, clockwise n.x, n.z = pos.x - 1, pos.z - 1 - if minetest.get_node(n).name == name then return 0.5 end + if plant_nodename_to_id[minetest.get_node(n).name] == plant then return 0.5 end n.x = pos.x + 1 - if minetest.get_node(n).name == name then return 0.5 end + if plant_nodename_to_id[minetest.get_node(n).name] == plant then return 0.5 end n.z = pos.z + 1 - if minetest.get_node(n).name == name then return 0.5 end + if plant_nodename_to_id[minetest.get_node(n).name] == plant then return 0.5 end n.x = pos.x - 1 - if minetest.get_node(n).name == name then return 0.5 end + if plant_nodename_to_id[minetest.get_node(n).name] == plant then return 0.5 end return 1 end @@ -92,7 +98,7 @@ function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) plant_info.interval = interval plant_info.chance = chance for _, nodename in pairs(names) do - plant_nodename_to_id_list[nodename] = identifier + plant_nodename_to_id[nodename] = identifier end for i, name in ipairs(names) do plant_step_from_name[name] = i @@ -121,16 +127,15 @@ end function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_water) stages = stages or 1 -- 0 when run from block loading -- check light - if not ignore_light_water and (minetest.get_node_light(pos) or 0) < 0 then return false end + if not ignore_light_water and (minetest.get_node_light(pos, 0.5) or 0) < 0 then return false end -- number of missed interval ticks, for catch-up in block loading local plant_info = plant_lists[identifier] - if plant_info then - stages = stages + floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) - end + if not plant_info then return end + stages = stages + floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) if not ignore_light_water then - local odds = floor(25 / (get_moisture_level(pos) * get_moisture_penalty(pos))) + 1 + local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1 for i = 1,stages do - -- we double the odds, and rather call the ABM less often + -- compared to MC, our ABM runs half as often, hence we use double the chance if random() * odds >= 2 then stages = stages - 1 end end end @@ -307,7 +312,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s interval = grow_interval, chance = grow_chance, action = function(stempos) - local light = minetest.get_node_light(stempos) + local light = minetest.get_node_light(stempos, 0.5) if not light or light < 9 then return end -- Pick one neighbor and check if it can be used to grow local dir = random(1, 4) -- pick direction at random @@ -324,9 +329,9 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s if (floordef.groups.grass_block or 0) == 0 and (floordef.groups.dirt or 0) == 0 and (floordef.groups.soil or 0) < 2 then return end -- not suitable for growing -- check moisture level - local moisture = get_moisture_level(stempos) * get_moisture_penalty(stempos) + local odds = floor(25 / (get_moisture_level(stempos) * get_same_crop_penalty(stempos))) + 1 -- we double the odds, and rather call the ABM less often - if random() * (math.floor(25 / moisture) + 1) >= 2 then return end + if random() * odds >= 2 then return end minetest.swap_node(stempos, { name = connected_stem_names[dir] }) if gourd_def.paramtype2 == "facedir" then @@ -374,13 +379,14 @@ minetest.register_lbm({ nodenames = { "group:plant" }, run_at_every_load = true, action = function(pos, node, dtime_s) - local identifier = plant_nodename_to_id_list[node.name] + local identifier = plant_nodename_to_id[node.name] if not identifier then return end mcl_farming:grow_plant(identifier, pos, node, 0, false) end, }) -- The average light levels were unreliable +-- LBM added in fall 2024 minetest.register_lbm({ label = "Drop legacy average lighting data", name = "mcl_farming:drop_average_light_meta", diff --git a/mods/ITEMS/mcl_farming/soil.lua b/mods/ITEMS/mcl_farming/soil.lua index e91feb1e8..67ea1bd3c 100644 --- a/mods/ITEMS/mcl_farming/soil.lua +++ b/mods/ITEMS/mcl_farming/soil.lua @@ -15,10 +15,6 @@ minetest.register_node("mcl_farming:soil", { {-0.5, -0.5, -0.5, 0.5, 0.4375, 0.5}, } }, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_int("wet", 0) - end, groups = {handy=1,shovely=1, dirtifies_below_solid=1, dirtifier=1, soil=2, soil_sapling=1, deco_block=1 }, sounds = mcl_sounds.node_sound_dirt_defaults(), _mcl_blast_resistance = 0.6, @@ -38,10 +34,6 @@ minetest.register_node("mcl_farming:soil_wet", { {-0.5, -0.5, -0.5, 0.5, 0.4375, 0.5}, } }, - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_int("wet", 7) - end, groups = {handy=1,shovely=1, not_in_creative_inventory=1, dirtifies_below_solid=1, dirtifier=1, soil=3, soil_sapling=1 }, sounds = mcl_sounds.node_sound_dirt_defaults(), _mcl_blast_resistance = 0.6, @@ -51,76 +43,60 @@ minetest.register_node("mcl_farming:soil_wet", { minetest.register_abm({ label = "Farmland hydration", nodenames = {"mcl_farming:soil", "mcl_farming:soil_wet"}, - interval = 15, - chance = 4, + interval = 2.73, + chance = 25, action = function(pos, node) - -- Get wetness value - local meta = minetest.get_meta(pos) - local wet = meta:get_int("wet") - if not wet then - if node.name == "mcl_farming:soil" then - wet = 0 - else - wet = 7 - end - end - -- Turn back into dirt when covered by solid node - local above_node = minetest.get_node_or_nil({x=pos.x,y=pos.y+1,z=pos.z}) - if above_node then - if minetest.get_item_group(above_node.name, "solid") ~= 0 then - node.name = "mcl_core:dirt" - minetest.set_node(pos, node) - return - end + local above_node = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0)) + if above_node and minetest.get_item_group(above_node.name, "solid") ~= 0 then + node.name = "mcl_core:dirt" + minetest.set_node(pos, node) -- also removes "wet" metadata + return end - -- Check an area of 9×2×9 around the node for nodename (9×9 on same level and 9×9 below) - local function check_surroundings(pos, nodename) - local nodes = minetest.find_nodes_in_area({x=pos.x-4,y=pos.y,z=pos.z-4}, {x=pos.x+4,y=pos.y+1,z=pos.z+4}, {nodename}) - return #nodes > 0 + local raining = mcl_weather and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) + local has_water, fully_loaded = false, true + if not raining then + -- Check an area of 9×2×9 around the node for nodename (9×9 on same level and 9×9 above) + -- include "ignore" to detect unloaded blocks + local nodes, counts = minetest.find_nodes_in_area(vector.offset(pos, -4, 0, -4), vector.offset(pos, 4, 1, 4), {"group:water", "ignore"}) + local ignore = counts.ignore or 0 + has_water, fully_loaded = #nodes - ignore > 0, ignore == 0 end - if check_surroundings(pos, "group:water") then - if node.name ~= "mcl_farming:soil_wet" then - -- Make it wet + local meta = minetest.get_meta(pos) + local wet = meta:get_int("wet") or (node.name == "mcl_farming:soil" and 0 or 7) + -- Hydrate by rain or water + if raining or has_water then + if node.name == "mcl_farming:soil" then node.name = "mcl_farming:soil_wet" + minetest.set_node(pos, node) -- resets wetness + meta:set_int("wet", 7) + elseif wet < 7 then + meta:set_int("wet", 7) + end + return + end + -- No decay near unloaded areas (ignore) since these might include water. + if not fully_loaded then return end + + -- Decay: make farmland dry or turn back to dirt + if wet > 1 then + if node.name == "mcl_farming:soil_wet" then -- change visual appearance to dry + node.name = "mcl_farming:soil" minetest.set_node(pos, node) end - else -- No water nearby. - -- The decay branch (make farmland dry or turn back to dirt) - - -- Don't decay while it's raining - if mcl_weather.rain.raining then - if mcl_weather.is_outdoor(pos) then - return - end - end - -- No decay near unloaded areas since these might include water. - if not check_surroundings(pos, "ignore") then - if wet <= 0 then - --local n_def = minetest.registered_nodes[node.name] or nil - local nn = minetest.get_node_or_nil({x=pos.x,y=pos.y+1,z=pos.z}) - if not nn or not nn.name then - return - end - local nn_def = minetest.registered_nodes[nn.name] or nil - - if nn_def and minetest.get_item_group(nn.name, "plant") == 0 then - node.name = "mcl_core:dirt" - minetest.set_node(pos, node) - return - end - else - if wet == 7 then - node.name = "mcl_farming:soil" - minetest.swap_node(pos, node) - end - -- Slowly count down wetness - meta:set_int("wet", wet-1) - end - end + meta:set_int("wet", wet - 1) + return end + -- 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_def = nn and minetest.registered_nodes[nn.name] or nil + if nn_def and (nn_def.groups.plant or 0) > 0 then + return + end + node.name = "mcl_core:dirt" + minetest.set_node(pos, node) -- also removes "wet" metadata end, }) From 220a7b06e67506313e3c004a17fce00fb0fbfc68 Mon Sep 17 00:00:00 2001 From: kno10 Date: Tue, 15 Oct 2024 10:18:22 +0200 Subject: [PATCH 15/93] code review feedback --- mods/ITEMS/mcl_farming/shared_functions.lua | 9 +++++---- mods/ITEMS/mcl_farming/soil.lua | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 94450acbd..f7d5c9584 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -45,7 +45,7 @@ local function get_moisture_level(pos) local ndef = minetest.registered_nodes[minetest.get_node(n).name] local soil = ndef and ndef.groups.soil 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 if x ~= 0 and z ~= 0 then m = m * 0.25 end totalm = totalm + m @@ -63,7 +63,7 @@ end local function get_same_crop_penalty(pos) local name = minetest.get_node(pos).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) -- check adjacent positions, avoid vector allocations and reduce node accesses 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 local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1 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 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 minetest.set_node(pos, { 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 end diff --git a/mods/ITEMS/mcl_farming/soil.lua b/mods/ITEMS/mcl_farming/soil.lua index 67ea1bd3c..d943a7000 100644 --- a/mods/ITEMS/mcl_farming/soil.lua +++ b/mods/ITEMS/mcl_farming/soil.lua @@ -91,10 +91,8 @@ minetest.register_abm({ end -- 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_def = nn and minetest.registered_nodes[nn.name] or nil - if nn_def and (nn_def.groups.plant or 0) > 0 then - return - end + local nn_def = nn and minetest.registered_nodes[nn.name] + if nn_def and (nn_def.groups.plant or 0) > 0 then return end node.name = "mcl_core:dirt" minetest.set_node(pos, node) -- also removes "wet" metadata end, From c097c652626ba466a2e062e0fc1dafecc55e8be4 Mon Sep 17 00:00:00 2001 From: kno10 Date: Wed, 16 Oct 2024 00:00:05 +0200 Subject: [PATCH 16/93] adjust growth rates again --- mods/ITEMS/mcl_farming/beetroot.lua | 4 ++-- mods/ITEMS/mcl_farming/carrots.lua | 2 +- mods/ITEMS/mcl_farming/melon.lua | 4 ++-- mods/ITEMS/mcl_farming/potatoes.lua | 2 +- mods/ITEMS/mcl_farming/pumpkin.lua | 4 ++-- mods/ITEMS/mcl_farming/sweet_berry.lua | 4 ++-- mods/ITEMS/mcl_farming/wheat.lua | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 904274b8e..4c77f3dad 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -171,8 +171,8 @@ minetest.register_craft({ }, }) --- beetroots grow 1/3rd of the default speed -mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 16.2012, 25) +-- beetroots grow at 2/3rd of the default speed +mcl_farming:add_plant("plant_beetroot", "mcl_farming:beetroot", {"mcl_farming:beetroot_0", "mcl_farming:beetroot_1", "mcl_farming:beetroot_2"}, 8.7012, 35) if minetest.get_modpath("doc") then for i = 1, 2 do diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index 580e4da5a..6f7d7a6aa 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -118,7 +118,7 @@ minetest.register_craft({ } }) -mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 5.4013, 25) +mcl_farming:add_plant("plant_carrot", "mcl_farming:carrot", {"mcl_farming:carrot_1", "mcl_farming:carrot_2", "mcl_farming:carrot_3", "mcl_farming:carrot_4", "mcl_farming:carrot_5", "mcl_farming:carrot_6", "mcl_farming:carrot_7"}, 5.8013, 35) if minetest.get_modpath("doc") then for i=2,7 do diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index 74c95e686..205150b6e 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -123,10 +123,10 @@ local stem_def = { } -- Register stem growth -mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 5.4014, 25) +mcl_farming:add_plant("plant_melon_stem", "mcl_farming:melontige_unconnect", {"mcl_farming:melontige_1", "mcl_farming:melontige_2", "mcl_farming:melontige_3", "mcl_farming:melontige_4", "mcl_farming:melontige_5", "mcl_farming:melontige_6", "mcl_farming:melontige_7"}, 5.8014, 35) -- Register actual melon, connected stems and stem-to-melon growth -mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 5.4015, 25, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:melontige_unconnect", "mcl_farming:melontige_linked", "mcl_farming:melontige_unconnect", stem_def, stem_drop, "mcl_farming:melon", melon_base_def, 5.8015, 35, "mcl_farming_melon_stem_connected.png^[colorize:#FFA800:127") -- Items and crafting minetest.register_craftitem("mcl_farming:melon_item", { diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index 455befa7d..2dc4a3522 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -135,7 +135,7 @@ minetest.register_craft({ cooktime = 10, }) -mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 5.4016, 25) +mcl_farming:add_plant("plant_potato", "mcl_farming:potato", {"mcl_farming:potato_1", "mcl_farming:potato_2", "mcl_farming:potato_3", "mcl_farming:potato_4", "mcl_farming:potato_5", "mcl_farming:potato_6", "mcl_farming:potato_7"}, 5.8016, 35) minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index e06ce7774..1befef8a8 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -180,10 +180,10 @@ if minetest.get_modpath("mcl_armor") then end -- Register stem growth -mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 5.4017, 25) +mcl_farming:add_plant("plant_pumpkin_stem", "mcl_farming:pumpkintige_unconnect", {"mcl_farming:pumpkin_1", "mcl_farming:pumpkin_2", "mcl_farming:pumpkin_3", "mcl_farming:pumpkin_4", "mcl_farming:pumpkin_5", "mcl_farming:pumpkin_6", "mcl_farming:pumpkin_7"}, 5.8017, 35) -- Register actual pumpkin, connected stems and stem-to-pumpkin growth -mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 5.4018, 25, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") +mcl_farming:add_gourd("mcl_farming:pumpkintige_unconnect", "mcl_farming:pumpkintige_linked", "mcl_farming:pumpkintige_unconnect", stem_def, stem_drop, "mcl_farming:pumpkin", pumpkin_base_def, 5.8018, 35, "mcl_farming_pumpkin_stem_connected.png^[colorize:#FFA800:127") -- Steal function to properly disconnect a carved pumpkin pumpkin_face_base_def.after_destruct = minetest.registered_nodes["mcl_farming:pumpkin"].after_destruct diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 7f565e97b..a03eee012 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -99,8 +99,8 @@ minetest.register_craftitem("mcl_farming:sweet_berry", { }) minetest.register_alias("mcl_sweet_berry:sweet_berry", "mcl_farming:sweet_berry") --- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages, 1/3rd of the default. -mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 16.2019, 25) +-- TODO: Find proper interval and chance values for sweet berry bushes. Current interval and chance values are copied from mcl_farming:beetroot which has similar growth stages, 2/3rd of the default. +mcl_farming:add_plant("plant_sweet_berry_bush", "mcl_farming:sweet_berry_bush_3", {"mcl_farming:sweet_berry_bush_0", "mcl_farming:sweet_berry_bush_1", "mcl_farming:sweet_berry_bush_2"}, 8.7019, 35) local function berry_damage_check(obj) local p = obj:get_pos() diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index b68ac4ce4..4ddbb156a 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -99,7 +99,7 @@ minetest.register_node("mcl_farming:wheat", { } }) -mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 5.4020, 25) +mcl_farming:add_plant("plant_wheat", "mcl_farming:wheat", {"mcl_farming:wheat_1", "mcl_farming:wheat_2", "mcl_farming:wheat_3", "mcl_farming:wheat_4", "mcl_farming:wheat_5", "mcl_farming:wheat_6", "mcl_farming:wheat_7"}, 5.8020, 35) minetest.register_craftitem("mcl_farming:wheat_item", { description = S("Wheat"), From fa7a7f4e8159ba2bac9109ce19b4d94f06f4a671 Mon Sep 17 00:00:00 2001 From: kno10 Date: Wed, 16 Oct 2024 00:24:07 +0200 Subject: [PATCH 17/93] more fixes to plant growth --- mods/ITEMS/mcl_farming/shared_functions.lua | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index f7d5c9584..61a0df2f2 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -15,14 +15,13 @@ local plant_step_from_name = {} -- map nodes to growth steps local growth_factor = tonumber(minetest.settings:get("vl_plant_growth")) or 1.0 +-- note: does not support /set time_speed! local time_speed = tonumber(minetest.settings:get("time_speed")) or 72 local time_multiplier = time_speed > 0 and (86400 / time_speed) or 0 local function get_intervals_counter(pos, interval, chance) - if time_multiplier == 0 then return 0 end - -- "wall clock time", so plants continue to grow while sleeping + -- in-game days, so plants continue to grow while sleeping, and we try to catch up local current_game_time = (minetest.get_day_count() + minetest.get_timeofday()) * time_multiplier - local meta = minetest.get_meta(pos) local last_game_time = meta:get_float("last_gametime") meta:set_float("last_gametime", current_game_time) @@ -33,8 +32,8 @@ end -- wetness of the surroundings -- dry farmland = 1 point -- wet farmland = 3 points --- diagonal neighbors only 25% --- center point gives + 1 point +-- center point gives + 1 point, so 2 resp. 4 +-- neighbors only 25% local function get_moisture_level(pos) local n = vector.offset(pos, 0, -1, 0) local totalm = 1 @@ -47,7 +46,7 @@ local function get_moisture_level(pos) if soil and soil >= 2 then local m = (soil > 2 or (soil == 2 and minetest.get_meta(n):get_int("wet") > 0)) and 3 or 1 -- corners have less weight - if x ~= 0 and z ~= 0 then m = m * 0.25 end + if x ~= 0 or z ~= 0 then m = m * 0.25 end totalm = totalm + m end end @@ -63,7 +62,7 @@ end local function get_same_crop_penalty(pos) local name = minetest.get_node(pos).name local plant = plant_nodename_to_id[name] - if not plant then return end + if not plant then return 1 end local n = vector.copy(pos) -- check adjacent positions, avoid vector allocations and reduce node accesses n.x = pos.x - 1 @@ -97,6 +96,7 @@ function mcl_farming:add_plant(identifier, full_grown, names, interval, chance) plant_info.names = names plant_info.interval = interval plant_info.chance = chance + plant_nodename_to_id[full_grown] = identifier for _, nodename in pairs(names) do plant_nodename_to_id[nodename] = identifier end @@ -131,12 +131,12 @@ function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_wate -- number of missed interval ticks, for catch-up in block loading local plant_info = plant_lists[identifier] if not plant_info then return end - stages = stages + floor(get_intervals_counter(pos, plant_info.interval, plant_info.chance)) + stages = floor(stages + get_intervals_counter(pos, plant_info.interval, plant_info.chance) - 0.45) if not ignore_light_water then local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1 for i = 1,stages do - -- 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 + -- compared to info from the MC wiki, our ABM runs a third as often, hence we use triple the chance + if random() * odds >= 3 then stages = stages - 1 end end end @@ -237,6 +237,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s stem_def.groups = stem_def.groups or { dig_immediate = 3, not_in_creative_inventory = 1, plant = 1, attached_node = 1, dig_by_water = 1, destroy_by_lava_flow = 1 } stem_def.sounds = stem_def.sounds or mcl_sounds.node_sound_leaves_defaults() minetest.register_node(stem_itemstring, stem_def) + plant_nodename_to_id[stem_itemstring] = stem_itemstring -- Register connected stems @@ -299,6 +300,7 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, }) + plant_nodename_to_id[connected_stem_names[i]] = stem_itemstring if minetest.get_modpath("doc") then doc.add_entry_alias("nodes", full_unconnected_stem, "nodes", connected_stem_names[i]) @@ -331,8 +333,8 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s -- check moisture level local odds = floor(25 / (get_moisture_level(stempos) * get_same_crop_penalty(stempos))) + 1 - -- we double the odds, and rather call the ABM less often - if random() * odds >= 2 then return end + -- we triple the odds, and rather call the ABM less often + if random() * odds >= 3 then return end minetest.swap_node(stempos, { name = connected_stem_names[dir] }) if gourd_def.paramtype2 == "facedir" then From a8318f66006a053064cbb6e7370d518dc414e679 Mon Sep 17 00:00:00 2001 From: kno10 Date: Wed, 16 Oct 2024 21:19:38 +0200 Subject: [PATCH 18/93] simplify catch-up LBM logic --- mods/ITEMS/mcl_farming/shared_functions.lua | 47 ++++++--------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 61a0df2f2..a33e414ed 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -15,20 +15,6 @@ local plant_step_from_name = {} -- map nodes to growth steps local growth_factor = tonumber(minetest.settings:get("vl_plant_growth")) or 1.0 --- note: does not support /set time_speed! -local time_speed = tonumber(minetest.settings:get("time_speed")) or 72 -local time_multiplier = time_speed > 0 and (86400 / time_speed) or 0 - -local function get_intervals_counter(pos, interval, chance) - -- in-game days, so plants continue to grow while sleeping, and we try to catch up - local current_game_time = (minetest.get_day_count() + minetest.get_timeofday()) * time_multiplier - local meta = minetest.get_meta(pos) - local last_game_time = meta:get_float("last_gametime") - meta:set_float("last_gametime", current_game_time) - if last_game_time < 1 then return 0 end - return (current_game_time - last_game_time) / (interval * chance) -end - -- wetness of the surroundings -- dry farmland = 1 point -- wet farmland = 3 points @@ -125,14 +111,11 @@ end -- Returns true if plant has been grown by 1 or more stages. -- Returns false if nothing changed. function mcl_farming:grow_plant(identifier, pos, node, stages, ignore_light_water) - stages = stages or 1 -- 0 when run from block loading - -- check light - if not ignore_light_water and (minetest.get_node_light(pos, 0.5) or 0) < 0 then return false end -- number of missed interval ticks, for catch-up in block loading local plant_info = plant_lists[identifier] if not plant_info then return end - stages = floor(stages + get_intervals_counter(pos, plant_info.interval, plant_info.chance) - 0.45) if not ignore_light_water then + if (minetest.get_node_light(pos, 0.5) or 0) < 0 then return false end -- day light local odds = floor(25 / (get_moisture_level(pos) * get_same_crop_penalty(pos))) + 1 for i = 1,stages do -- compared to info from the MC wiki, our ABM runs a third as often, hence we use triple the chance @@ -384,21 +367,19 @@ minetest.register_lbm({ action = function(pos, node, dtime_s) local identifier = plant_nodename_to_id[node.name] if not identifier then return end - mcl_farming:grow_plant(identifier, pos, node, 0, false) - end, -}) - --- The average light levels were unreliable --- LBM added in fall 2024 -minetest.register_lbm({ - label = "Drop legacy average lighting data", - name = "mcl_farming:drop_average_light_meta", - nodenames = { "group:plant" }, - run_at_every_load = false, -- only convert once - action = function(pos, node, dtime_s) - local meta = minetest.get_meta(pos) - meta:set_string("avg_light_summary", "") -- drop - meta:set_string("avg_light_count", "") -- drop + + local plant_info = plant_lists[identifier] + if not plant_info then return end + local rolls = floor(dtime_s / plant_info.interval) + if rolls <= 0 then return end + -- simulate how often the block will be ticked + local stages = 0 + for i = 1,rolls do + if random(1, plant_info.chance) == 1 then stages = stages + 1 end + end + if stages > 0 then + mcl_farming:grow_plant(identifier, pos, node, stages, false) + end end, }) From ebf6cf32e89fe1d402e1859a81c4f361153beb27 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sat, 2 Nov 2024 21:05:57 +0100 Subject: [PATCH 19/93] meta:set_private("wet"), require only walkable nodes --- mods/ITEMS/mcl_farming/shared_functions.lua | 5 ++--- mods/ITEMS/mcl_farming/soil.lua | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index a33e414ed..6ebf659ca 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -307,12 +307,11 @@ function mcl_farming:add_gourd(full_unconnected_stem, connected_stem_basename, s or (dir == 3 and vector.offset(stempos, 0, 0, 1)) or vector.offset(stempos, 0, 0, -1) if minetest.get_node(neighbor).name ~= "air" then return end -- occupied - -- check for suitable floor: grass, dirt, or soil + -- check for suitable floor -- in contrast to MC, we think everything solid is fine local floorpos = vector.offset(neighbor, 0, -1, 0) local floorname = minetest.get_node(floorpos).name local floordef = minetest.registered_nodes[floorname] - if not floordef then return end - if (floordef.groups.grass_block or 0) == 0 and (floordef.groups.dirt or 0) == 0 and (floordef.groups.soil or 0) < 2 then return end -- not suitable for growing + if not floordef or not floordef.walkable then return end -- check moisture level local odds = floor(25 / (get_moisture_level(stempos) * get_same_crop_penalty(stempos))) + 1 diff --git a/mods/ITEMS/mcl_farming/soil.lua b/mods/ITEMS/mcl_farming/soil.lua index d943a7000..32f624c3c 100644 --- a/mods/ITEMS/mcl_farming/soil.lua +++ b/mods/ITEMS/mcl_farming/soil.lua @@ -72,6 +72,7 @@ minetest.register_abm({ node.name = "mcl_farming:soil_wet" minetest.set_node(pos, node) -- resets wetness meta:set_int("wet", 7) + meta:mark_as_private("wet") elseif wet < 7 then meta:set_int("wet", 7) end @@ -85,8 +86,11 @@ minetest.register_abm({ if node.name == "mcl_farming:soil_wet" then -- change visual appearance to dry node.name = "mcl_farming:soil" minetest.set_node(pos, node) + meta:set_int("wet", wet - 1) + meta:mark_as_private("wet") -- after set_int + else + meta:set_int("wet", wet - 1) end - meta:set_int("wet", wet - 1) return end -- Revert to dirt if wetness is 0, and no plant above From b5afa34469673766dd11969e9fada9494326b0dc Mon Sep 17 00:00:00 2001 From: kno10 Date: Sat, 2 Nov 2024 23:41:38 +0100 Subject: [PATCH 20/93] Remove "wet" metadata altogether --- mods/ITEMS/mcl_farming/shared_functions.lua | 2 +- mods/ITEMS/mcl_farming/soil.lua | 63 +++++++++------------ 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/mods/ITEMS/mcl_farming/shared_functions.lua b/mods/ITEMS/mcl_farming/shared_functions.lua index 6ebf659ca..2cf5514a2 100644 --- a/mods/ITEMS/mcl_farming/shared_functions.lua +++ b/mods/ITEMS/mcl_farming/shared_functions.lua @@ -30,7 +30,7 @@ local function get_moisture_level(pos) local ndef = minetest.registered_nodes[minetest.get_node(n).name] local soil = ndef and ndef.groups.soil if soil and soil >= 2 then - local m = (soil > 2 or (soil == 2 and minetest.get_meta(n):get_int("wet") > 0)) and 3 or 1 + local m = soil > 2 and 3 or 1 -- corners have less weight if x ~= 0 or z ~= 0 then m = m * 0.25 end totalm = totalm + m diff --git a/mods/ITEMS/mcl_farming/soil.lua b/mods/ITEMS/mcl_farming/soil.lua index 32f624c3c..6196f5286 100644 --- a/mods/ITEMS/mcl_farming/soil.lua +++ b/mods/ITEMS/mcl_farming/soil.lua @@ -50,55 +50,48 @@ minetest.register_abm({ local above_node = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0)) if above_node and minetest.get_item_group(above_node.name, "solid") ~= 0 then node.name = "mcl_core:dirt" - minetest.set_node(pos, node) -- also removes "wet" metadata + minetest.set_node(pos, node) return end - local raining = mcl_weather and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) - local has_water, fully_loaded = false, true - if not raining then - -- Check an area of 9×2×9 around the node for nodename (9×9 on same level and 9×9 above) - -- include "ignore" to detect unloaded blocks - local nodes, counts = minetest.find_nodes_in_area(vector.offset(pos, -4, 0, -4), vector.offset(pos, 4, 1, 4), {"group:water", "ignore"}) - local ignore = counts.ignore or 0 - has_water, fully_loaded = #nodes - ignore > 0, ignore == 0 - end - - local meta = minetest.get_meta(pos) - local wet = meta:get_int("wet") or (node.name == "mcl_farming:soil" and 0 or 7) - -- Hydrate by rain or water - if raining or has_water then + -- in rain, become wet, do not decay + if mcl_weather and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then if node.name == "mcl_farming:soil" then node.name = "mcl_farming:soil_wet" - minetest.set_node(pos, node) -- resets wetness - meta:set_int("wet", 7) - meta:mark_as_private("wet") - elseif wet < 7 then - meta:set_int("wet", 7) + minetest.set_node(pos, node) + end + return + end + + -- Check an area of 9x2x9 around the node for nodename (9x9 on same level and 9x9 above) + -- include "ignore" to detect unloaded blocks + local nodes, counts = minetest.find_nodes_in_area(vector.offset(pos, -4, 0, -4), vector.offset(pos, 4, 1, 4), {"group:water", "ignore"}) + local ignore = counts.ignore or 0 + local has_water, fully_loaded = #nodes > ignore, ignore == 0 + + -- Hydrate by rain or water, do not decay + if has_water then + if node.name == "mcl_farming:soil" then + node.name = "mcl_farming:soil_wet" + minetest.set_node(pos, node) end return end -- No decay near unloaded areas (ignore) since these might include water. if not fully_loaded then return end - -- Decay: make farmland dry or turn back to dirt - if wet > 1 then - if node.name == "mcl_farming:soil_wet" then -- change visual appearance to dry - node.name = "mcl_farming:soil" - minetest.set_node(pos, node) - meta:set_int("wet", wet - 1) - meta:mark_as_private("wet") -- after set_int - else - meta:set_int("wet", wet - 1) - end + -- Decay: make wet farmland dry up + if node.name == "mcl_farming:soil_wet" then + node.name = "mcl_farming:soil" + minetest.set_node(pos, node) return end -- 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_def = nn and minetest.registered_nodes[nn.name] - if nn_def and (nn_def.groups.plant or 0) > 0 then return end - node.name = "mcl_core:dirt" - minetest.set_node(pos, node) -- also removes "wet" metadata + local above = minetest.get_node_or_nil(vector.offset(pos, 0, 1, 0)) + if minetest.get_item_group(above.name, "plant") == 0 then + node.name = "mcl_core:dirt" + minetest.set_node(pos, node) + end end, }) From d49426d453ae9ce1f21f9ba0cca66fdcbb50d234 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 10 Nov 2024 02:32:51 +0100 Subject: [PATCH 21/93] Cleanup of mcl_core/functions (#4592) Cleanup of mods/ITEMS/mcl_core/functions.lua This improves several further ABMs such as vine growing, and uses the `vector` API instead of tables. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4592 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/ITEMS/mcl_core/functions.lua | 931 ++++++++++++------------------ 1 file changed, 375 insertions(+), 556 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 596a9c875..399b2d15c 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -1,13 +1,20 @@ --- --- Lava vs water interactions --- - local modpath = minetest.get_modpath(minetest.get_current_modname()) - local mg_name = minetest.get_mapgen_setting("mg_name") -local math = math -local vector = vector +local random = math.random +local sqrt = math.sqrt +local floor = math.floor +local ceil = math.ceil +local abs = math.abs +local max = math.max + +local vector_new = vector.new +local vector_zero = vector.zero +local vector_offset = vector.offset +local vector_copy = vector.copy +local vector_add = vector.add +local vector_subtract = vector.subtract +local vector_distance = vector.distance local OAK_TREE_ID = 1 local DARK_OAK_TREE_ID = 2 @@ -24,7 +31,7 @@ minetest.register_abm({ chance = 1, min_y = mcl_vars.mg_end_min, action = function(pos, node, active_object_count, active_object_count_wider) - local water = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+1, z=pos.z+1}, "group:water") + local water = minetest.find_nodes_in_area(vector_offset(pos, -1, -1, -1), vector_offset(pos, 1, 1, 1), "group:water") local lavatype = minetest.registered_nodes[node.name].liquidtype @@ -100,18 +107,11 @@ end local function drop_attached_node(p) local nn = minetest.get_node(p).name - if nn == "air" or nn == "ignore" then - return - end + if nn == "air" or nn == "ignore" then return end minetest.remove_node(p) for _, item in pairs(minetest.get_node_drops(nn, "")) do - local pos = { - x = p.x + math.random()/2 - 0.25, - y = p.y + math.random()/2 - 0.25, - z = p.z + math.random()/2 - 0.25, - } if item ~= "" then - minetest.add_item(pos, item) + minetest.add_item(vector_offset(p, random() * 0.5 - 0.25, random() * 0.5 - 0.25, random() * 0.5 - 0.25), item) end end end @@ -119,36 +119,25 @@ end -- Helper function for node actions for liquid flow local function liquid_flow_action(pos, group, action) local function check_detach(pos, xp, yp, zp) - local p = {x=pos.x+xp, y=pos.y+yp, z=pos.z+zp} - local n = minetest.get_node_or_nil(p) - if not n then - return false - end - local d = minetest.registered_nodes[n.name] - if not d then - return false - end + local n = minetest.get_node_or_nil(vector_offset(pos, xp, yp, zp)) + local d = n and minetest.registered_nodes[n.name] + if not d then return false end --[[ Check if we want to perform the liquid action. * 1: Item must be in liquid group * 2a: If target node is below liquid, always succeed * 2b: If target node is horizontal to liquid: succeed if source, otherwise check param2 for horizontal flow direction ]] local range = d.liquid_range or 8 - if (minetest.get_item_group(n.name, group) ~= 0) and - ((yp > 0) or - (yp == 0 and ((d.liquidtype == "source") or (n.param2 > (8-range) and n.param2 < 9)))) then + if minetest.get_item_group(n.name, group) ~= 0 and + (yp > 0 or + (yp == 0 and (d.liquidtype == "source" or (n.param2 > 8-range and n.param2 < 9)))) then action(pos) end end - local posses = { - { x=-1, y=0, z=0 }, - { x=1, y=0, z=0 }, - { x=0, y=0, z=-1 }, - { x=0, y=0, z=1 }, - { x=0, y=1, z=0 }, - } - for p=1,#posses do - check_detach(pos, posses[p].x, posses[p].y, posses[p].z) - end + check_detach(pos, -1, 0, 0) + check_detach(pos, 1, 0, 0) + check_detach(pos, 0, 0, -1) + check_detach(pos, 0, 0, 1) + check_detach(pos, 0, 1, 0) end -- Drop some nodes next to flowing water, if it would flow into the node @@ -208,21 +197,21 @@ minetest.register_abm({ object:remove() end end - if is_walkable(vector.offset(pos, 1, 0, 0)) - or is_walkable(vector.offset(pos, -1, 0, 0)) - or is_walkable(vector.offset(pos, 0, 0, 1)) - or is_walkable(vector.offset(pos, 0, 0, -1)) then - local lpos = vector.copy(pos) + if is_walkable(vector_offset(pos, 1, 0, 0)) + or is_walkable(vector_offset(pos, -1, 0, 0)) + or is_walkable(vector_offset(pos, 0, 0, 1)) + or is_walkable(vector_offset(pos, 0, 0, -1)) then + local lpos = vector_copy(pos) local dx, dy while true do local node = minetest.get_node(lpos) if not node or node.name ~= "mcl_core:cactus" then break end -- minetest.dig_node ignores protected nodes and causes infinite drop (#4628) minetest.remove_node(lpos) - dx = dx or ((math.random(0,1)-0.5) * math.sqrt(math.random())) * 1.5 - dy = dy or ((math.random(0,1)-0.5) * math.sqrt(math.random())) * 1.5 - local obj = minetest.add_item(vector.offset(lpos, dx, 0.25, dy), "mcl_core:cactus") - obj:set_velocity(vector.new(dx, 1, dy)) + dx = dx or ((random(0,1)-0.5) * sqrt(random())) * 1.5 + dy = dy or ((random(0,1)-0.5) * sqrt(random())) * 1.5 + local obj = minetest.add_item(vector_offset(lpos, dx, 0.25, dy), "mcl_core:cactus") + obj:set_velocity(vector_new(dx, 1, dy)) lpos.y = lpos.y + 1 end end @@ -242,52 +231,25 @@ minetest.register_abm({ -- -- Sugar canes drop -- - -local timber_nodenames={"mcl_core:reeds"} - minetest.register_on_dignode(function(pos, node) - local i=1 - while timber_nodenames[i]~=nil do - local np={x=pos.x, y=pos.y+1, z=pos.z} - while minetest.get_node(np).name==timber_nodenames[i] do - minetest.remove_node(np) - minetest.add_item(np, timber_nodenames[i]) - np={x=np.x, y=np.y+1, z=np.z} - end - i=i+1 + local name = "mcl_core:reeds" + local np = vector_offset(pos, 0, 1, 0) + while minetest.get_node(np).name == name do + minetest.remove_node(np) + minetest.add_item(np, name) + np.y = np.y + 1 end end) -local function air_leaf(leaftype) - if math.random(0, 50) == 3 then - return {name = "air"} - else - return {name = leaftype} - end -end - --- Check if a node stops a tree from growing. Torches, plants, wood, tree, +-- Check if a node stops a tree from growing. Torches, plants, wood, tree, -- leaves and dirt does not affect tree growth. local function node_stops_growth(node) - if node.name == "air" then - return false - end - + if node.name == "air" then return false end local def = minetest.registered_nodes[node.name] - if not def then - return true - end + local groups = def and def.groups + if not groups then return true end - local groups = def.groups - if not groups then - return true - end - if groups.plant or groups.torch or groups.dirt or groups.tree - or groups.bark or groups.leaves or groups.wood then - return false - end - - return true + return not (groups.leaves or groups.wood or groups.tree or groups.plant or groups.dirt or groups.torch or groups.bark) end -- Check if a tree can grow at position. The width is the width to check @@ -297,16 +259,11 @@ end local function check_growth_width(pos, width, height) -- Huge tree (with even width to check) will check one more node in -- positive x and y directions. - local neg_space = math.min((width - 1) / 2) - local pos_space = math.max((width - 1) / 2) + local neg_space, pos_space = floor((width - 1) * 0.5), ceil((width - 1) * 0.5) for x = -neg_space, pos_space do for z = -neg_space, pos_space do for y = 1, height do - local np = vector.new( - pos.x + x, - pos.y + y, - pos.z + z) - if node_stops_growth(minetest.get_node(np)) then + if node_stops_growth(minetest.get_node(vector_offset(pos, x, y, z))) then return false end end @@ -358,13 +315,7 @@ end -- generate huge trees. The 'balloon' option is used by oak to generate a balloon -- oak tree. function mcl_core.generate_tree(pos, tree_type, options) - pos.y = pos.y-1 - --local nodename = minetest.get_node(pos).name - - pos.y = pos.y+1 - if not minetest.get_node_light(pos) then - return - end + if not minetest.get_node_light(pos) then return end local two_by_two = options and options.two_by_two local balloon = options and options.balloon @@ -410,65 +361,36 @@ function mcl_core.generate_tree(pos, tree_type, options) end -- Classic oak in v6 style -function mcl_core.generate_v6_oak_tree(pos) - local trunk = "mcl_core:tree" - local leaves = "mcl_core:leaves" - local node - for dy=1,4 do - pos.y = pos.y+dy - if minetest.get_node(pos).name ~= "air" then - return - end - pos.y = pos.y-dy +function mcl_core.generate_v6_oak_tree(p) + local pos = vector_copy(p) + for dy = 0, 4 do + pos.y = p.y + dy + if minetest.get_node(pos).name ~= "air" then return end end - node = {name = trunk} - for dy=0,4 do - pos.y = pos.y+dy - if minetest.get_node(pos).name == "air" then - minetest.add_node(pos, node) - end - pos.y = pos.y-dy + local trunk = {name = "mcl_core:tree" } + for dy = 0, 4 do + pos.y = p.y + dy + minetest.add_node(pos, trunk) end - node = {name = leaves} - pos.y = pos.y+3 - --[[local rarity = 0 - if math.random(0, 10) == 3 then - rarity = 1 - end]] - for dx=-2,2 do - for dz=-2,2 do - for dy=0,3 do - pos.x = pos.x+dx - pos.y = pos.y+dy - pos.z = pos.z+dz - - if dx == 0 and dz == 0 and dy==3 then - if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.add_node(pos, node) - minetest.add_node(pos, air_leaf(leaves)) + local leaves = { name = "mcl_core:leaves" } + for dx = -2, 2 do + for dz = -2, 2 do + for dy = 3, 6 do + pos.x, pos.y, pos.z = p.x + dx, p.y + dy, p.z + dz + if dy == 6 then + if dx == 0 and dz == 0 and minetest.get_node(pos).name == "air" and random(1, 5) <= 4 then + minetest.add_node(pos, leaves) end - elseif dx == 0 and dz == 0 and dy==4 then - if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.add_node(pos, node) - minetest.add_node(pos, air_leaf(leaves)) - end - elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then + elseif abs(dx) ~= 2 and abs(dz) ~= 2 then if minetest.get_node(pos).name == "air" then - minetest.add_node(pos, node) - minetest.add_node(pos, air_leaf(leaves)) + minetest.add_node(pos, leaves) end - else - if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then - if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.add_node(pos, node) - minetest.add_node(pos, air_leaf(leaves)) - end + elseif abs(dx) ~= 2 or abs(dz) ~= 2 then + if minetest.get_node(pos).name == "air" and random(1, 5) <= 4 then + minetest.add_node(pos, leaves) end end - pos.x = pos.x-dx - pos.y = pos.y-dy - pos.z = pos.z-dz end end end @@ -476,39 +398,32 @@ end -- Ballon Oak function mcl_core.generate_balloon_oak_tree(pos) - local path - local offset - local s = math.random(1, 12) - if s == 1 then + if random(1, 12) == 1 then -- Small balloon oak - path = modpath .. "/schematics/mcl_core_oak_balloon.mts" - offset = { x = -2, y = -1, z = -2 } - else - -- Large balloon oak - local t = math.random(1, 4) - path = modpath .. "/schematics/mcl_core_oak_large_"..t..".mts" - if t == 1 or t == 3 then - offset = { x = -3, y = -1, z = -3 } - elseif t == 2 or t == 4 then - offset = { x = -4, y = -1, z = -4 } - end + minetest.place_schematic(vector_offset(pos, -2, -1, -2), + modpath .. "/schematics/mcl_core_oak_balloon.mts", + "random", nil, false) + return + end + -- Large balloon oak + local t = random(1, 4) + local path = modpath .. "/schematics/mcl_core_oak_large_"..t..".mts" + if t == 1 or t == 3 then + minetest.place_schematic(vector_offset(pos, -3, -1, -3), path, "random", nil, false) + elseif t == 2 or t == 4 then + minetest.place_schematic(vector_offset(pos, -4, -1, -4), path, "random", nil, false) end - minetest.place_schematic(vector.add(pos, offset), path, "random", nil, false) end -- Oak local path_oak_tree = modpath.."/schematics/mcl_core_oak_classic.mts" - function mcl_core.generate_oak_tree(pos) - local offset = { x = -2, y = -1, z = -2 } - minetest.place_schematic(vector.add(pos, offset), path_oak_tree, "random", nil, false) + minetest.place_schematic(vector_offset(pos, -2, -1, -2 ), path_oak_tree, "random", nil, false) end -- Birch function mcl_core.generate_birch_tree(pos) - local path = modpath .. - "/schematics/mcl_core_birch.mts" - minetest.place_schematic({x = pos.x - 2, y = pos.y - 1, z = pos.z - 2}, path, "random", nil, false) + minetest.place_schematic(vector_offset(pos, -2, -1, -2), modpath .. "/schematics/mcl_core_birch.mts", "random", nil, false) end -- BEGIN of spruce tree generation functions -- @@ -524,7 +439,7 @@ end function mcl_core.generate_v6_spruce_tree(pos) local x, y, z = pos.x, pos.y, pos.z - local maxy = y + math.random(9, 13) -- Trunk top + local maxy = y + random(9, 13) -- Trunk top local c_air = minetest.get_content_id("air") local c_ignore = minetest.get_content_id("ignore") @@ -533,11 +448,8 @@ function mcl_core.generate_v6_spruce_tree(pos) local c_snow = minetest.get_content_id("mcl_core:snow") local vm = minetest.get_voxel_manip() - local minp, maxp = vm:read_from_map( - {x = x - 3, y = y, z = z - 3}, - {x = x + 3, y = maxy + 3, z = z + 3} - ) - local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) + local minp, maxp = vm:read_from_map(vector_offset(pos, -3, 0, -3), vector_offset(pos, 3, maxy - y + 3, 3)) + local a = VoxelArea:new(minp, maxp) local data = vm:get_data() -- Upper branches layer @@ -545,42 +457,32 @@ function mcl_core.generate_v6_spruce_tree(pos) for yy = maxy - 1, maxy + 1 do for zz = z - dev, z + dev do local vi = a:index(x - dev, yy, zz) - local via = a:index(x - dev, yy + 1, zz) for xx = x - dev, x + dev do - if math.random() < 0.95 - dev * 0.05 then - add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, - c_spruce_leaves) + if random() < 0.95 - dev * 0.05 then + add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, c_spruce_leaves) end vi = vi + 1 - via = via + 1 end end dev = dev - 1 end -- Centre top nodes - add_spruce_leaves(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow, - c_spruce_leaves) - add_spruce_leaves(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow, - c_spruce_leaves) -- Paramat added a pointy top node + add_spruce_leaves(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow, c_spruce_leaves) + add_spruce_leaves(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow, c_spruce_leaves) -- Lower branches layer local my = 0 for i = 1, 20 do -- Random 2x2 squares of leaves - local xi = x + math.random(-3, 2) - local yy = maxy + math.random(-6, -5) - local zi = z + math.random(-3, 2) - if yy > my then - my = yy - end - for zz = zi, zi+1 do + local xi = x + random(-3, 2) + local yy = maxy + random(-6, -5) + local zi = z + random(-3, 2) + if yy > my then my = yy end + for zz = zi, zi + 1 do local vi = a:index(xi, yy, zz) - local via = a:index(xi, yy + 1, zz) for xx = xi, xi + 1 do - add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, - c_spruce_leaves) + add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, c_spruce_leaves) vi = vi + 1 - via = via + 1 end end end @@ -589,14 +491,11 @@ function mcl_core.generate_v6_spruce_tree(pos) for yy = my + 1, my + 2 do for zz = z - dev, z + dev do local vi = a:index(x - dev, yy, zz) - local via = a:index(x - dev, yy + 1, zz) for xx = x - dev, x + dev do - if math.random() < 0.95 - dev * 0.05 then - add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, - c_spruce_leaves) + if random() < 0.95 - dev * 0.05 then + add_spruce_leaves(data, vi, c_air, c_ignore, c_snow, c_spruce_leaves) end vi = vi + 1 - via = via + 1 end end dev = dev - 1 @@ -608,8 +507,7 @@ function mcl_core.generate_v6_spruce_tree(pos) for yy = y + 1, maxy do local vi = a:index(x, yy, z) local node_id = data[vi] - if node_id == c_air or node_id == c_ignore or - node_id == c_spruce_leaves or node_id == c_snow then + if node_id == c_air or node_id == c_ignore or node_id == c_spruce_leaves or node_id == c_snow then data[vi] = c_spruce_tree end end @@ -619,51 +517,50 @@ function mcl_core.generate_v6_spruce_tree(pos) end function mcl_core.generate_spruce_tree(pos) - local r = math.random(1, 3) - local path = modpath .. "/schematics/mcl_core_spruce_"..r..".mts" - minetest.place_schematic({ x = pos.x - 3, y = pos.y - 1, z = pos.z - 3 }, path, "0", nil, false) + minetest.place_schematic(vector_offset(pos, -3, -1, -3), + modpath .. "/schematics/mcl_core_spruce_"..random(1, 3)..".mts", "0", nil, false) end local function find_necorner(p) - local n=minetest.get_node_or_nil(vector.offset(p,0,1,1)) - local e=minetest.get_node_or_nil(vector.offset(p,1,1,0)) + local n = minetest.get_node_or_nil(vector_offset(p, 0, 1, 1)) + local e = minetest.get_node_or_nil(vector_offset(p, 1, 1, 0)) if n and n.name == "mcl_core:sprucetree" then - p=vector.offset(p,0,0,1) + p = vector_offset(p, 0, 0, 1) end if e and e.name == "mcl_core:sprucetree" then - p=vector.offset(p,1,0,0) + p = vector_offset(p, 1, 0, 0) end return p end local function generate_spruce_podzol(ps) - local pos=find_necorner(ps) - local pos1=vector.offset(pos,-6,-6,-6) - local pos2=vector.offset(pos,6,6,6) - local nn=minetest.find_nodes_in_area_under_air(pos1, pos2, {"group:dirt"}) + local pos = find_necorner(ps) + local pos1, pos2 = vector_offset(pos, -6, -6, -6), vector_offset(pos, 6, 6, 6) + local nn = minetest.find_nodes_in_area_under_air(pos1, pos2, {"group:dirt"}) for k,v in pairs(nn) do - if math.random(vector.distance(pos,v)) < 4 and not (math.abs(pos.x-v.x) == 6 and math.abs(pos.z-v.z) == 6) then --leave out the corners - minetest.set_node(v,{name="mcl_core:podzol"}) + if not (abs(pos.x - v.x) == 6 and abs(pos.z - v.z) == 6) and random(vector_distance(pos,v)) < 4 then --leave out the corners + minetest.set_node(v, {name="mcl_core:podzol"}) end end end function mcl_core.generate_huge_spruce_tree(pos) - local r1 = math.random(1, 2) - local r2 = math.random(1, 4) - local path - local offset = { x = -4, y = -1, z = -5 } + local r1, r2 = random(1, 2), random(1, 4) + local path, offset if r1 <= 2 then -- Mega Spruce Taiga (full canopy) path = modpath.."/schematics/mcl_core_spruce_huge_"..r2..".mts" + offset = vector_offset(pos, -4, -1, -5) else -- Mega Taiga (leaves only at top) if r2 == 1 or r2 == 3 then - offset = { x = -3, y = -1, z = -4} + offset = vector_offset(pos, -3, -1, -4) + else + offset = vector_offset(pos, -4, -1, -5) end path = modpath.."/schematics/mcl_core_spruce_huge_up_"..r2..".mts" end - minetest.place_schematic(vector.add(pos, offset), path, "0", nil, false) + minetest.place_schematic(offset, path, "0", nil, false) generate_spruce_podzol(pos) end @@ -671,29 +568,26 @@ end -- Acacia tree (multiple variants) function mcl_core.generate_acacia_tree(pos) - local r = math.random(1, 7) - local offset = vector.new() - if r == 2 or r == 3 then - offset = { x = -4, y = -1, z = -4 } + local r = random(1, 7) + local path, offset = modpath.."/schematics/mcl_core_acacia_"..r..".mts", nil + if r == 1 or r == 5 then + offset = vector_offset(pos, -5, -1, -5) + elseif r == 2 or r == 3 then + offset = vector_offset(pos, -4, -1, -4) elseif r == 4 or r == 6 or r == 7 then - offset = { x = -3, y = -1, z = -3 } - elseif r == 1 or r == 5 then - offset = { x = -5, y = -1, z = -5 } + offset = vector_offset(pos, -3, -1, -3) end - local path = modpath.."/schematics/mcl_core_acacia_"..r..".mts" - minetest.place_schematic(vector.add(pos, offset), path, "random", nil, false) + minetest.place_schematic(offset, path, "random", nil, false) end --- Generate dark oak tree with 2×2 trunk. +-- Generate dark oak tree with 2x2 trunk. -- With pos being the lower X and the higher Z value of the trunk function mcl_core.generate_dark_oak_tree(pos) - local path = modpath.."/schematics/mcl_core_dark_oak.mts" - minetest.place_schematic({x = pos.x - 3, y = pos.y - 1, z = pos.z - 4}, path, "random", nil, false) + minetest.place_schematic(vector_offset(pos, -3, -1, -4), modpath.."/schematics/mcl_core_dark_oak.mts", "random", nil, false) end -- Helper function for jungle tree, form Minetest Game 0.4.15 -local function add_trunk_and_leaves(data, a, pos, tree_cid, leaves_cid, - height, size, iters) +local function add_trunk_and_leaves(data, a, pos, tree_cid, leaves_cid, height, size, iters) local x, y, z = pos.x, pos.y, pos.z local c_air = minetest.CONTENT_AIR local c_ignore = minetest.CONTENT_IGNORE @@ -710,33 +604,33 @@ local function add_trunk_and_leaves(data, a, pos, tree_cid, leaves_cid, -- Force leaves near the trunk for z_dist = -1, 1 do - for y_dist = -size, 1 do - local vi = a:index(x - 1, y + height + y_dist, z + z_dist) - for x_dist = -1, 1 do - if data[vi] == c_air or data[vi] == c_ignore then - data[vi] = leaves_cid + for y_dist = -size, 1 do + local vi = a:index(x - 1, y + height + y_dist, z + z_dist) + for x_dist = -1, 1 do + if data[vi] == c_air or data[vi] == c_ignore then + data[vi] = leaves_cid + end + vi = vi + 1 end - vi = vi + 1 end end - end -- Randomly add leaves in 2x2x2 clusters. for i = 1, iters do - local clust_x = x + math.random(-size, size - 1) - local clust_y = y + height + math.random(-size, 0) - local clust_z = z + math.random(-size, size - 1) + local clust_x = x + random(-size, size - 1) + local clust_y = y + height + random(-size, 0) + local clust_z = z + random(-size, size - 1) for xi = 0, 1 do - for yi = 0, 1 do - for zi = 0, 1 do - local vi = a:index(clust_x + xi, clust_y + yi, clust_z + zi) - if data[vi] == c_air or data[vi] == c_ignore then - data[vi] = leaves_cid + for yi = 0, 1 do + for zi = 0, 1 do + local vi = a:index(clust_x + xi, clust_y + yi, clust_z + zi) + if data[vi] == c_air or data[vi] == c_ignore then + data[vi] = leaves_cid + end + end end end - end - end end end @@ -749,18 +643,15 @@ function mcl_core.generate_v6_jungle_tree(pos) --]] local x, y, z = pos.x, pos.y, pos.z - local height = math.random(8, 12) + local height = random(8, 12) local c_air = minetest.get_content_id("air") local c_ignore = minetest.get_content_id("ignore") local c_jungletree = minetest.get_content_id("mcl_core:jungletree") local c_jungleleaves = minetest.get_content_id("mcl_core:jungleleaves") local vm = minetest.get_voxel_manip() - local minp, maxp = vm:read_from_map( - {x = x - 3, y = y - 1, z = z - 3}, - {x = x + 3, y = y + height + 1, z = z + 3} - ) - local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) + local minp, maxp = vm:read_from_map(vector_offset(pos, -3, -1, -3), vector_offset(pos, 3, 1, 3)) + local a = VoxelArea:new(minp, maxp) local data = vm:get_data() add_trunk_and_leaves(data, a, pos, c_jungletree, c_jungleleaves, height, 3, 30) @@ -770,7 +661,7 @@ function mcl_core.generate_v6_jungle_tree(pos) local vi_1 = a:index(x - 1, y - 1, z + z_dist) local vi_2 = a:index(x - 1, y, z + z_dist) for x_dist = -1, 1 do - if math.random(1, 3) >= 2 then + if random(1, 3) >= 2 then if data[vi_1] == c_air or data[vi_1] == c_ignore then data[vi_1] = c_jungletree elseif data[vi_2] == c_air or data[vi_2] == c_ignore then @@ -787,17 +678,15 @@ function mcl_core.generate_v6_jungle_tree(pos) end function mcl_core.generate_jungle_tree(pos) - local path = modpath.."/schematics/mcl_core_jungle_tree.mts" - minetest.place_schematic({x = pos.x - 2, y = pos.y - 1, z = pos.z - 2}, path, "random", nil, false) + minetest.place_schematic(vector_offset(pos, -2, -1, -2), modpath.."/schematics/mcl_core_jungle_tree.mts", "random", nil, false) end --- Generate huge jungle tree with 2×2 trunk. +-- Generate huge jungle tree with 2x2 trunk. -- With pos being the lower X and the higher Z value of the trunk. function mcl_core.generate_huge_jungle_tree(pos) - -- 2 variants - local r = math.random(1, 2) - local path = modpath.."/schematics/mcl_core_jungle_tree_huge_"..r..".mts" - minetest.place_schematic({x = pos.x - 6, y = pos.y - 1, z = pos.z - 7}, path, "random", nil, false) + minetest.place_schematic(vector_offset(pos, -6, -1, -7), + modpath.."/schematics/mcl_core_jungle_tree_huge_"..random(1, 2)..".mts", + "random", nil, false) end @@ -805,9 +694,7 @@ local grass_spread_randomizer = PseudoRandom(minetest.get_mapgen_setting("seed") -- Return appropriate grass block node for pos function mcl_core.get_grass_block_type(pos, requested_grass_block_name) - local grass_palette_index = mcl_util.get_palette_indexes_from_pos(pos).grass_palette_index - local grass_block_name = requested_grass_block_name or minetest.get_node(pos).name - return {name = grass_block_name, param2 = grass_palette_index} + return {name = requested_grass_block_name or minetest.get_node(pos).name, param2 = mcl_util.get_palette_indexes_from_pos(pos).grass_palette_index} end -- Return appropriate foliage block node for pos @@ -824,7 +711,7 @@ end -- Spread grass blocks and mycelium on neighbor dirt ------------------------------ minetest.register_abm({ - label = "Grass Block and Mycelium spread", + label = "Grass block and mycelium spread", nodenames = {"mcl_core:dirt"}, neighbors = {"air", "group:grass_block_no_snow", "mcl_core:mycelium"}, interval = 30, @@ -833,7 +720,7 @@ minetest.register_abm({ action = function(pos) if pos == nil then return end - local above = {x=pos.x, y=pos.y+1, z=pos.z} + local above = vector_offset(pos, 0, 1, 0) local abovenode = minetest.get_node(above) if minetest.get_item_group(abovenode.name, "liquid") ~= 0 or minetest.get_item_group(abovenode.name, "opaque") == 1 then -- Never grow directly below liquids or opaque blocks @@ -844,18 +731,14 @@ minetest.register_abm({ if not light_self then return end --[[ Try to find a spreading dirt-type block (e.g. grass block or mycelium) - within a 3×5×3 area, with the source block being on the 2nd-topmost layer. ]] - local nodes = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1}, {x=pos.x+1, y=pos.y+3, z=pos.z+1}, "group:spreading_dirt_type") - local p2 + within a 3x5x3 area, with the source block being on the 2nd-topmost layer. ]] + local nodes = minetest.find_nodes_in_area(vector_offset(pos, -1, -1, -1), vector_offset(pos, 1, 3, 1), "group:spreading_dirt_type") -- Nothing found ? Bail out! - if #nodes <= 0 then - return - else - p2 = nodes[grass_spread_randomizer:next(1, #nodes)] - end + if #nodes <= 0 then return end + local p2 = nodes[grass_spread_randomizer:next(1, #nodes)] -- Found it! Now check light levels! - local source_above = {x=p2.x, y=p2.y+1, z=p2.z} + local source_above = vector_offset(p2, 0, 1, 0) local light_source = minetest.get_node_light(source_above) if not light_source then return end @@ -881,16 +764,15 @@ minetest.register_abm({ -- Grass/mycelium death in darkness minetest.register_abm({ - label = "Grass Block / Mycelium in darkness", + label = "Grass block / mycelium in darkness", nodenames = {"group:spreading_dirt_type"}, interval = 8, chance = 50, catch_up = false, action = function(pos, node) - local above = {x = pos.x, y = pos.y + 1, z = pos.z} - local name = minetest.get_node(above).name + local above = minetest.get_node(vector_offset(pos, 0, 1, 0)).name -- Kill grass/mycelium when below opaque block or liquid - if name ~= "ignore" and (minetest.get_item_group(name, "opaque") == 1 or minetest.get_item_group(name, "liquid") ~= 0) then + if above ~= "ignore" and (minetest.get_item_group(above, "opaque") == 1 or minetest.get_item_group(above, "liquid") ~= 0) then minetest.set_node(pos, {name = "mcl_core:dirt"}) end end @@ -898,9 +780,8 @@ minetest.register_abm({ -- Turn Grass Path and similar nodes to Dirt if a solid node is placed above it minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack, pointed_thing) - if minetest.get_item_group(newnode.name, "solid") ~= 0 or - minetest.get_item_group(newnode.name, "dirtifier") ~= 0 then - local below = {x=pos.x, y=pos.y-1, z=pos.z} + if minetest.get_item_group(newnode.name, "solid") ~= 0 or minetest.get_item_group(newnode.name, "dirtifier") ~= 0 then + local below = vector_offset(pos, 0, -1, 0) local belownode = minetest.get_node(below) if minetest.get_item_group(belownode.name, "dirtifies_below_solid") == 1 then minetest.set_node(below, {name="mcl_core:dirt"}) @@ -909,16 +790,16 @@ minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack end) minetest.register_abm({ - label = "Turn Grass Path below solid block into Dirt", + label = "Turn grass path below solid block into dirt", nodenames = {"mcl_core:grass_path"}, neighbors = {"group:solid"}, interval = 8, chance = 50, action = function(pos, node) - local above = {x = pos.x, y = pos.y + 1, z = pos.z} - local name = minetest.get_node(above).name - local nodedef = minetest.registered_nodes[name] - if name ~= "ignore" and nodedef and (nodedef.groups and nodedef.groups.solid) then + local above = minetest.get_node(vector_offset(pos, 0, 1, 0)).name + if above == "ignore" then return end + local nodedef = minetest.registered_nodes[above] + if nodedef and (nodedef.groups and nodedef.groups.solid) then minetest.set_node(pos, {name = "mcl_core:dirt"}) end end, @@ -931,17 +812,10 @@ minetest.register_lbm({ nodenames = {"mcl_core:dirt_with_dry_grass", "mcl_core:dirt_with_dry_grass_snow"}, run_at_every_load = true, action = function(pos, node) - if node.name == "mcl_core:dirt_with_dry_grass_snow" then - node.name = "mcl_core:dirt_with_grass_snow" - else - node.name = "mcl_core:dirt_with_grass" - end + node.name = node.name == "mcl_core:dirt_with_dry_grass_snow" and "mcl_core:dirt_with_grass_snow" or "mcl_core:dirt_with_grass" -- use savanna palette index to simulate dry grass. - if not node.param2 then - node.param2 = SAVANNA_INDEX - end + node.param2 = node.param2 or SAVANNA_INDEX minetest.set_node(pos, node) - return end, }) @@ -957,7 +831,7 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two, -- Checks if the sapling at pos has enough light and the correct soil local light = minetest.get_node_light(pos) if not light then return end - local low_light = (light < treelight) + local low_light = light < treelight local delta = 1 local current_game_time = minetest.get_day_count() + minetest.get_timeofday() @@ -978,7 +852,7 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two, -- TODO: delta is [days] missed in inactive area. Currently we just add it to stage, which is far from a perfect calculation... - local soilnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + local soilnode = minetest.get_node(vector_offset(pos, 0, -1, 0)) local soiltype = minetest.get_item_group(soilnode.name, "soil_sapling") if soiltype < soil_needed then return end @@ -986,66 +860,67 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two, local meta = minetest.get_meta(pos) local stage = meta:get_int("stage") if stage == nil then stage = 0 end - stage = stage + math.max(1, math.floor(delta)) + stage = stage + max(1, floor(delta)) if stage >= 3 then meta:set_string("grown", "true") - -- This sapling grows in a special way when there are 4 saplings in a 2×2 pattern + -- This sapling grows in a special way when there are 4 saplings in a 2x2 pattern if two_by_two then - -- Check 8 surrounding saplings and try to find a 2×2 pattern + -- Check 8 surrounding saplings and try to find a 2x2 pattern local function is_sapling(pos, sapling) return minetest.get_node(pos).name == sapling end - local p2 = {x=pos.x+1, y=pos.y, z=pos.z} - local p3 = {x=pos.x, y=pos.y, z=pos.z-1} - local p4 = {x=pos.x+1, y=pos.y, z=pos.z-1} - local p5 = {x=pos.x-1, y=pos.y, z=pos.z-1} - local p6 = {x=pos.x-1, y=pos.y, z=pos.z} - local p7 = {x=pos.x-1, y=pos.y, z=pos.z+1} - local p8 = {x=pos.x, y=pos.y, z=pos.z+1} - local p9 = {x=pos.x+1, y=pos.y, z=pos.z+1} - local s2 = is_sapling(p2, sapling) - local s3 = is_sapling(p3, sapling) - local s4 = is_sapling(p4, sapling) - local s5 = is_sapling(p5, sapling) - local s6 = is_sapling(p6, sapling) - local s7 = is_sapling(p7, sapling) - local s8 = is_sapling(p8, sapling) - local s9 = is_sapling(p9, sapling) - -- In a 9×9 field there are 4 possible 2×2 squares. We check them all. - if s2 and s3 and s4 and check_tree_growth(pos, tree_id, { two_by_two = true }) then + -- clockwise from x+1, coded right/bottom/left/top + local prr = vector_offset(pos, 1, 0, 0) -- right + local prb = vector_offset(pos, 1, 0, -1) -- right bottom + local pbb = vector_offset(pos, 0, 0, -1) -- bottom + local pbl = vector_offset(pos, -1, 0, -1) -- bottom left + local pll = vector_offset(pos, -1, 0, 0) -- left + local plt = vector_offset(pos, -1, 0, 1) -- left top + local ptt = vector_offset(pos, 0, 0, 1) -- top + local ptr = vector_offset(pos, 1, 0, 1) -- top right + local srr = is_sapling(prr, sapling) + local srb = is_sapling(prb, sapling) + local sbb = is_sapling(pbb, sapling) + local sbl = is_sapling(pbl, sapling) + local sll = is_sapling(pll, sapling) + local slt = is_sapling(plt, sapling) + local stt = is_sapling(ptt, sapling) + local str = is_sapling(ptr, sapling) + -- In a 3x3 field there are 4 possible 2x2 squares. We check them all. + if srr and srb and sbb and check_tree_growth(pos, tree_id, { two_by_two = true }) then -- Success: Remove saplings and place tree minetest.remove_node(pos) - minetest.remove_node(p2) - minetest.remove_node(p3) - minetest.remove_node(p4) - mcl_core.generate_tree(pos, tree_id, { two_by_two = true }) + minetest.remove_node(prr) + minetest.remove_node(prb) + minetest.remove_node(pbb) + mcl_core.generate_tree(pos, tree_id, { two_by_two = true }) -- center is top-left of 2x2 return - elseif s3 and s5 and s6 and check_tree_growth(p6, tree_id, { two_by_two = true }) then + elseif sbb and sbl and sll and check_tree_growth(pll, tree_id, { two_by_two = true }) then minetest.remove_node(pos) - minetest.remove_node(p3) - minetest.remove_node(p5) - minetest.remove_node(p6) - mcl_core.generate_tree(p6, tree_id, { two_by_two = true }) + minetest.remove_node(pbb) + minetest.remove_node(pbl) + minetest.remove_node(pll) + mcl_core.generate_tree(pll, tree_id, { two_by_two = true }) -- ll is top-left of 2x2 return - elseif s6 and s7 and s8 and check_tree_growth(p7, tree_id, { two_by_two = true }) then + elseif sll and slt and stt and check_tree_growth(plt, tree_id, { two_by_two = true }) then minetest.remove_node(pos) - minetest.remove_node(p6) - minetest.remove_node(p7) - minetest.remove_node(p8) - mcl_core.generate_tree(p7, tree_id, { two_by_two = true }) + minetest.remove_node(pll) + minetest.remove_node(plt) + minetest.remove_node(ptt) + mcl_core.generate_tree(plt, tree_id, { two_by_two = true }) -- lt is top-left of 2x2 return - elseif s2 and s8 and s9 and check_tree_growth(p8, tree_id, { two_by_two = true }) then + elseif stt and str and srr and check_tree_growth(ptt, tree_id, { two_by_two = true }) then minetest.remove_node(pos) - minetest.remove_node(p2) - minetest.remove_node(p8) - minetest.remove_node(p9) - mcl_core.generate_tree(p8, tree_id, { two_by_two = true }) + minetest.remove_node(ptt) + minetest.remove_node(ptr) + minetest.remove_node(prr) + mcl_core.generate_tree(ptt, tree_id, { two_by_two = true }) -- tt is top-left of 2x2 return end end if one_by_one and tree_id == OAK_TREE_ID then -- There is a chance that this tree wants to grow as a balloon oak - if math.random(1, 12) == 1 then + if random(1, 12) == 1 then -- Check if there is room for that if check_tree_growth(pos, tree_id, { balloon = true }) then minetest.set_node(pos, {name="air"}) @@ -1054,11 +929,10 @@ local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two, end end end - -- If this sapling can grow alone + -- If this sapling can grow alone if one_by_one and check_tree_growth(pos, tree_id) then -- Single sapling minetest.set_node(pos, {name="air"}) - --local r = math.random(1, 12) mcl_core.generate_tree(pos, tree_id) return end @@ -1076,44 +950,39 @@ local grow_spruce = sapling_grow_action(SPRUCE_TREE_ID, 1, true, true, "mcl_core local grow_birch = sapling_grow_action(BIRCH_TREE_ID, 1, true, false) function mcl_core.update_sapling_foliage_colors(pos) - local pos1, pos2 = vector.offset(pos, -8, 0, -8), vector.offset(pos, 8, 30, 8) - local fnode - local foliage = minetest.find_nodes_in_area(pos1, pos2, {"group:foliage_palette", "group:foliage_palette_wallmounted"}) + local foliage = minetest.find_nodes_in_area( + vector_offset(pos, -8, 0, -8), vector_offset(pos, 8, 30, 8), + {"group:foliage_palette", "group:foliage_palette_wallmounted"}) for _, fpos in pairs(foliage) do - fnode = minetest.get_node(fpos) - minetest.set_node(fpos, fnode) + minetest.set_node(fpos, minetest.get_node(fpos)) end end --- Attempts to grow the sapling at the specified position +--- Attempts to grow the sapling at the specified position -- pos: Position -- node: Node table of the node at this position, from minetest.get_node -- Returns true on success and false on failure function mcl_core.grow_sapling(pos, node) - local grow if node.name == "mcl_core:sapling" then - grow = grow_oak + grow_oak(pos) elseif node.name == "mcl_core:darksapling" then - grow = grow_dark_oak + grow_dark_oak(pos) elseif node.name == "mcl_core:junglesapling" then - grow = grow_jungle_tree + grow_jungle_tree(pos) elseif node.name == "mcl_core:acaciasapling" then - grow = grow_acacia + grow_acacia(pos) elseif node.name == "mcl_core:sprucesapling" then - grow = grow_spruce + grow_spruce(pos) elseif node.name == "mcl_core:birchsapling" then - grow = grow_birch - end - if grow then - grow(pos) - return true + grow_birch(pos) else return false end + return true end -- TODO: Use better tree models for everything --- TODO: Support 2×2 saplings +-- TODO: Support 2x2 saplings -- Oak tree minetest.register_abm({ @@ -1219,14 +1088,14 @@ minetest.register_lbm({ local function leafdecay_particles(pos, node) minetest.add_particlespawner({ - amount = math.random(10, 20), + amount = random(10, 20), time = 0.1, - minpos = vector.add(pos, {x=-0.4, y=-0.4, z=-0.4}), - maxpos = vector.add(pos, {x=0.4, y=0.4, z=0.4}), - minvel = {x=-0.2, y=-0.2, z=-0.2}, - maxvel = {x=0.2, y=0.1, z=0.2}, - minacc = {x=0, y=-9.81, z=0}, - maxacc = {x=0, y=-9.81, z=0}, + minpos = vector_offset(pos, -0.4, -0.4, -0.4), + maxpos = vector_offset(pos, 0.4, 0.4, 0.4), + minvel = vector_new(-0.2, -0.2, -0.2), + maxvel = vector_new(0.2, 0.1, 0.2), + minacc = vector_new(0, -9.81, 0), + maxacc = vector_new(0, -9.81, 0), minexptime = 0.1, maxexptime = 0.5, minsize = 0.5, @@ -1239,32 +1108,33 @@ end local function vinedecay_particles(pos, node) local dir = minetest.wallmounted_to_dir(node.param2) - local relpos1, relpos2 + if not dir then return end -- Don't crash if the map data got corrupted somehow + local minpos, maxpos if dir.x < 0 then - relpos1 = { x = -0.45, y = -0.4, z = -0.5 } - relpos2 = { x = -0.4, y = 0.4, z = 0.5 } + minpos = vector_offset(pos, -0.45, -0.4, -0.5) + maxpos = vector_offset(pos, -0.4, 0.4, 0.5) elseif dir.x > 0 then - relpos1 = { x = 0.4, y = -0.4, z = -0.5 } - relpos2 = { x = 0.45, y = 0.4, z = 0.5 } + minpos = vector_offset(pos, 0.4, -0.4, -0.5) + maxpos = vector_offset(pos, 0.45, 0.4, 0.5) elseif dir.z < 0 then - relpos1 = { x = -0.5, y = -0.4, z = -0.45 } - relpos2 = { x = 0.5, y = 0.4, z = -0.4 } + minpos = vector_offset(pos, -0.5, -0.4, -0.45) + maxpos = vector_offset(pos, 0.5, 0.4, -0.4) elseif dir.z > 0 then - relpos1 = { x = -0.5, y = -0.4, z = 0.4 } - relpos2 = { x = 0.5, y = 0.4, z = 0.45 } + minpos = vector_offset(pos, -0.5, -0.4, 0.4) + maxpos = vector_offset(pos, 0.5, 0.4, 0.45) else return end minetest.add_particlespawner({ - amount = math.random(8, 16), + amount = random(8, 16), time = 0.1, - minpos = vector.add(pos, relpos1), - maxpos = vector.add(pos, relpos2), - minvel = {x=-0.2, y=-0.2, z=-0.2}, - maxvel = {x=0.2, y=0.1, z=0.2}, - minacc = {x=0, y=-9.81, z=0}, - maxacc = {x=0, y=-9.81, z=0}, + minpos = minpos, + maxpos = maxpos, + minvel = vector_new(-0.2, -0.2, -0.2), + maxvel = vector_new( 0.2, 0.1, 0.2), + minacc = vector_new(0, -9.81, 0), + maxacc = vector_new(0, -9.81, 0), minexptime = 0.1, maxexptime = 0.5, minsize = 0.5, @@ -1275,17 +1145,57 @@ local function vinedecay_particles(pos, node) }) end ---------------------- --- Vine generating -- ---------------------- +----------------- +-- Vine growth -- +----------------- +-- Add vines below pos (if empty) +local function vine_spread_down(origin, node) + if random(1, 2) == 1 then return end + local target = vector_offset(origin, 0, -1, 0) + if minetest.get_node(target).name == "air" then + minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) + end +end + +-- Add vines above pos if it is backed up +local function vine_spread_up(origin, node) + if random(1, 2) == 1 then return end + local vines_in_area = minetest.find_nodes_in_area(vector_offset(origin, -4, -1, -4), vector_offset(origin, 4, 1, 4), "mcl_core:vine") + -- Less than 4 other vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) + if #vines_in_area >= 5 then return end + local target = vector_offset(origin, 0, 1, 0) + if minetest.get_node(target).name ~= "air" then return end + local backupnodename = minetest.get_node(vector_subtract(target, minetest.wallmounted_to_dir(node.param2))).name + + -- Check if the block above is supported + if mcl_core.supports_vines(backupnodename) then + minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) + end +end + +local function vine_spread_horizontal(origin, dir, node) + local vines_in_area = minetest.find_nodes_in_area(vector_offset(origin, -4, -1, -4), vector_offset(origin, 4, 1, 4), "mcl_core:vine") + if #vines_in_area >= 5 then return end + -- Less than 4 other vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) + local target = vector_add(origin, dir) + -- Spread horizontally, but not into support direction + local backup_dir = minetest.wallmounted_to_dir(node.param2) + if backup_dir.x == dir.x and backup_dir.y == dir.y then return end + local target_node = minetest.get_node(target) + if target_node.name ~= "air" then return end + local backupnodename = minetest.get_node(vector_add(target, backup_dir)).name + if mcl_core.supports_vines(backupnodename) then + minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) + end +end + minetest.register_abm({ - label = "Vines growth", + label = "Vine growth", nodenames = {"mcl_core:vine"}, interval = 47, chance = 4, action = function(pos, node, active_object_count, active_object_count_wider) - - -- First of all, check if we are even supported, otherwise, let's die! + -- First of all, check if we are even supported, otherwise, decay. if not mcl_core.check_vines_supported(pos, node) then minetest.remove_node(pos) vinedecay_particles(pos, node) @@ -1293,68 +1203,20 @@ minetest.register_abm({ return end - -- Add vines below pos (if empty) - local function spread_down(origin, target, dir, node) - if math.random(1, 2) == 1 then - if minetest.get_node(target).name == "air" then - minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) - end - end + local d = random(1, 6) + if d == 1 then + vine_spread_horizontal(pos, vector_new( 1, 0, 0), node) + elseif d == 2 then + vine_spread_horizontal(pos, vector_new(-1, 0, 0), node) + elseif d == 3 then + vine_spread_horizontal(pos, vector_new( 0, 0, 1), node) + elseif d == 4 then + vine_spread_horizontal(pos, vector_new( 0, 0, -1), node) + elseif d == 5 then + vine_spread_up(pos, node) + else + vine_spread_down(pos, node) end - - -- Add vines above pos if it is backed up - local function spread_up(origin, target, dir, node) - local vines_in_area = minetest.find_nodes_in_area({x=origin.x-4, y=origin.y-1, z=origin.z-4}, {x=origin.x+4, y=origin.y+1, z=origin.z+4}, "mcl_core:vine") - -- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) - if #vines_in_area < 5 then - if math.random(1, 2) == 1 then - if minetest.get_node(target).name == "air" then - local backup_dir = minetest.wallmounted_to_dir(node.param2) - local backup = vector.subtract(target, backup_dir) - local backupnodename = minetest.get_node(backup).name - - -- Check if the block above is supported - if mcl_core.supports_vines(backupnodename) then - minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) - end - end - end - end - end - - local function spread_horizontal(origin, target, dir, node) - local vines_in_area = minetest.find_nodes_in_area({x=origin.x-4, y=origin.y-1, z=origin.z-4}, {x=origin.x+4, y=origin.y+1, z=origin.z+4}, "mcl_core:vine") - -- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) - if #vines_in_area < 5 then - -- Spread horizontally - local backup_dir = minetest.wallmounted_to_dir(node.param2) - if not vector.equals(backup_dir, dir) then - local target_node = minetest.get_node(target) - if target_node.name == "air" then - local backup = vector.add(target, backup_dir) - local backupnodename = minetest.get_node(backup).name - if mcl_core.supports_vines(backupnodename) then - minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) - end - end - end - end - end - - local directions = { - { { x= 1, y= 0, z= 0 }, spread_horizontal }, - { { x=-1, y= 0, z= 0 }, spread_horizontal }, - { { x= 0, y= 1, z= 0 }, spread_up }, - { { x= 0, y=-1, z= 0 }, spread_down }, - { { x= 0, y= 0, z= 1 }, spread_horizontal }, - { { x= 0, y= 0, z=-1 }, spread_horizontal }, - } - - local d = math.random(1, #directions) - local dir = directions[d][1] - local spread = directions[d][2] - - spread(pos, vector.add(pos, dir), dir, node) end }) @@ -1380,12 +1242,11 @@ minetest.register_abm({ nodenames = {"group:orphan_leaves"}, interval = 5, chance = 10, - action = function(pos, node) + action = function(pos, node) -- Spawn item entities for any of the leaf's drops local itemstacks = minetest.get_node_drops(node.name) for _, itemname in pairs(itemstacks) do - local p_drop = vector.offset(pos, math.random() - 0.5, math.random() - 0.5, math.random() - 0.5) - minetest.add_item(p_drop, itemname) + minetest.add_item(vector_offset(pos, random() - 0.5, random() - 0.5, random() - 0.5), itemname) end -- Remove the decayed node minetest.remove_node(pos) @@ -1393,23 +1254,19 @@ minetest.register_abm({ minetest.check_for_falling(pos) -- Kill depending vines immediately to skip the vines decay delay - local surround = { - { x = 0, y = 0, z = -1 }, - { x = 0, y = 0, z = 1 }, - { x = -1, y = 0, z = 0 }, - { x = 1, y = 0, z = 0 }, - { x = 0, y = -1, z = -1 }, - } - for s=1, #surround do - local spos = vector.add(pos, surround[s]) + local function clean_vines(spos) local maybe_vine = minetest.get_node(spos) - --local surround_inverse = vector.multiply(surround[s], -1) if maybe_vine.name == "mcl_core:vine" and (not mcl_core.check_vines_supported(spos, maybe_vine)) then minetest.remove_node(spos) vinedecay_particles(spos, maybe_vine) minetest.check_for_falling(spos) end end + clean_vines(vector_offset(pos, 0, 0, -1)) + clean_vines(vector_offset(pos, 0, 0, 1)) + clean_vines(vector_offset(pos, -1, 0, 0)) + clean_vines(vector_offset(pos, 1, 0, 0)) + clean_vines(vector_offset(pos, 0, -1, 0)) end }) @@ -1424,13 +1281,11 @@ minetest.register_abm({ -- A low interval and a high inverse chance spreads the load interval = 4, chance = 8, - action = function(p0, node, _, _) - if not mcl_core.check_vines_supported(p0, node) then - -- Vines must die! - minetest.remove_node(p0) - vinedecay_particles(p0, node) - -- Just in case a falling node happens to float above vines - minetest.check_for_falling(p0) + action = function(pos, node) + if not mcl_core.check_vines_supported(pos, node) then + minetest.remove_node(pos) + vinedecay_particles(pos, node) + minetest.check_for_falling(pos) end end }) @@ -1460,7 +1315,7 @@ minetest.register_abm({ chance = 8, action = function(pos, node) if mcl_weather.has_snow(pos) - and minetest.get_natural_light(vector.offset(pos,0,1,0), 0.5) == minetest.LIGHT_MAX + 1 + and minetest.get_natural_light(vector_offset(pos, 0, 1, 0), 0.5) == minetest.LIGHT_MAX + 1 and minetest.get_artificial_light(minetest.get_node(pos).param1) < 10 then node.name = "mcl_core:ice" minetest.swap_node(pos, node) @@ -1473,49 +1328,39 @@ Given the pos and node of a vines node, this returns true if the vines are suppo and false if the vines are currently floating. Vines are considered “supported” if they face a walkable+solid block or “hang” from a vines node above. ]] function mcl_core.check_vines_supported(pos, node) - local supported = false local dir = minetest.wallmounted_to_dir(node.param2) - local pos1 = vector.add(pos, dir) - local node_neighbor = minetest.get_node(pos1) - -- Check if vines are attached to a solid block. - -- If ignore, we assume its solid. - if node_neighbor.name == "ignore" or mcl_core.supports_vines(node_neighbor.name) then - supported = true - elseif dir.y == 0 then + if not dir then return end -- Don't crash if the map data got corrupted somehow + local node_neighbor = minetest.get_node(vector_add(pos, dir)) + -- Check if vines are attached to a solid block, assume "ignore" is good. + if node_neighbor.name == "ignore" or mcl_core.supports_vines(node_neighbor.name) then return true end + if dir.y == 0 then -- Vines are not attached, now we check if the vines are “hanging” below another vines block -- of equal orientation. - local pos2 = vector.add(pos, {x=0, y=1, z=0}) - local node2 = minetest.get_node(pos2) - -- Again, ignore means we assume its supported + local node2 = minetest.get_node(vector_offset(pos, 0, 1, 0)) if node2.name == "ignore" or (node2.name == "mcl_core:vine" and node2.param2 == node.param2) then - supported = true + return true end end - return supported + return false end -- Melt ice at pos. mcl_core:ice MUST be at pos if you call this! function mcl_core.melt_ice(pos) -- Create a water source if ice is destroyed and there was something below it - local below = {x=pos.x, y=pos.y-1, z=pos.z} - local belownode = minetest.get_node(below) + local below = vector_offset(pos, 0, -1, 0) local dim = mcl_worlds.pos_to_dimension(below) - if dim ~= "nether" and belownode.name ~= "air" and belownode.name ~= "ignore" and belownode.name ~= "mcl_core:void" then - minetest.set_node(pos, {name="mcl_core:water_source"}) - else + local belownode = minetest.get_node(below) + if dim == "nether" or belownode.name == "air" or belownode.name == "ignore" or belownode.name == "mcl_core:void" then minetest.remove_node(pos) + else + minetest.set_node(pos, {name="mcl_core:water_source"}) end - local neighbors = { - {x=-1, y=0, z=0}, - {x=1, y=0, z=0}, - {x=0, y=-1, z=0}, - {x=0, y=1, z=0}, - {x=0, y=0, z=-1}, - {x=0, y=0, z=1}, - } - for n=1, #neighbors do - minetest.check_single_for_falling(vector.add(pos, neighbors[n])) - end + minetest.check_single_for_falling(vector_offset(pos, -1, 0, 0)) + minetest.check_single_for_falling(vector_offset(pos, 1, 0, 0)) + minetest.check_single_for_falling(vector_offset(pos, 0, -1, 0)) + minetest.check_single_for_falling(vector_offset(pos, 0, 1, 0)) + minetest.check_single_for_falling(vector_offset(pos, 0, 0, -1)) + minetest.check_single_for_falling(vector_offset(pos, 0, 0, 1)) end ---- FUNCTIONS FOR SNOWED NODES ---- @@ -1534,12 +1379,6 @@ end -- of the snowed node. function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tiles, sounds, clear_colorization, desc, grass_palette) local def = table.copy(minetest.registered_nodes[itemstring_clear]) - local create_doc_alias - if def.description then - create_doc_alias = true - else - create_doc_alias = false - end -- Just some group clearing def.description = desc def._doc_items_longdesc = nil @@ -1563,11 +1402,7 @@ function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tile -- Note: _mcl_snowed must be added to the clear node manually! - if not tiles then - def.tiles = {"default_snow.png", "default_dirt.png", {name="mcl_core_grass_side_snowed.png", tileable_vertical=false}} - else - def.tiles = tiles - end + def.tiles = tiles or {"default_snow.png", "default_dirt.png", {name="mcl_core_grass_side_snowed.png", tileable_vertical=false}} if clear_colorization then def.paramtype2 = nil def.palette = nil @@ -1575,20 +1410,14 @@ function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tile def.color = nil def.overlay_tiles = nil end - if not sounds then - def.sounds = mcl_sounds.node_sound_dirt_defaults({ - footstep = mcl_sounds.node_sound_snow_defaults().footstep, - }) - else - def.sounds = sounds - end + def.sounds = sounds or mcl_sounds.node_sound_dirt_defaults({footstep = mcl_sounds.node_sound_snow_defaults().footstep}) def._mcl_silk_touch_drop = {itemstring_clear} -- Register stuff minetest.register_node(itemstring_snowed, def) - if create_doc_alias and minetest.get_modpath("doc") then + if def.description and minetest.get_modpath("doc") then doc.add_entry_alias("nodes", itemstring_clear, "nodes", itemstring_snowed) end end @@ -1599,7 +1428,7 @@ end function mcl_core.clear_snow_dirt(pos, node) local def = minetest.registered_nodes[node.name] if def and def._mcl_snowless then - minetest.swap_node(pos, {name = def._mcl_snowless, param2=node.param2}) + minetest.swap_node(pos, {name = def._mcl_snowless, param2 = node.param2}) end end @@ -1609,18 +1438,13 @@ end -- on_construct -- Makes constructed snowable node snowed if placed below a snow cover node. function mcl_core.on_snowable_construct(pos) - -- Myself - local node = minetest.get_node(pos) - - -- Above - local apos = {x=pos.x, y=pos.y+1, z=pos.z} - local anode = minetest.get_node(apos) - + local above = minetest.get_node(vector_offset(pos, 0, 1, 0)).name -- Make snowed if needed - if minetest.get_item_group(anode.name, "snow_cover") == 1 then + if minetest.get_item_group(above.name, "snow_cover") == 1 then + local node = minetest.get_node(pos) local def = minetest.registered_nodes[node.name] if def and def._mcl_snowed then - minetest.swap_node(pos, {name = def._mcl_snowed, param2=node.param2}) + minetest.swap_node(pos, {name = def._mcl_snowed, param2 = node.param2}) end end end @@ -1637,31 +1461,26 @@ end -- on_construct -- Makes snowable node below snowed. function mcl_core.on_snow_construct(pos) - local npos = {x=pos.x, y=pos.y-1, z=pos.z} - local node = minetest.get_node(npos) + local below = vector_offset(pos, 0, -1, 0) + local node = minetest.get_node(below) local def = minetest.registered_nodes[node.name] if def and def._mcl_snowed then - minetest.swap_node(npos, {name = def._mcl_snowed, param2=node.param2}) + minetest.swap_node(below, {name = def._mcl_snowed, param2 = node.param2}) end end -- after_destruct -- Clears snowed dirtlike node below. function mcl_core.after_snow_destruct(pos) - local nn = minetest.get_node(pos).name - -- No-op if snow was replaced with snow - if minetest.get_item_group(nn, "snow_cover") == 1 then - return - end - local npos = {x=pos.x, y=pos.y-1, z=pos.z} - local node = minetest.get_node(npos) - mcl_core.clear_snow_dirt(npos, node) + if minetest.get_item_group(minetest.get_node(pos).name, "snow_cover") == 1 then return end + local below = vector_offset(pos, 0, -1, 0) + mcl_core.clear_snow_dirt(below, minetest.get_node(below)) end -- Obsidian crying local crobby_particle = { - velocity = vector.zero(), - acceleration = vector.zero(), + velocity = vector_zero(), + acceleration = vector_zero(), texture = "mcl_core_crying_obsidian_tear.png", collisiondetection = false, collision_removal = false, @@ -1673,16 +1492,16 @@ minetest.register_abm({ interval = 5, chance = 10, action = function(pos, node) - minetest.after(0.1 + math.random() * 1.4, function() + minetest.after(0.1 + random() * 1.4, function() local pt = table.copy(crobby_particle) - pt.size = 1.3 + math.random() * 1.2 - pt.expirationtime = 0.5 + math.random() - pt.pos = vector.offset(pos, math.random() - 0.5, -0.51, math.random() - 0.5) + pt.size = 1.3 + random() * 1.2 + pt.expirationtime = 0.5 + random() + pt.pos = vector_offset(pos, random() - 0.5, -0.51, random() - 0.5) minetest.add_particle(pt) minetest.after(pt.expirationtime, function() - pt.acceleration = vector.new(0, -9, 0) + pt.acceleration = vector_new(0, -9, 0) pt.collisiondetection = true - pt.expirationtime = 1.2 + math.random() * 3.3 + pt.expirationtime = 1.2 + random() * 3.3 minetest.add_particle(pt) end) end) From b540e6c77b56ca5e694ab91287a393bc641df96c Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 10 Nov 2024 02:41:55 +0100 Subject: [PATCH 22/93] Improve head swivel code (#4622) * Utilize the minetest 5.9.0 API that uses radians not degree. * Simplify computations to make this more efficient, in particular by querying and updating the bone position less frequently. * Resolves minetest warning `Deprecated call to set_bone_position, use set_bone_override instead` in this location, but other uses remain. * `mcl_util.set_bone_position` not modified, because it redundantly compares to the previous rotation once more. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4622 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/ENTITIES/mcl_mobs/effects.lua | 127 +++++++++++++---------------- mods/ENTITIES/mcl_mobs/init.lua | 2 +- 2 files changed, 59 insertions(+), 70 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index e746fef39..27811e5c2 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -5,6 +5,7 @@ local validate_vector = mcl_util.validate_vector local active_particlespawners = {} local disable_blood = minetest.settings:get_bool("mobs_disable_blood") local DEFAULT_FALL_SPEED = -9.81*1.5 +local PI_THIRD = math.pi / 3 -- 60 degrees local PATHFINDING = "gowp" @@ -294,86 +295,66 @@ function mcl_mobs:set_animation(self, anim) self:set_animation(anim) end -local function dir_to_pitch(dir) - --local dir2 = vector.normalize(dir) - local xz = math.abs(dir.x) + math.abs(dir.z) - return -math.atan2(-dir.y, xz) -end - local function who_are_you_looking_at (self, dtime) - local pos = self.object:get_pos() + if self.order == "sleep" then + self._locked_object = nil + return + end - local stop_look_at_player_chance = math.random(833/self.curiosity) -- was 10000 - div by 12 for avg entities as outside loop - - local stop_look_at_player = stop_look_at_player_chance == 1 + local stop_look_at_player = math.random() * 833 <= self.curiosity if self.attack then - if not self.target_time_lost then - self._locked_object = self.attack - else - self._locked_object = nil - end + self._locked_object = not self.target_time_lost and self.attack or nil elseif self.following then self._locked_object = self.following elseif self._locked_object then - if stop_look_at_player then - --minetest.log("Stop look: ".. self.name) - self._locked_object = nil - end + if stop_look_at_player then self._locked_object = nil end elseif not self._locked_object then if mcl_util.check_dtime_timer(self, dtime, "step_look_for_someone", 0.2) then - --minetest.log("Change look check: ".. self.name) - - -- For the wither this was 20/60=0.33, so probably need to rebalance and divide rates. - -- but frequency of check isn't good as it is costly. Making others too infrequent requires testing - local chance = 150/self.curiosity - - if chance < 1 then chance = 1 end - local look_at_player_chance = math.random(chance) - - -- was 5000 but called in loop based on entities. so div by 12 as estimate avg of entities found, - -- then div by 20 as less freq lookup - - local look_at_player = look_at_player_chance == 1 - + local pos = self.object:get_pos() for _, obj in pairs(minetest.get_objects_inside_radius(pos, 8)) do - if obj:is_player() and vector.distance(pos,obj:get_pos()) < 4 then - --minetest.log("Change look to player: ".. self.name) + if obj:is_player() and vector.distance(pos, obj:get_pos()) < 4 then self._locked_object = obj break - elseif obj:is_player() or (obj:get_luaentity() and obj:get_luaentity().name == self.name and self ~= obj:get_luaentity()) then - if look_at_player then - --minetest.log("Change look to mob: ".. self.name) + elseif obj:is_player() or (obj:get_luaentity() and self ~= obj:get_luaentity() and obj:get_luaentity().name == self.name) then + -- For the wither this was 20/60=0.33, so probably need to rebalance and divide rates. + -- but frequency of check isn't good as it is costly. Making others too infrequent requires testing + -- was 5000 but called in loop based on entities. so div by 12 as estimate avg of entities found, + -- then div by 20 as less freq lookup + if math.random() * 150 <= self.curiosity then self._locked_object = obj break end end end end - end end function mob_class:check_head_swivel(dtime) if not self.head_swivel or type(self.head_swivel) ~= "string" then return end + who_are_you_looking_at(self, dtime) - who_are_you_looking_at (self, dtime) + local newr, oldp, oldr = vector.zero(), nil, nil + if self.object.get_bone_override then -- minetest >= 5.9 + local ov = self.object:get_bone_override(self.head_swivel) + oldp, oldr = ov.position.vec, ov.rotation.vec + else -- minetest < 5.9 + oldp, oldr = self.object:get_bone_position(self.head_swivel) + oldr = vector.apply(oldr, math.rad) -- old API uses radians + end - local final_rotation = vector.zero() - local oldp,oldr = self.object:get_bone_position(self.head_swivel) - - if self._locked_object and (self._locked_object:is_player() or self._locked_object:get_luaentity()) and self._locked_object:get_hp() > 0 then + local locked_object = self._locked_object + if locked_object and (locked_object:is_player() or locked_object:get_luaentity()) and locked_object:get_hp() > 0 then local _locked_object_eye_height = 1.5 - if self._locked_object:get_luaentity() then - _locked_object_eye_height = self._locked_object:get_luaentity().head_eye_height - end - if self._locked_object:is_player() then - _locked_object_eye_height = self._locked_object:get_properties().eye_height + if locked_object:is_player() then + _locked_object_eye_height = locked_object:get_properties().eye_height + elseif locked_object:get_luaentity() then + _locked_object_eye_height = locked_object:get_luaentity().head_eye_height end if _locked_object_eye_height then - local self_rot = self.object:get_rotation() -- If a mob is attached, should we really be messing with what they are looking at? -- Should this be excluded? @@ -381,40 +362,48 @@ function mob_class:check_head_swivel(dtime) self_rot = self.object:get_attach():get_rotation() end - local player_pos = self._locked_object:get_pos() - local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0))) - local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))+self.head_yaw_offset - local mob_pitch = math.deg(-dir_to_pitch(direction_player))*self.head_pitch_multiplier + local ps = self.object:get_pos() + ps.y = ps.y + self.head_eye_height * .7 + local pt = locked_object:get_pos() + pt.y = pt.y + _locked_object_eye_height + local dir = vector.direction(ps, pt) + local mob_yaw = self_rot.y + math.atan2(dir.x, dir.z) + self.head_yaw_offset + local mob_pitch = math.asin(-dir.y) * self.head_pitch_multiplier - if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.state == "attack" and not self.runaway) then - final_rotation = vector.multiply(oldr, 0.9) + if (mob_yaw < -PI_THIRD or mob_yaw > PI_THIRD) and not (self.attack and self.state == "attack" and not self.runaway) then + newr = vector.multiply(oldr, 0.9) elseif self.attack and self.state == "attack" and not self.runaway then if self.head_yaw == "y" then - final_rotation = vector.new(mob_pitch, mob_yaw, 0) + newr = vector.new(mob_pitch, mob_yaw, 0) elseif self.head_yaw == "z" then - final_rotation = vector.new(mob_pitch, 0, -mob_yaw) + newr = vector.new(mob_pitch, 0, -mob_yaw) end - else - if self.head_yaw == "y" then - final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0) + newr = vector.new((mob_pitch-oldr.x)*.3+oldr.x, (mob_yaw-oldr.y)*.3+oldr.y, 0) elseif self.head_yaw == "z" then - final_rotation = vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3) + newr = vector.new((mob_pitch-oldr.x)*.3+oldr.x, 0, ((mob_yaw-oldr.y)*.3+oldr.y)*-3) end end end - elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then - final_rotation = vector.multiply(oldr, 0.9) - else - --final_rotation = vector.new(0,0,0) + elseif not locked_object and math.abs(oldr.y) > 0.05 and math.abs(oldr.x) < 0.05 then + newr = vector.multiply(oldr, 0.9) + end + + -- 0.02 is about 1.14 degrees tolerance, to update less often + local newp = vector.new(0, self.bone_eye_height, self.horizontal_head_height) + if math.abs(oldr.x-newr.x) + math.abs(oldr.y-newr.y) + math.abs(oldr.z-newr.z) < 0.02 and vector.equals(oldp, newp) then return end + if self.object.get_bone_override then -- minetest >= 5.9 + self.object:set_bone_override(self.head_swivel, { + position = { vec = newp, absolute = true }, + rotation = { vec = newr, absolute = true } }) + else -- minetest < 5.9 + -- old API uses degrees not radians + self.object:set_bone_position(self.head_swivel, newp, vector.apply(newr, math.deg)) end - - mcl_util.set_bone_position(self.object,self.head_swivel, vector.new(0,self.bone_eye_height,self.horizontal_head_height), final_rotation) end - function mob_class:set_animation_speed() local v = self.object:get_velocity() if v then diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index d8f8491d5..b0a7ed9d4 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -141,7 +141,7 @@ function mcl_mobs.register_mob(name, def) local final_def = { use_texture_alpha = def.use_texture_alpha, head_swivel = def.head_swivel or nil, -- bool to activate this function - head_yaw_offset = def.head_yaw_offset or 0, -- for wonkey model bones + head_yaw_offset = math.rad(def.head_yaw_offset or 0), -- for wonkey model bones head_pitch_multiplier = def.head_pitch_multiplier or 1, --for inverted pitch bone_eye_height = def.bone_eye_height or 1.4, -- head bone offset head_eye_height = def.head_eye_height or def.bone_eye_height or 0, -- how hight aproximatly the mobs head is fromm the ground to tell the mob how high to look up at the player From 0422635047ce344a24a0f019a430e513ee4f2832 Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 04:06:43 +0200 Subject: [PATCH 23/93] Add bonemealing callback to saplings. * Adds a _mcl_on_bonemealing callback to the sapling node definitions. --- mods/ITEMS/mcl_core/nodes_trees.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index beead761d..96b619f73 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -280,6 +280,14 @@ function mcl_core.register_sapling(subname, description, longdesc, tt_help, text nn == "mcl_core:podzol" or nn == "mcl_core:podzol_snow" or nn == "mcl_core:dirt" or nn == "mcl_core:mycelium" or nn == "mcl_core:coarse_dirt" end), + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + -- Saplings: 45% chance to advance growth stage + if math.random(1,100) <= 45 then + return mcl_core.grow_sapling(pos, n) + end + end, node_placement_prediction = "", _mcl_blast_resistance = 0, _mcl_hardness = 0, From 9ea52ce9b38bb1a8ee3e8878fe59b41e2ed4a5fd Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 05:48:00 +0200 Subject: [PATCH 24/93] Add bonemealing callback to small mushrooms. * Adds a _mcl_on_bonemealing callback to the mushroom node definitions. --- mods/ITEMS/mcl_mushrooms/small.lua | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/mods/ITEMS/mcl_mushrooms/small.lua b/mods/ITEMS/mcl_mushrooms/small.lua index 4d1ffa2f5..260fe700a 100644 --- a/mods/ITEMS/mcl_mushrooms/small.lua +++ b/mods/ITEMS/mcl_mushrooms/small.lua @@ -1,5 +1,8 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local modpath = minetest.get_modpath(minetest.get_current_modname()) +local schempath = modpath .. "/schematics/" + local on_place = mcl_util.generate_on_place_plant_function(function(place_pos, place_node) local soil_node = minetest.get_node_or_nil({x=place_pos.x, y=place_pos.y-1, z=place_pos.z}) if not soil_node then return false end @@ -16,6 +19,40 @@ local on_place = mcl_util.generate_on_place_plant_function(function(place_pos, p return ((snn == "mcl_core:podzol" or snn == "mcl_core:podzol_snow" or snn == "mcl_core:mycelium" or snn == "mcl_core:mycelium_snow") or (light_ok and minetest.get_item_group(snn, "solid") == 1 and minetest.get_item_group(snn, "opaque") == 1)) end) +-- Try to grow huge mushroom +local function apply_bonemeal(pos, schematic, offset) + -- Must be on a dirt-type block + local below = minetest.get_node(vector.offset(pos, 0, -1, 0)) + if minetest.get_item_group(below.name, "grass_block") ~= 1 + and below.name ~= "mcl_core:mycelium" + and below.name ~= "mcl_core:dirt" + and below.name ~= "mcl_core:coarse_dirt" + and below.name ~= "mcl_core:podzol" then + return false + end + -- 40% chance + if math.random(1, 100) <= 40 then + -- Check space requirements + for i= 1, 3 do + local cpos = vector.offset(pos, 0, i, 0) + if minetest.get_node(cpos).name ~= "air" then + return false + end + end + local minp = vector.offset(pos, -3, 3, -3) + local maxp = vector.offset(pos, 3, 8, 3) + local diff = maxp - minp + local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"}) + if #goodnodes < (diff.x + 1) * (diff.y + 1) * (diff.z + 1) then + return false + end + -- Place the huge mushroom + minetest.remove_node(pos) + return minetest.place_schematic(pos + offset, schematic, 0, nil, false) + end + return false +end + local longdesc_intro_brown = S("Brown mushrooms are fungi which grow and spread in darkness, but are sensitive to light. They are inedible as such, but they can be used to craft food items.") local longdesc_intro_red = S("Red mushrooms are fungi which grow and spread in darkness, but are sensitive to light. They are inedible as such, but they can be used to craft food items.") @@ -51,6 +88,11 @@ minetest.register_node("mcl_mushrooms:mushroom_brown", { }, node_placement_prediction = "", on_place = on_place, + _mcl_on_bonemealing = function(pointed_thing, placer) + local schematic = schempath .. "mcl_mushrooms_huge_brown.mts" + local offset = vector.new(-3, -1, -3) + return apply_bonemeal(pointed_thing.under, schematic, offset) + end, _mcl_blast_resistance = 0, }) @@ -78,6 +120,11 @@ minetest.register_node("mcl_mushrooms:mushroom_red", { }, node_placement_prediction = "", on_place = on_place, + _mcl_on_bonemealing = function(pointed_thing, placer) + local schematic = schempath .. "mcl_mushrooms_huge_red.mts" + local offset = vector.new(-2, -1, -2) + return apply_bonemeal(pointed_thing.under, schematic, offset) + end, _mcl_blast_resistance = 0, }) From 71e6fa9646e8855ec16a9e242b71291103f88d3b Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 05:59:14 +0200 Subject: [PATCH 25/93] Add bonemealing callback to wheat. * Adds a _mcl_on_bonemealing callback to the unripe wheat node definitions. --- mods/ITEMS/mcl_farming/wheat.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index 4ddbb156a..d8ed0d0fb 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -60,6 +60,12 @@ for i=1,7 do dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + local stages = math.random(2, 5) + return mcl_farming:grow_plant("plant_wheat", pos, n, stages, true) + end }) end From 69032c3222197cc176ce7d3ae12f6e9d25d5c34c Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:05:37 +0200 Subject: [PATCH 26/93] Add bonemealing callback to potatoes. * Adds a _mcl_on_bonemealing callback to the unripe potato plants. --- mods/ITEMS/mcl_farming/potatoes.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index 2dc4a3522..da837009a 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -49,6 +49,12 @@ for i=1, 7 do groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + local stages = math.random(2, 5) + return mcl_farming:grow_plant("plant_potato", pos, n, stages, true) + end }) end From 2d8bb12fadc9eb4cc5f53e0d12de4d201e0d3d6b Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:08:38 +0200 Subject: [PATCH 27/93] Add bonemealing callback to carrots. * Adds a _mcl_on_bonemealing callback to the unripe carrot plants. --- mods/ITEMS/mcl_farming/carrots.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index 6f7d7a6aa..a008f73ed 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -45,6 +45,12 @@ for i=1, 7 do groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + local stages = math.random(2, 5) + return mcl_farming:grow_plant("plant_carrot", pos, n, stages, true) + end }) end From 5d2fa8072a4ad7521970d225d4e79c582b9a2d64 Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:12:45 +0200 Subject: [PATCH 28/93] Add bonemealing callback to pumpkins. * Adds a _mcl_on_bonemealing callback to the unripe pumpkin plants. --- mods/ITEMS/mcl_farming/pumpkin.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 1befef8a8..3d6062f0b 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -79,6 +79,12 @@ for s=1,7 do groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1,}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + local stages = math.random(2, 5) + return mcl_farming:grow_plant("plant_pumpkin_stem", pos, n, stages, true) + end }) end From d07e8d95364e9067b57d95fc454424806b57eac1 Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:19:16 +0200 Subject: [PATCH 29/93] Add bonemealing callback to melons. * Adds a _mcl_on_bonemealing callback to the unripe melon plants. --- mods/ITEMS/mcl_farming/melon.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index 205150b6e..deda6ba10 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -109,6 +109,12 @@ for s=1,7 do groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, plant_melon_stem=s}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + local stages = math.random(2, 5) + return mcl_farming:grow_plant("plant_melon_stem", pos, n, stages, true) + end }) end From 17f2d85de90e243a4d64ce7de37011c7862b713e Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:36:09 +0200 Subject: [PATCH 30/93] Refactor beetroots and add bonemealing callback. * Abstract unripe beetroot plant node registrations into a single indexed definition and do the registration in a loop. * Adds a _mcl_on_bonemealing callback to the unripe melon plants. --- mods/ITEMS/mcl_farming/beetroot.lua | 104 ++++++++++------------------ 1 file changed, 35 insertions(+), 69 deletions(-) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 4c77f3dad..2ee7037f0 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -13,78 +13,44 @@ minetest.register_craftitem("mcl_farming:beetroot_seeds", { end }) -minetest.register_node("mcl_farming:beetroot_0", { - description = S("Premature Beetroot Plant (Stage 1)"), - _doc_items_longdesc = S("Beetroot plants are plants which grow on farmland under sunlight in 4 stages. On hydrated farmland, they grow a bit faster. They can be harvested at any time but will only yield a profit when mature."), - _doc_items_entry_name = S("Premature Beetroot Plant"), - paramtype = "light", - paramtype2 = "meshoptions", - sunlight_propagates = true, - place_param2 = 3, - walkable = false, - drawtype = "plantlike", - drop = "mcl_farming:beetroot_seeds", - tiles = {"mcl_farming_beetroot_0.png"}, - inventory_image = "mcl_farming_beetroot_0.png", - wield_image = "mcl_farming_beetroot_0.png", - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5} - }, - }, - groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, -}) +local size = {[0]=-5, -3, 2} -minetest.register_node("mcl_farming:beetroot_1", { - description = S("Premature Beetroot Plant (Stage 2)"), - _doc_items_create_entry = false, - paramtype = "light", - paramtype2 = "meshoptions", - sunlight_propagates = true, - place_param2 = 3, - walkable = false, - drawtype = "plantlike", - drop = "mcl_farming:beetroot_seeds", - tiles = {"mcl_farming_beetroot_1.png"}, - inventory_image = "mcl_farming_beetroot_1.png", - wield_image = "mcl_farming_beetroot_1.png", - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, -4/16, 0.5} +for i = 0, 2 do + minetest.register_node("mcl_farming:beetroot_".. i, { + description = S("Premature Beetroot Plant (Stage ".. i + 1 ..")"), + _doc_items_longdesc = S("Beetroot plants are plants which grow on farmland under sunlight in 4 stages. On hydrated farmland, they grow a bit faster. They can be harvested at any time but will only yield a profit when mature."), + _doc_items_entry_name = S("Premature Beetroot Plant"), + paramtype = "light", + paramtype2 = "meshoptions", + sunlight_propagates = true, + place_param2 = 3, + walkable = false, + drawtype = "plantlike", + drop = "mcl_farming:beetroot_seeds", + tiles = {"mcl_farming_beetroot_".. i ..".png"}, + inventory_image = "mcl_farming_beetroot_".. i ..".png", + wield_image = "mcl_farming_beetroot_".. i ..".png", + selection_box = { + type = "fixed", + fixed = { {-0.5, -0.5, -0.5, 0.5, size[i]/16, 0.5} }, }, - }, - groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, -}) - -minetest.register_node("mcl_farming:beetroot_2", { - description = S("Premature Beetroot Plant (Stage 3)"), - _doc_items_create_entry = false, - paramtype = "light", - paramtype2 = "meshoptions", - sunlight_propagates = true, - place_param2 = 3, - walkable = false, - drawtype = "plantlike", - drop = "mcl_farming:beetroot_seeds", - tiles = {"mcl_farming_beetroot_2.png"}, - inventory_image = "mcl_farming_beetroot_2.png", - wield_image = "mcl_farming_beetroot_2.png", - selection_box = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, -3/16, 0.5} + groups = { + dig_immediate=3, not_in_creative_inventory=1, + plant=1, attached_node=1, dig_by_water=1, + destroy_by_lava_flow=1,dig_by_piston=1 }, - }, - groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, - sounds = mcl_sounds.node_sound_leaves_defaults(), - _mcl_blast_resistance = 0, -}) + sounds = mcl_sounds.node_sound_leaves_defaults(), + _mcl_blast_resistance = 0, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + -- 75% chance to advance to next stage + if math.random(1, 100) <= 75 then + return mcl_farming:grow_plant("plant_beetroot", pos, n, 1, true) + end + end + }) +end minetest.register_node("mcl_farming:beetroot", { description = S("Mature Beetroot Plant"), From f644d37332305f11668c00af81189250a78afd78 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 18 Mar 2024 17:59:37 +0000 Subject: [PATCH 31/93] Keep same selection box size --- mods/ITEMS/mcl_farming/beetroot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 2ee7037f0..605c41005 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -13,7 +13,7 @@ minetest.register_craftitem("mcl_farming:beetroot_seeds", { end }) -local size = {[0]=-5, -3, 2} +local size = {[0]=-5, -4, -3} for i = 0, 2 do minetest.register_node("mcl_farming:beetroot_".. i, { From bde0d9b238ed884427c500379aafa4d7fdfee3ae Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 06:54:07 +0200 Subject: [PATCH 32/93] Add bonemealing callback to cocoa. * Adds a _mcl_on_bonemealing callback to the unripe cocoa pods. --- mods/ITEMS/mcl_cocoas/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 0792972be..0d5491bb8 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -100,6 +100,11 @@ local crop_def = { on_rotate = false, _mcl_blast_resistance = 3, _mcl_hardness = 0.2, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + mcl_cocoas.grow(pos) + return true + end } -- 2nd stage @@ -145,6 +150,7 @@ crop_def.selection_box = { }, } crop_def.drop = "mcl_cocoas:cocoa_beans 3" +crop_def._mcl_on_bonemealing = nil minetest.register_node("mcl_cocoas:cocoa_3", table.copy(crop_def)) minetest.register_craftitem("mcl_cocoas:cocoa_beans", { From fdc7f4634db5feca2e423f5e9427b0268196a175 Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 30 Apr 2022 17:34:15 +0200 Subject: [PATCH 33/93] Add bonemealing callback for dirt with grass. * Add new file mcl_flowers/bonemeal.lua, containing the bonemealing callback for "mcl_core:dirt_with_grass". * Override "mcl_core:dirt_with_grass" with a _mcl_on_bonemealing handler calling a function defined in mcl_flowers. This sidesteps the problem that bonemealing a node from mcl_core needs knowledge of mcl_flowers, which would create a circular dependency. H/t to cora for suggesting this solution. H/t to wsor for suggesting a solution that also works. --- mods/ITEMS/mcl_flowers/bonemealing.lua | 123 +++++++++++++++++++++++++ mods/ITEMS/mcl_flowers/init.lua | 3 + 2 files changed, 126 insertions(+) create mode 100644 mods/ITEMS/mcl_flowers/bonemealing.lua diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua new file mode 100644 index 000000000..24c4fbdb8 --- /dev/null +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -0,0 +1,123 @@ +-- bonemealing grass nodes +-- +-- When bonemealing "mcl_core:dirt_with_grass", it spawns grass and flowers +-- over a 7x7 patch of adjacent grassy nodes. +-- +-- Because of potential dependency complications it is not advisable to add +-- callbacks to mcl_core that create dependencies on mods that depend on +-- mcl_core, such as mcl_flowers. +-- +-- To work around this restriction, the bonemealing callback is defined here +-- and the _mcl_on_bonemealing callback in "mcl_core:dirt_with_grass" node +-- definition is overwritten with it. + +local mg_name = minetest.get_mapgen_setting("mg_name") + +local flowers_table_simple = { + "mcl_flowers:dandelion", + "mcl_flowers:poppy", +} +local flowers_table_plains = { + "mcl_flowers:dandelion", + "mcl_flowers:dandelion", + "mcl_flowers:poppy", + "mcl_flowers:oxeye_daisy", + "mcl_flowers:tulip_orange", + "mcl_flowers:tulip_red", + "mcl_flowers:tulip_white", + "mcl_flowers:tulip_pink", + "mcl_flowers:azure_bluet", +} +local flowers_table_swampland = { + "mcl_flowers:blue_orchid", +} +local flowers_table_flower_forest = { + "mcl_flowers:dandelion", + "mcl_flowers:poppy", + "mcl_flowers:oxeye_daisy", + "mcl_flowers:tulip_orange", + "mcl_flowers:tulip_red", + "mcl_flowers:tulip_white", + "mcl_flowers:tulip_pink", + "mcl_flowers:azure_bluet", + "mcl_flowers:allium", +} + +local biome_flowers_tables = { + ["Plains"] = flowers_table_plains, + ["Plains_beach"] = flowers_table_plains, + ["Plains_ocean"] = flowers_table_plains, + ["Plains_deep_ocean"] = flowers_table_plains, + ["Plains_underground"] = flowers_table_plains, + ["SunflowerPlains"] = flowers_table_plains, + ["SunflowerPlains_ocean"] = flowers_table_plains, + ["SunflowerPlains_deep_ocean"] = flowers_table_plains, + ["SunflowerPlains_underground"] = flowers_table_plains, + ["Swampland"] = flowers_table_swampland, + ["Swampland_shore"] = flowers_table_swampland, + ["Swampland_ocean"] = flowers_table_swampland, + ["Swampland_deep_ocean"] = flowers_table_swampland, + ["Swampland_underground"] = flowers_table_swampland, + ["FlowerForest"] = flowers_table_flower_forest, + ["FlowerForest_beach"] = flowers_table_flower_forest, + ["FlowerForest_ocean"] = flowers_table_flower_forest, + ["FlowerForest_deep_ocean"] = flowers_table_flower_forest, + ["FlowerForest_underground"] = flowers_table_flower_forest, +} + +-- Randomly generate flowers, tall grass or nothing +-- pos: node to place into +-- color: param2 value for tall grass +-- +local function add_random_flower(pos, color) + -- 90% tall grass, 10% flower + if math.random(1,100) <= 90 then + minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=color}) + else + local flowers_table + if mg_name == "v6" then + flowers_table = flowers_table_plains + else + local biome = minetest.get_biome_name(minetest.get_biome_data(pos).biome) + flowers_table = biome_flowers_tables[biome] or flowers_table_simple + end + minetest.add_node(pos, {name=flowers_table[math.random(1, #flowers_table)]}) + end +end + +--- Generate tall grass and random flowers in a 7x7 area +-- Bonemealing callback handler for "mcl_core:dirt_with_grass" +-- +local function bonemeal_grass(pointed_thing, placer) + local pos, below, r, color + for i = -7, 7 do for j = -7, 7 do for y = -1, 1 do + pos = vector.offset(pointed_thing.above, i, y, j) + if minetest.get_node(pos).name == "air" then + below = minetest.get_node(vector.offset(pos, 0, -1, 0)) + r = ((math.abs(i) + math.abs(j)) / 2) + if (minetest.get_item_group(below.name, "grass_block_no_snow") == 1) and + math.random(1, 100) <= 90 / r then + color = below.param2 + add_random_flower(pos, color) + end + end + end end end + return true +end + +-- Overwrite "mcl_core:dirt_with_grass" bonemealing handler. +local nodename = "mcl_core:dirt_with_grass" +local olddef = minetest.registered_nodes[nodename] +if not olddef then + minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!") +else + local oldhandler = olddef._mcl_on_bonemealing + local newdef = table.copy(olddef) + newdef._mcl_on_bonemealing = function (pointed_thing, placer) + bonemeal_grass(pointed_thing, placer) + if oldhandler then + oldhandler(pointed_thing, placer) + end + end + minetest.register_node(":" .. nodename, newdef) +end diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 85a65a165..e4ef5a55c 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -572,3 +572,6 @@ if mod_mcimport and mg_name == "singlenode" and fix_doubleplants == true then end dofile(modpath.."/register.lua") + +-- Bonemealing handler and override for "mcl_core:dirt_with_grass": +dofile(modpath.."/bonemealing.lua") From ea1d52baaba2527a635653a842a9168650b92b44 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 00:05:30 +0200 Subject: [PATCH 34/93] Add bonemealing callback for double flowers. * Adds a _mcl_on_bonemealing callback to the double flowers. --- mods/ITEMS/mcl_flowers/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index e4ef5a55c..0e0a61135 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -243,10 +243,16 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im if name == "double_grass" then bottom_groups.compostability = 50 end + local on_bonemealing if is_flower then bottom_groups.flower = 1 bottom_groups.place_flowerlike = 1 bottom_groups.dig_immediate = 3 + on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + minetest.add_item(pos, "mcl_flowers:"..name) + return true + end else bottom_groups.place_flowerlike = 2 bottom_groups.handy = 1 @@ -381,6 +387,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im minetest.remove_node(top) end end, + _mcl_on_bonemealing = on_bonemealing, groups = bottom_groups, sounds = mcl_sounds.node_sound_leaves_defaults(), mesh = mesh @@ -419,6 +426,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im minetest.remove_node(bottom) end end, + _mcl_on_bonemealing = on_bonemealing, groups = top_groups, sounds = mcl_sounds.node_sound_leaves_defaults(), }) From 21900808325960b95065cbbc61a41c9579c9c6fd Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 00:15:40 +0200 Subject: [PATCH 35/93] Add bonemealing callback for tall grass. * Adds a _mcl_on_bonemealing callback to tall grass. --- mods/ITEMS/mcl_flowers/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 0e0a61135..084975a36 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -162,6 +162,18 @@ local def_tallgrass = { _mcl_fortune_drop = fortune_wheat_seed_drop, node_placement_prediction = "", on_place = on_place_flower, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + -- Grow into double tallgrass + local toppos = vector.offset(pos, 0, 1, 0) + local topnode = minetest.get_node(toppos) + if minetest.registered_nodes[topnode.name].buildable_to then + minetest.set_node(pos, { name = "mcl_flowers:double_grass", param2 = n.param2 }) + minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top", param2 = n.param2 }) + return true + end + end, _mcl_blast_resistance = 0, _mcl_hardness = 0, } From f6235e8e92598febbfc0127814ddb243361e36c5 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 00:20:00 +0200 Subject: [PATCH 36/93] Add bonemealing callback for fern. * Adds a _mcl_on_bonemealing callback to fern. --- mods/ITEMS/mcl_flowers/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 084975a36..20c153dfa 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -192,6 +192,18 @@ def_fern.selection_box = { fixed = { -6/16, -0.5, -6/16, 6/16, 5/16, 6/16 }, } def_fern.groups.compostability = 65 +def_fern._mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local n = minetest.get_node(pos) + -- Grow into double fern. + local toppos = vector.offset(pos, 0, 1, 0) + local topnode = minetest.get_node(toppos) + if minetest.registered_nodes[topnode.name].buildable_to then + minetest.set_node(pos, { name = "mcl_flowers:double_fern", param2 = n.param2 }) + minetest.set_node(toppos, { name = "mcl_flowers:double_fern_top", param2 = n.param2 }) + return true + end + end minetest.register_node("mcl_flowers:fern", def_fern) From 3889abbaf4ea980ea8a39846724bade0f4974ef7 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 12:33:19 +0200 Subject: [PATCH 37/93] Add mcl_bone_meal. * New mod mcl_bone_meal, replacing bone meal functionality previously held in mcl_dye. * Improve bonemealing API using callbacks in the nodes that support bonemealing. * Rename bone meal item to `"mcl_bone_meal:bone_meal"` and updated its crafting recipe. * Implement legacy compatibility for older bone meal API. * Remove all non dye-related bone meal code, texture and translations from mcl_dye. * Add legacy compatibility shims to mcl_dye that refer to mcl_bone_meal. * Add an alias for "mcl_dye:white" to keep mcl_dye and its API working uniterrupted. * Update mod depends in mcl_dye mod.conf. --- mods/ITEMS/mcl_bone_meal/API.md | 54 ++++ mods/ITEMS/mcl_bone_meal/init.lua | 159 ++++++++++ mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr | 5 + mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr | 4 + mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr | 5 + mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr | 5 + mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr | 5 + .../mcl_bone_meal/locale/mcl_dye.zh_TW.tr | 5 + mods/ITEMS/mcl_bone_meal/locale/template.txt | 6 + mods/ITEMS/mcl_bone_meal/mod.conf | 3 + .../mcl_bone_meal/textures/mcl_bone_meal.png | Bin mods/ITEMS/mcl_dye/init.lua | 276 +----------------- mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr | 3 - mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr | 3 - mods/ITEMS/mcl_dye/locale/template.txt | 4 - mods/ITEMS/mcl_dye/mod.conf | 3 +- 19 files changed, 259 insertions(+), 293 deletions(-) create mode 100644 mods/ITEMS/mcl_bone_meal/API.md create mode 100644 mods/ITEMS/mcl_bone_meal/init.lua create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr create mode 100644 mods/ITEMS/mcl_bone_meal/locale/template.txt create mode 100644 mods/ITEMS/mcl_bone_meal/mod.conf rename textures/mcl_bone_meal_bone_meal.png => mods/ITEMS/mcl_bone_meal/textures/mcl_bone_meal.png (100%) diff --git a/mods/ITEMS/mcl_bone_meal/API.md b/mods/ITEMS/mcl_bone_meal/API.md new file mode 100644 index 000000000..f0402aae3 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/API.md @@ -0,0 +1,54 @@ + +# Bone meal API +Bonemealing callbacks and particle functions. + + +## _mcl_on_bonemealing(pointed_thing, placer) +The bone meal API provides a callback definition that nodes can use to +register a handler that is executed when a bone meal item is used on it. + +Nodes that wish to use the bone meal API should in their node registration +define a callback handler named `_mcl_on_bonemealing`. This handler is a + + `function(pointed_thing, placer)` + +Its arguments are: +* `pointed_thing`: exact pointing location (see Minetest API), where the + bone meal is applied +* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! + +The function should return `true` if the bonemealing was succesful. + +It is for all intents and purposes up to the callback defined in the node to +decide how to handle the effect that bone meal has on that particular node. + +The `on_place` code in the bone meal item will spawn bone meal particles and +decrease the bone meal itemstack if the handler returned `true` and the +`placer` is not in creative mode. + + +## mcl_bone_meal.add_bone_meal_particle(pos, def) +Spawns standard or custom bone meal particles. +* `pos`: position, is ignored if you define def.minpos and def.maxpos +* `def`: (optional) particle definition; see minetest.add_particlespawner() + for more details. + + +# Legacy API +The bone meal API also provides a legacy compatibility function. This +function is not meant to be continued and callers should migrate to the +newer bonemealing API. + +## mcl_bone_meal.register_on_bone_meal_apply(function(pointed_thing, placer)) +Called when the bone meal is applied anywhere. +* `pointed_thing`: exact pointing location (see Minetest API), where the + bone meal is applied +* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! +This function is deprecated and will be removed at some time in the future. + +## mcl_dye.add_bone_meal_particle(pos, def) +## mcl_dye.register_on_bone_meal_apply(function(pointed_thing, user)) +These shims in mcl_dye that point to corresponding legacy compatibility +functions in mcl_bone_meal remain for legacy callers that have not yet been +updated to the new API. These shims will be removed at some time in the +future. diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua new file mode 100644 index 000000000..a5487d57e --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -0,0 +1,159 @@ +local S = minetest.get_translator(minetest.get_current_modname()) + +local longdesc = S( + "Bone meal is a white dye and also useful as a fertilizer to " .. + "speed up the growth of many plants." +) +local usagehelp = S( + "Rightclick a sheep to turn its wool white. Rightclick a plant " .. + "to speed up its growth. Note that not all plants can be " .. + "fertilized like this. When you rightclick a grass block, tall " .. + "grass and flowers will grow all over the place." +) + +mcl_bone_meal = {} + +-- Bone meal particle api: + +--- Spawns bone meal particles. +-- pos: where the particles spawn +-- def: particle spawner parameters, see minetest.add_particlespawner() for +-- details on these parameters. +-- +function mcl_bone_meal.add_bone_meal_particle(pos, def) + if not def then + def = {} + end + minetest.add_particlespawner({ + amount = def.amount or 10, + time = def.time or 0.1, + minpos = def.minpos or vector.subtract(pos, 0.5), + maxpos = def.maxpos or vector.add(pos, 0.5), + minvel = def.minvel or vector.new(-0.01, 0.01, -0.01), + maxvel = def.maxvel or vector.new(0.01, 0.01, 0.01), + minacc = def.minacc or vector.new(0, 0, 0), + maxacc = def.maxacc or vector.new(0, 0, 0), + minexptime = def.minexptime or 1, + maxexptime = def.maxexptime or 4, + minsize = def.minsize or 0.7, + maxsize = def.maxsize or 2.4, + texture = "mcl_particles_bonemeal.png^[colorize:#00EE00:125", -- TODO: real MC color + glow = def.glow or 1, + }) +end + +-- Begin legacy bone meal API. +-- +-- Compatibility code for legacy users of the old bone meal API. +-- This code will be removed at some time in the future. +-- +mcl_bone_meal.bone_meal_callbacks = {} + +-- Shims for the old API are still available in mcl_dye and refer to +-- the real functions in mcl_bone_meal. +-- +function mcl_bone_meal.register_on_bone_meal_apply(func) + minetest.log("warning", "register_on_bone_meal_apply(func) is deprecated. Read mcl_bone_meal/API.md!") + table.insert(mcl_bone_meal.bone_meal_callbacks, func) +end + +-- Legacy registered users of the old API are handled through this function. +-- +local function apply_bone_meal(pointed_thing, placer) + for _, func in pairs(mcl_bone_meal.bone_meal_callbacks) do + if func(pointed_thing, placer) then + return true + end + end + + local pos = pointed_thing.under + local n = minetest.get_node(pos) + if n.name == "" then return false end + + -- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages + if string.find(n.name, "mcl_farming:sweet_berry_bush_") then + mcl_dye.add_bone_meal_particle(pos) + 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, 0, true) + end + return true +--[[ + Here for when Bonemeal becomes an api, there's code if needed for handling applying to bamboo. + -- Handle applying bonemeal to bamboo. + elseif mcl_bamboo.is_bamboo(n.name) then + local success = mcl_bamboo.grow_bamboo(pos, true) + if success then + mcl_dye.add_bone_meal_particle(pos) + end + return success +--]] + end + + return false +end +-- End legacy bone meal API + +minetest.register_craftitem("mcl_bone_meal:bone_meal", { + inventory_image = "mcl_bone_meal.png", + description = S("Bone Meal"), + _tt_help = S("Speeds up plant growth"), + _doc_items_longdesc = longdesc, + _doc_items_usagehelp = usagehelp, + stack_max = 64, + groups = {craftitem=1, dye=1, basecolor_white=1, excolor_white=1, unicolor_white=1}, + on_place = function(itemstack, placer, pointed_thing) + local pos = pointed_thing.under + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + -- Use pointed node's on_rightclick function first, if present. + if placer and not placer:get_player_control().sneak then + if ndef and ndef.on_rightclick then + return ndef.on_rightclick(pos, node, placer, itemstack, pointed_thing) or itemstack + end + end + -- If the pointed node can be bonemealed, let it handle the processing. + if ndef and ndef._mcl_on_bonemealing then + if ndef._mcl_on_bonemealing(pointed_thing, placer) then + mcl_bone_meal.add_bone_meal_particle(pos) + if not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() + end + end + -- Otherwise try the legacy API. + elseif apply_bone_meal(pointed_thing, placer) and + not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() + end + return itemstack + end, + _on_dispense = function(itemstack, pos, droppos, dropnode, dropdir) + local pointed_thing + if dropnode.name == "air" then + pointed_thing = {above = droppos, under = vector.offset(droppos, 0, -1 ,0)} + else + pointed_thing = {above = pos, under = droppos} + end + local node = minetest.get_node(pointed_thing.under) + local ndef = minetest.registered_nodes[node.name] + -- If the pointed node can be bonemealed, let it handle the processing. + if ndef and ndef._mcl_on_bonemealing then + if ndef._mcl_on_bonemealing(pointed_thing, nil) then + itemstack:take_item() + end + else + -- Otherwise try the legacy API. + if apply_bone_meal(pointed_thing, nil) then + itemstack:take_item() + end + end + return itemstack + end, + _dispense_into_walkable = true +}) + +minetest.register_craft({ + output = "mcl_bone_meal:bone_meal 3", + recipe = {{"mcl_mobitems:bone"}}, +}) diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr new file mode 100644 index 000000000..22aad0ae5 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr @@ -0,0 +1,5 @@ +# textdomain: mcl_bone_meal +Bone Meal=Knochenmehl +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=Knochenmehl ist ein weißer Farbstoff und auch nützlich als Dünger, um das Wachstum vieler Pflanzen zu beschleunigen. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Rechtsklicken Sie auf ein Schaf, um die Wolle weiß einzufärben. Rechtsklicken Sie auf eine Pflanze, um ihr Wachstum zu beschleunigen. Beachten Sie, dass nicht alle Pflanzen darauf ansprechen. Benutzen Sie es auf einem Grasblock, wächst viel hohes Gras und vielleicht auch ein paar Blumen. +Speeds up plant growth=Beschleunigt Pflanzenwachstum diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr new file mode 100644 index 000000000..267f244bb --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr @@ -0,0 +1,4 @@ +# textdomain: mcl_bone_meal +Bone Meal=Harina de hueso +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La harina de hueso es un tinte blanco y también es útil como fertilizante para acelerar el crecimiento de muchas plantas. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=RHaga clic derecho en una oveja para volver su lana blanca. Haga clic derecho en una planta para acelerar su crecimiento. Tenga en cuenta que no todas las plantas pueden ser fertilizadas de esta manera. Cuando haces clic derecho en un bloque de hierba, crecerán hierba alta y flores por todo el lugar. diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr new file mode 100644 index 000000000..5cb6c42b6 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr @@ -0,0 +1,5 @@ +# textdomain: mcl_bone_meal +Bone Meal=Farine d'Os +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La farine d'os est une teinture blanche et également utile comme engrais pour accélérer la croissance de nombreuses plantes. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Notez que toutes les plantes ne peuvent pas être fertilisées comme ça. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent partout. +Speeds up plant growth=Accélère la croissance des plantes diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr new file mode 100644 index 000000000..7c17c4032 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr @@ -0,0 +1,5 @@ +# textdomain: mcl_bone_meal +Bone Meal=Mączka kostna +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=Mączka kostna to biała farba i przydatny nawóz, który przyspiesza rośnięcie wielu roślin. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Kliknij prawym na owcę, aby wybielić jej wełnę. Kliknij prawym na roślinę aby przyspieszyć jej wzrost. Zważ, że nie na wszystkie rośliny to tak działa. Gdy klikniesz prawym na blok trawy, wysoka trawa wyrośnie wokół. +Speeds up plant growth=Przyspiesza wzrost roślin diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr new file mode 100644 index 000000000..83b9fbe02 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr @@ -0,0 +1,5 @@ +# textdomain: mcl_bone_meal +Bone Meal=Костная мука +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=Костная мука является белым красителем. Она также полезна в качестве удобрения, чтобы увеличить скорость роста многих растений. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Кликните правой по овце, чтобы сделать её шерсть белой. Кликните правой по растению, чтобы ускорить его рост. Имейте в виду, что не все растения можно удобрять таким способом. Если вы кликнете по травяному блоку, то на этом месте вырастет высокая трава и цветы. +Speeds up plant growth=Ускоряет рост растений diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr new file mode 100644 index 000000000..e9c240d19 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr @@ -0,0 +1,5 @@ +# textdomain: mcl_bone_meal +Bone Meal=骨粉 +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=骨粉是一種白色染料,也可作為肥料,加速許多植物的生長。 +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=右鍵點擊一隻羊,使其羊毛變白。右鍵點擊一株植物以加快其生長速度。注意,不是所有的植物都能像這樣施肥。當你右鍵點擊一個草方時,高高的草和花會到處生長。 +Speeds up plant growth=加速植物生長 diff --git a/mods/ITEMS/mcl_bone_meal/locale/template.txt b/mods/ITEMS/mcl_bone_meal/locale/template.txt new file mode 100644 index 000000000..4e295dc57 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/locale/template.txt @@ -0,0 +1,6 @@ +# textdomain: mcl_bone_meal +Bone Meal= +Rightclick on a sheep to dye its wool. Other things are dyed by crafting.= +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.= +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.= +Speeds up plant growth= diff --git a/mods/ITEMS/mcl_bone_meal/mod.conf b/mods/ITEMS/mcl_bone_meal/mod.conf new file mode 100644 index 000000000..439973540 --- /dev/null +++ b/mods/ITEMS/mcl_bone_meal/mod.conf @@ -0,0 +1,3 @@ +name = mcl_bone_meal +description = Bone meal can be used as a fertilizer and as a dye. +author = kabou diff --git a/textures/mcl_bone_meal_bone_meal.png b/mods/ITEMS/mcl_bone_meal/textures/mcl_bone_meal.png similarity index 100% rename from textures/mcl_bone_meal_bone_meal.png rename to mods/ITEMS/mcl_bone_meal/textures/mcl_bone_meal.png diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index b35904fc4..40f75e252 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -15,7 +15,6 @@ mcl_dye = {} local S = minetest.get_translator(minetest.get_current_modname()) -local math = math local string = string -- Base color groups: @@ -115,279 +114,19 @@ for _, row in pairs(dyes) do }) end --- Bone meal code to be moved into its own mod. +-- Legacy support for things now in mcl_bone_meal. +-- These shims will at some time in the future be removed. -- function mcl_dye.add_bone_meal_particle(pos, def) - if not def then - def = {} - end - minetest.add_particlespawner({ - amount = def.amount or 10, - time = def.time or 0.1, - minpos = def.minpos or vector.subtract(pos, 0.5), - maxpos = def.maxpos or vector.add(pos, 0.5), - minvel = def.minvel or vector.new(-0.01, 0.01, -0.01), - maxvel = def.maxvel or vector.new(0.01, 0.01, 0.01), - minacc = def.minacc or vector.new(0, 0, 0), - maxacc = def.maxacc or vector.new(0, 0, 0), - minexptime = def.minexptime or 1, - maxexptime = def.maxexptime or 4, - minsize = def.minsize or 0.7, - maxsize = def.maxsize or 2.4, - texture = "mcl_particles_bonemeal.png^[colorize:#00EE00:125", -- TODO: real MC color - glow = def.glow or 1, - }) + minetest.log("warning", "mcl_dye.add_bone_meal_particles() is deprecated. Read mcl_bone_meal/API.md!") + mcl_bone_meal.add_bone_meal_particle(pos, def) end -mcl_dye.bone_meal_callbacks = {} - function mcl_dye.register_on_bone_meal_apply(func) - table.insert(mcl_dye.bone_meal_callbacks, func) + minetest.log("warning", "mcl_dye.register_on_bone_meal_apply() is deprecated. Read mcl_bone_meal/API.md!") + mcl_bone_meal.register_on_bone_meal_apply(func) end -local function apply_bone_meal(pointed_thing, user) - -- Bone meal currently spawns all flowers found in the plains. - local flowers_table_plains = { - "mcl_flowers:dandelion", - "mcl_flowers:dandelion", - "mcl_flowers:poppy", - - "mcl_flowers:oxeye_daisy", - "mcl_flowers:tulip_orange", - "mcl_flowers:tulip_red", - "mcl_flowers:tulip_white", - "mcl_flowers:tulip_pink", - "mcl_flowers:azure_bluet", - } - local flowers_table_simple = { - "mcl_flowers:dandelion", - "mcl_flowers:poppy", - } - local flowers_table_swampland = { - "mcl_flowers:blue_orchid", - } - local flowers_table_flower_forest = { - "mcl_flowers:dandelion", - "mcl_flowers:poppy", - "mcl_flowers:oxeye_daisy", - "mcl_flowers:tulip_orange", - "mcl_flowers:tulip_red", - "mcl_flowers:tulip_white", - "mcl_flowers:tulip_pink", - "mcl_flowers:azure_bluet", - "mcl_flowers:allium", - } - - local pos = pointed_thing.under - local n = minetest.get_node(pos) - if n.name == "" then return false end - - if mcl_util.check_area_protection(pos, pointed_thing.above, user) then - return false - end - - for _, func in pairs(mcl_dye.bone_meal_callbacks) do - if func(pointed_thing, user) then - return true - end - end - - if minetest.get_item_group(n.name, "sapling") >= 1 then - mcl_dye.add_bone_meal_particle(pos) - -- Saplings: 45% chance to advance growth stage - if math.random(1, 100) <= 45 then - if n.name == "mcl_cherry_blossom:cherrysapling" then - return mcl_cherry_blossom.generate_cherry_tree(pos) -- If cherry blossom sapling, run that callback instead. - else - return mcl_core.grow_sapling(pos, n) - end - end - elseif minetest.get_item_group(n.name, "mushroom") == 1 then - mcl_dye.add_bone_meal_particle(pos) - -- Try to grow huge mushroom - - -- Must be on a dirt-type block - local below = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) - if below.name ~= "mcl_core:mycelium" and below.name ~= "mcl_core:dirt" and minetest.get_item_group(below.name, "grass_block") ~= 1 and below.name ~= "mcl_core:coarse_dirt" and below.name ~= "mcl_core:podzol" then - return false - end - - -- Select schematic - local schematic, offset, height - if n.name == "mcl_mushrooms:mushroom_brown" then - schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_brown.mts" - offset = { x = -3, y = -1, z = -3 } - height = 8 - elseif n.name == "mcl_mushrooms:mushroom_red" then - schematic = minetest.get_modpath("mcl_mushrooms").."/schematics/mcl_mushrooms_huge_red.mts" - offset = { x = -2, y = -1, z = -2 } - height = 8 - else - return false - end - -- 40% chance - if math.random(1, 100) <= 40 then - -- Check space requirements - for i=1,3 do - local cpos = vector.add(pos, {x=0, y=i, z=0}) - if minetest.get_node(cpos).name ~= "air" then - return false - end - end - local yoff = 3 - local minp, maxp = {x=pos.x-3, y=pos.y+yoff, z=pos.z-3}, {x=pos.x+3, y=pos.y+yoff+(height-3), z=pos.z+3} - local diff = vector.subtract(maxp, minp) - diff = vector.add(diff, {x=1,y=1,z=1}) - local totalnodes = diff.x * diff.y * diff.z - local goodnodes = minetest.find_nodes_in_area(minp, maxp, {"air", "group:leaves"}) - if #goodnodes < totalnodes then - return false - end - - -- Place the huge mushroom - minetest.remove_node(pos) - local place_pos = vector.add(pos, offset) - local ok = minetest.place_schematic(place_pos, schematic, 0, nil, false) - return ok ~= nil - end - return false - -- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages - elseif string.find(n.name, "mcl_farming:wheat_") then - mcl_dye.add_bone_meal_particle(pos) - local stages = math.random(2, 5) - return mcl_farming:grow_plant("plant_wheat", pos, n, stages, true) - elseif string.find(n.name, "mcl_farming:potato_") then - mcl_dye.add_bone_meal_particle(pos) - local stages = math.random(2, 5) - return mcl_farming:grow_plant("plant_potato", pos, n, stages, true) - elseif string.find(n.name, "mcl_farming:carrot_") then - mcl_dye.add_bone_meal_particle(pos) - local stages = math.random(2, 5) - return mcl_farming:grow_plant("plant_carrot", pos, n, stages, true) - elseif string.find(n.name, "mcl_farming:pumpkin_") then - mcl_dye.add_bone_meal_particle(pos) - local stages = math.random(2, 5) - return mcl_farming:grow_plant("plant_pumpkin_stem", pos, n, stages, true) - elseif string.find(n.name, "mcl_farming:melontige_") then - mcl_dye.add_bone_meal_particle(pos) - local stages = math.random(2, 5) - return mcl_farming:grow_plant("plant_melon_stem", pos, n, stages, true) - elseif string.find(n.name, "mcl_farming:beetroot_") then - mcl_dye.add_bone_meal_particle(pos) - -- Beetroot: 75% chance to advance to next stage - if math.random(1, 100) <= 75 then - return mcl_farming:grow_plant("plant_beetroot", pos, n, 1, true) - end - elseif string.find(n.name, "mcl_farming:sweet_berry_bush_") then - mcl_dye.add_bone_meal_particle(pos) - 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) - end - elseif n.name == "mcl_cocoas:cocoa_1" or n.name == "mcl_cocoas:cocoa_2" then - mcl_dye.add_bone_meal_particle(pos) - -- Cocoa: Advance by 1 stage - mcl_cocoas.grow(pos) - return true - elseif minetest.get_item_group(n.name, "grass_block") == 1 then - -- Grass Block: Generate tall grass and random flowers all over the place - for i = -7, 7 do - for j = -7, 7 do - for y = -1, 1 do - pos = vector.offset(pointed_thing.above, i, y, j) - n = minetest.get_node(pos) - local n2 = minetest.get_node(vector.offset(pos, 0, -1, 0)) - - if n.name ~= "" and n.name == "air" and (minetest.get_item_group(n2.name, "grass_block_no_snow") == 1) then - -- Randomly generate flowers, tall grass or nothing - if math.random(1, 100) <= 90 / ((math.abs(i) + math.abs(j)) / 2)then - -- 90% tall grass, 10% flower - mcl_dye.add_bone_meal_particle(pos, {amount = 4}) - if math.random(1,100) <= 90 then - local col = n2.param2 - minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=col}) - else - local flowers_table - if mg_name == "v6" then - flowers_table = flowers_table_plains - else - local biome = minetest.get_biome_name(minetest.get_biome_data(pos).biome) - if biome == "Swampland" or biome == "Swampland_shore" or biome == "Swampland_ocean" or biome == "Swampland_deep_ocean" or biome == "Swampland_underground" then - flowers_table = flowers_table_swampland - elseif biome == "FlowerForest" or biome == "FlowerForest_beach" or biome == "FlowerForest_ocean" or biome == "FlowerForest_deep_ocean" or biome == "FlowerForest_underground" then - flowers_table = flowers_table_flower_forest - elseif biome == "Plains" or biome == "Plains_beach" or biome == "Plains_ocean" or biome == "Plains_deep_ocean" or biome == "Plains_underground" or biome == "SunflowerPlains" or biome == "SunflowerPlains_ocean" or biome == "SunflowerPlains_deep_ocean" or biome == "SunflowerPlains_underground" then - flowers_table = flowers_table_plains - else - flowers_table = flowers_table_simple - end - end - minetest.add_node(pos, {name=flowers_table[math.random(1, #flowers_table)]}) - end - end - end - end - end - end - return true - - -- Double flowers: Drop corresponding item - elseif n.name == "mcl_flowers:rose_bush" or n.name == "mcl_flowers:rose_bush_top" then - mcl_dye.add_bone_meal_particle(pos) - minetest.add_item(pos, "mcl_flowers:rose_bush") - return true - elseif n.name == "mcl_flowers:peony" or n.name == "mcl_flowers:peony_top" then - mcl_dye.add_bone_meal_particle(pos) - minetest.add_item(pos, "mcl_flowers:peony") - return true - elseif n.name == "mcl_flowers:lilac" or n.name == "mcl_flowers:lilac_top" then - mcl_dye.add_bone_meal_particle(pos) - minetest.add_item(pos, "mcl_flowers:lilac") - return true - elseif n.name == "mcl_flowers:sunflower" or n.name == "mcl_flowers:sunflower_top" then - mcl_dye.add_bone_meal_particle(pos) - minetest.add_item(pos, "mcl_flowers:sunflower") - return true - - elseif n.name == "mcl_flowers:tallgrass" then - mcl_dye.add_bone_meal_particle(pos) - -- Tall Grass: Grow into double tallgrass - local toppos = { x=pos.x, y=pos.y+1, z=pos.z } - local topnode = minetest.get_node(toppos) - if minetest.registered_nodes[topnode.name].buildable_to then - minetest.set_node(pos, { name = "mcl_flowers:double_grass", param2 = n.param2 }) - minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top", param2 = n.param2 }) - return true - end - ---[[ - Here for when Bonemeal becomes an api, there's code if needed for handling applying to bamboo. - -- Handle applying bonemeal to bamboo. - elseif mcl_bamboo.is_bamboo(n.name) then - local success = mcl_bamboo.grow_bamboo(pos, true) - if success then - mcl_dye.add_bone_meal_particle(pos) - end - return success ---]] - elseif n.name == "mcl_flowers:fern" then - mcl_dye.add_bone_meal_particle(pos) - -- Fern: Grow into large fern - local toppos = { x=pos.x, y=pos.y+1, z=pos.z } - local topnode = minetest.get_node(toppos) - if minetest.registered_nodes[topnode.name].buildable_to then - minetest.set_node(pos, { name = "mcl_flowers:double_fern", param2 = n.param2 }) - minetest.set_node(toppos, { name = "mcl_flowers:double_fern_top", param2 = n.param2 }) - return true - end - end - - return false -end - -mcl_dye.apply_bone_meal = apply_bone_meal - -- Bone meal item registration. -- -- To be moved into its own mod. @@ -609,19 +348,16 @@ minetest.register_craft({ output = "mcl_dye:magenta 2", recipe = {"mcl_dye:violet", "mcl_dye:pink"}, }) - minetest.register_craft({ type = "shapeless", output = "mcl_dye:pink 2", recipe = {"mcl_dye:red", "mcl_dye:white"}, }) - minetest.register_craft({ type = "shapeless", output = "mcl_dye:cyan 2", recipe = {"mcl_dye:blue", "mcl_dye:dark_green"}, }) - minetest.register_craft({ type = "shapeless", output = "mcl_dye:violet 2", diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr index 92be50c17..a2769934a 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr @@ -17,11 +17,7 @@ Magenta Dye=Magenta Farbstoff Pink Dye=Rosa Farbstoff This item is a dye which is used for dyeing and crafting.=Dieser Gegenstand ist ein Farbstoff, der zum Einfärben und in der Herstellung benutzt werden kann. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Rechtsklicken Sie auf ein Schaf, um seine Wolle zu färben. Andere Dinge werden mit der Fertigung eingefärbt. -Bone Meal=Knochenmehl -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=Knochenmehl ist ein weißer Farbstoff und auch nützlich als Dünger, um das Wachstum vieler Pflanzen zu beschleunigen. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Rechtsklicken Sie auf ein Schaf, um die Wolle weiß einzufärben. Rechtsklicken Sie auf eine Pflanze, um ihr Wachstum zu beschleunigen. Beachten Sie, dass nicht alle Pflanzen darauf ansprechen. Benutzen Sie es auf einem Grasblock, wächst viel hohes Gras und vielleicht auch ein paar Blumen. Cocoa beans are a brown dye and can be used to plant cocoas.=Kakaobohnen sind ein brauner Farbstoff und werden benutzt, um Kakao anzupflanzen. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Rechtsklicken Sie auf ein Schaf, um die Wolle braun einzufärben. Rechtsklicken Sie an die Seite eines Dschungelbaumstamms (Dschungelholz), um eine junge Kakaoschote zu pflanzen. Cocoa Beans=Kakaobohnen Grows at the side of jungle trees=Wächst an der Seite von Dschungelbäumen -Speeds up plant growth=Beschleunigt Pflanzenwachstum diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr index a829d5386..e363a63b5 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr @@ -17,9 +17,6 @@ Magenta Dye=Tinte magenta Pink Dye=Tinte rosado This item is a dye which is used for dyeing and crafting.=Este artículo es un tinte que se utiliza para teñir y elaborar. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Haga clic derecho sobre una oveja para teñir su lana. Otras cosas pueden ser teñidas mediante la elaboración. -Bone Meal=Harina de hueso -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La harina de hueso es un tinte blanco y también es útil como fertilizante para acelerar el crecimiento de muchas plantas. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=RHaga clic derecho en una oveja para volver su lana blanca. Haga clic derecho en una planta para acelerar su crecimiento. Tenga en cuenta que no todas las plantas pueden ser fertilizadas de esta manera. Cuando haces clic derecho en un bloque de hierba, crecerán hierba alta y flores por todo el lugar. Cocoa beans are a brown dye and can be used to plant cocoas.=Los granos de cacao son un tinte marrón y se pueden usar para plantar cacao. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en una oveja para convertir su lana en marrón. Haga clic derecho en el costado del tronco de un árbol de jungla para plantar un cacao joven. Cocoa Beans=Granos de cacao diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr index 761511c5b..efb8d5bb9 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr @@ -17,11 +17,7 @@ Magenta Dye=Teinture Magenta Pink Dye=Teinture Rose This item is a dye which is used for dyeing and crafting.=Cet objet est un colorant utilisé pour la teinture et l'artisanat. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Clic droit sur un mouton pour teindre sa laine. D'autres choses sont teintes par l'artisanat. -Bone Meal=Farine d'Os -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La farine d'os est une teinture blanche et également utile comme engrais pour accélérer la croissance de nombreuses plantes. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Notez que toutes les plantes ne peuvent pas être fertilisées comme ça. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent partout. Cocoa beans are a brown dye and can be used to plant cocoas.=Les fèves de cacao ont une teinture brune et peuvent être utilisées pour planter du cacao. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Faites un clic droit sur un mouton pour brunir sa laine. Clic droit sur le côté d'un tronc d'arbre de la jungle (Bois Acajou) pour planter un jeune cacao. Cocoa Beans=Fèves de Cacao Grows at the side of jungle trees=Pousse à côté des arbres de la jungle -Speeds up plant growth=Accélère la croissance des plantes diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr index 85e5b9605..ae8d00641 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr @@ -17,11 +17,7 @@ Magenta Dye=Karmazynowa farba Pink Dye=Różowa farba This item is a dye which is used for dyeing and crafting.=Ten przedmiot to farba wykorzystywana to farbowania i wytwarzania. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Kliknij prawym na owcę aby zafarbować jej wełnę. Inne rzeczy mogą być zafarbowane przy wytwarzaniu. -Bone Meal=Mączka kostna -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=Mączka kostna to biała farba i przydatny nawóz, który przyspiesza rośnięcie wielu roślin. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Kliknij prawym na owcę, aby wybielić jej wełnę. Kliknij prawym na roślinę aby przyspieszyć jej wzrost. Zważ, że nie na wszystkie rośliny to tak działa. Gdy klikniesz prawym na blok trawy, wysoka trawa wyrośnie wokół. Cocoa beans are a brown dye and can be used to plant cocoas.=Ziarna kakaowe mogą być wykorzystane do sadzenia kakao. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Naciśnij prawym aby zafarbować wełnę owcy na brązowo. Naciśnij prawym na boku tropikalnego pnia (Tropikalne drewno) aby zasadzić młode kakao. Cocoa Beans=Ziarna kakaowe Grows at the side of jungle trees=Rośnie na boku tropikalnych drzew -Speeds up plant growth=Przyspiesza wzrost roślin diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr index 86dc708e2..4552c5ce5 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr @@ -17,9 +17,6 @@ Magenta Dye=洋紅色染料 Pink Dye=粉紅色染料 This item is a dye which is used for dyeing and crafting.=這個物品是一種用於染色和合成的染料。 Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=右鍵單擊綿羊以染它的毛。其他東西是通過合成染色的。 -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=骨粉是一種白色染料,也可作為肥料,加速許多植物的生長。 -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=右鍵點擊一隻羊,使其羊毛變白。右鍵點擊一株植物以加快其生長速度。注意,不是所有的植物都能像這樣施肥。當你右鍵點擊一個草方時,高高的草和花會到處生長。 Cocoa beans are a brown dye and can be used to plant cocoas.=可可豆是一種棕色染料,也可用於種植可可。 Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=右鍵點擊一隻羊,使其羊毛變成褐色。右鍵點擊叢林木的一側,可以種植一個可可。 Grows at the side of jungle trees=在叢林木側生長 -Speeds up plant growth=加速植物生長 diff --git a/mods/ITEMS/mcl_dye/locale/template.txt b/mods/ITEMS/mcl_dye/locale/template.txt index 84bac96af..123df4514 100644 --- a/mods/ITEMS/mcl_dye/locale/template.txt +++ b/mods/ITEMS/mcl_dye/locale/template.txt @@ -17,11 +17,7 @@ Magenta Dye= Pink Dye= This item is a dye which is used for dyeing and crafting.= Rightclick on a sheep to dye its wool. Other things are dyed by crafting.= -Bone Meal= -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.= -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.= Cocoa beans are a brown dye and can be used to plant cocoas.= Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.= Cocoa Beans= Grows at the side of jungle trees= -Speeds up plant growth= diff --git a/mods/ITEMS/mcl_dye/mod.conf b/mods/ITEMS/mcl_dye/mod.conf index fe93278fc..f570211b2 100644 --- a/mods/ITEMS/mcl_dye/mod.conf +++ b/mods/ITEMS/mcl_dye/mod.conf @@ -1,2 +1,3 @@ name = mcl_dye -depends = mcl_core, mcl_flowers, mcl_mobitems, mcl_cocoas +description = Adds color to your world! +depends = mcl_bone_meal, mcl_cocoas From 8855246dd40ae63041a4f5d1d0385557876d8f58 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 16:16:28 +0200 Subject: [PATCH 38/93] Update to new bone meal API. * Update to use new mcl_bone_meal API: * Use new bone meal item and remove related comment. * Update mod depends in mod.conf * Spelling fixes: s/bonemeal/bone meal/g --- mods/ITEMS/mcl_composters/init.lua | 10 ++++------ mods/ITEMS/mcl_composters/locale/template.txt | 6 +++--- mods/ITEMS/mcl_composters/mod.conf | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_composters/init.lua b/mods/ITEMS/mcl_composters/init.lua index efa08c75c..b635760ca 100644 --- a/mods/ITEMS/mcl_composters/init.lua +++ b/mods/ITEMS/mcl_composters/init.lua @@ -11,7 +11,7 @@ local composter_description = S( "Composter" ) local composter_longdesc = S( - "Composters can convert various organic items into bonemeal." + "Composters can convert various organic items into bone meal." ) local composter_usagehelp = S( "Use organic items on the composter to fill it with layers of compost. " .. @@ -97,7 +97,7 @@ function composter_progress_chance(pos, node, chance) -- get current compost level local level = registered_nodes[node.name]["_mcl_compost_level"] -- spawn green particles above new layer - mcl_dye.add_bone_meal_particle(vector_offset(pos, 0, level/8, 0)) + mcl_bone_meal.add_bone_meal_particle(vector_offset(pos, 0, level/8, 0)) -- update composter block if level < 7 then level = level + 1 @@ -114,9 +114,7 @@ function composter_progress_chance(pos, node, chance) -- the block will get updated by the node timer callback set in node reg def if level == 7 then local timer = get_node_timer(pos) - if not timer:is_started() then - timer:start(1) - end + timer:start(1) end end end @@ -203,7 +201,7 @@ end -- minetest.register_node("mcl_composters:composter", { description = composter_description, - _tt_help = S("Converts organic items into bonemeal"), + _tt_help = S("Converts organic items into bone meal"), _doc_items_longdesc = composter_longdesc, _doc_items_usagehelp = composter_usagehelp, paramtype = "light", diff --git a/mods/ITEMS/mcl_composters/locale/template.txt b/mods/ITEMS/mcl_composters/locale/template.txt index f3329719a..5d8df6fdb 100644 --- a/mods/ITEMS/mcl_composters/locale/template.txt +++ b/mods/ITEMS/mcl_composters/locale/template.txt @@ -1,7 +1,7 @@ # textdomain: mcl_composters Composter= -Composters can convert various organic items into bonemeal.= -Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter.= +Composters can convert various organic items into bone meal.= +Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter."= filled= ready for harvest= -Converts organic items into bonemeal= +Converts organic items into bone meal= diff --git a/mods/ITEMS/mcl_composters/mod.conf b/mods/ITEMS/mcl_composters/mod.conf index ed6119d3a..f7f229fbc 100644 --- a/mods/ITEMS/mcl_composters/mod.conf +++ b/mods/ITEMS/mcl_composters/mod.conf @@ -1,5 +1,5 @@ name = mcl_composters author = kabou description = Composters can convert various organic items into bonemeal. -depends = mcl_core, mcl_sounds, mcl_dye, mcl_hoppers +depends = mcl_core, mcl_sounds, mcl_bone_meal, mcl_hoppers optional_depends = doc From e8d965e21ae224dcc854763b94c673045cec3748 Mon Sep 17 00:00:00 2001 From: kabou Date: Sun, 1 May 2022 16:30:30 +0200 Subject: [PATCH 39/93] Add more particles when bonemealing grass. * Bonemealing dirt_with_grass spawns new growth over a wide area, so it looks better if we spawn a few more extra bone meal particles. * Update mod.conf depends to mcl_bone_meal. --- mods/ITEMS/mcl_flowers/bonemealing.lua | 3 +++ mods/ITEMS/mcl_flowers/mod.conf | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index 24c4fbdb8..a478ec458 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -99,6 +99,9 @@ local function bonemeal_grass(pointed_thing, placer) math.random(1, 100) <= 90 / r then color = below.param2 add_random_flower(pos, color) + if math.random(1,5) == 1 then + mcl_bone_meal.add_bone_meal_particle(pos) + end end end end end end diff --git a/mods/ITEMS/mcl_flowers/mod.conf b/mods/ITEMS/mcl_flowers/mod.conf index b309ac22e..cd67070da 100644 --- a/mods/ITEMS/mcl_flowers/mod.conf +++ b/mods/ITEMS/mcl_flowers/mod.conf @@ -1,3 +1,3 @@ name=mcl_flowers -depends=mcl_core, mcl_util, mcl_sounds -optional_depends=screwdriver, doc, mcl_flowerpots \ No newline at end of file +depends=mcl_core, mcl_util, mcl_sounds, mcl_bone_meal +optional_depends=screwdriver, doc, mcl_flowerpots From 7ddcf3f93fd42571be9a6b9e559f6e8953a299da Mon Sep 17 00:00:00 2001 From: kabou Date: Mon, 2 May 2022 01:35:47 +0200 Subject: [PATCH 40/93] Use better override mechanism. * Use `minetest.override_item()` instead of re-registering the node with ":" prefixed to its name. Thanks again to wsor for mentioning this. --- mods/ITEMS/mcl_flowers/bonemealing.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index a478ec458..297c297e8 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -108,19 +108,18 @@ local function bonemeal_grass(pointed_thing, placer) return true end --- Overwrite "mcl_core:dirt_with_grass" bonemealing handler. +-- Override "mcl_core:dirt_with_grass" bonemealing handler. local nodename = "mcl_core:dirt_with_grass" local olddef = minetest.registered_nodes[nodename] if not olddef then minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!") else local oldhandler = olddef._mcl_on_bonemealing - local newdef = table.copy(olddef) - newdef._mcl_on_bonemealing = function (pointed_thing, placer) + local newhandler = function (pointed_thing, placer) bonemeal_grass(pointed_thing, placer) if oldhandler then oldhandler(pointed_thing, placer) end end - minetest.register_node(":" .. nodename, newdef) + minetest.override_item(nodename, {_mcl_on_bonemealing = newhandler}) end From ae56a864d0e633e8cd2b0662a9b8ce0f5ac0a01f Mon Sep 17 00:00:00 2001 From: kabou Date: Tue, 3 May 2022 10:31:55 +0200 Subject: [PATCH 41/93] Remove stray line from locale template. * Removed a line from the mcl_bone_meal locale template that had by accident put there during the bone meal <-> white dye changes. --- mods/ITEMS/mcl_bone_meal/locale/template.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/ITEMS/mcl_bone_meal/locale/template.txt b/mods/ITEMS/mcl_bone_meal/locale/template.txt index 4e295dc57..9ecc61044 100644 --- a/mods/ITEMS/mcl_bone_meal/locale/template.txt +++ b/mods/ITEMS/mcl_bone_meal/locale/template.txt @@ -1,6 +1,5 @@ # textdomain: mcl_bone_meal Bone Meal= -Rightclick on a sheep to dye its wool. Other things are dyed by crafting.= Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.= Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.= Speeds up plant growth= From 810051c5918c5e5eff43b05cedf90fa37f61c486 Mon Sep 17 00:00:00 2001 From: kabou Date: Mon, 2 May 2022 00:58:31 +0200 Subject: [PATCH 42/93] Move cocoa beans item to mcl_cocoas. * Add `mcl_cocoas:coca_beans` craftitem to mcl_cocoas. * Remove `mcl_dye:brown` craftitem from mcl_dye. * Move cocoa beans translations from mcl_dye to mcl_cocoas. * Add `mcl_dye:brown` alias for `mcl_cocoas:cocoa_beans` to mcl_dye. * Abstract cocoa pod node registration into a loop. * Update chocolate cookies crafting recipe in mcl_farming. --- mods/ITEMS/mcl_cocoas/init.lua | 225 ++++++++++-------- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.de.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.fr.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.pl.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr | 3 +- .../mcl_cocoas/locale/mcl_cocoas.zh_TW.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/template.txt | 2 +- mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr | 3 - mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr | 4 - mods/ITEMS/mcl_dye/locale/mcl_dye.ru.tr | 3 - mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr | 3 - mods/ITEMS/mcl_dye/locale/template.txt | 4 - ...as_cocoa_beans.png => mcl_cocoa_beans.png} | Bin 16 files changed, 132 insertions(+), 133 deletions(-) rename textures/{mcl_cocoas_cocoa_beans.png => mcl_cocoa_beans.png} (100%) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 0d5491bb8..dc065f0ca 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -2,29 +2,33 @@ local S = minetest.get_translator(minetest.get_current_modname()) mcl_cocoas = {} --- Place cocoa -local function cocoa_place(itemstack, placer, pt, plantname) +--- Place a cocoa pod. +-- Attempt to place a cocoa pod on a jungle tree. Checks if attachment +-- point is a jungle tree and sets the correct orientation of the stem. +-- +function mcl_cocoas.place(itemstack, placer, pt, plantname) -- check if pointing at a node if not pt or pt.type ~= "node" then return end - local under = minetest.get_node(pt.under) + local node = minetest.get_node(pt.under) -- return if any of the nodes are not registered - if not minetest.registered_nodes[under.name] then + local def = minetest.registered_nodes[node.name] + if not def then return end -- Am I right-clicking on something that has a custom on_rightclick set? if placer and not placer:get_player_control().sneak then - if minetest.registered_nodes[under.name] and minetest.registered_nodes[under.name].on_rightclick then - return minetest.registered_nodes[under.name].on_rightclick(pt.under, under, placer, itemstack) or itemstack + if def and def.on_rightclick then + return def.on_rightclick(pt.under, node, placer, itemstack) or itemstack end end -- Check if pointing at jungle tree - if under.name ~= "mcl_core:jungletree" + if node.name ~= "mcl_core:jungletree" or minetest.get_node(pt.above).name ~= "air" then return end @@ -39,9 +43,7 @@ local function cocoa_place(itemstack, placer, pt, plantname) -- Add the node, set facedir and remove 1 item from the itemstack minetest.set_node(pt.above, {name = plantname, param2 = minetest.dir_to_facedir(clickdir)}) - minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0}, true) - if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end @@ -49,117 +51,138 @@ local function cocoa_place(itemstack, placer, pt, plantname) return itemstack end --- Attempts to grow a cocoa at pos, returns true when grown, returns false if there's no cocoa --- or it is already at full size +--- Grows cocoa pod one size larger. +-- Attempts to grow a cocoa at pos, returns true when grown, returns false +-- if there's no cocoa or it is already at full size. +-- function mcl_cocoas.grow(pos) local node = minetest.get_node(pos) if node.name == "mcl_cocoas:cocoa_1" then minetest.set_node(pos, {name = "mcl_cocoas:cocoa_2", param2 = node.param2}) elseif node.name == "mcl_cocoas:cocoa_2" then minetest.set_node(pos, {name = "mcl_cocoas:cocoa_3", param2 = node.param2}) - return true + else + return false end - return false + return true end --- Cocoa definition --- 1st stage -local crop_def = { - description = S("Premature Cocoa Pod"), - _doc_items_create_entry = true, - _doc_items_longdesc = S("Cocoa pods grow on the side of jungle trees in 3 stages."), - drawtype = "mesh", - mesh = "mcl_cocoas_cocoa_stage_0.obj", - tiles = {"mcl_cocoas_cocoa_stage_0.png"}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "facedir", - walkable = true, - drop = "mcl_cocoas:cocoa_beans", - collision_box = { - type = "fixed", - fixed = { - {-0.125, -0.0625, 0.1875, 0.125, 0.25, 0.4375}, -- Pod +-- only caller was mcl_dye, now these can be local functions. +-- TODO: remove aliases, replace global functions with local functions. +local cocoa_place = mcl_cocoas.place +local cocoa_grow = mcl_cocoas.grow + +-- Cocoa pod variant definitions. +--[[ TODO: Use a mesh for cocoas for perfect texture compability. ]] +local podinfo = { + { desc = S("Premature Cocoa Pod"), + longdesc = S("Cocoa pods grow on the side of jungle trees in 3 stages."), + tiles = { + "[combine:16x16:6,1=mcl_cocoas_cocoa_stage_0.png", + "[combine:16x16:6,11=mcl_cocoas_cocoa_stage_0.png", + "mcl_cocoas_cocoa_stage_0.png", + "mcl_cocoas_cocoa_stage_0.png^[transformFX", + "[combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png", + "[combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png", }, + n_box = {-0.125, -0.0625, 0.1875, 0.125, 0.25, 0.4375}, + s_box = {-0.125, -0.0625, 0.1875, 0.125, 0.5, 0.5 }, }, - selection_box = { - type = "fixed", - fixed = { - {-0.125, -0.0625, 0.1875, 0.125, 0.5, 0.5}, -- Pod + { desc = S("Medium Cocoa Pod"), + tiles = { + "[combine:16x16:5,1=mcl_cocoas_cocoa_stage_1.png", + "[combine:16x16:5,9=mcl_cocoas_cocoa_stage_1.png", + "mcl_cocoas_cocoa_stage_1.png", + "mcl_cocoas_cocoa_stage_1.png^[transformFX", + "[combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png", + "[combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png", }, + n_box = {-0.1875, -0.1875, 0.0625, 0.1875, 0.25, 0.4375}, + s_box = {-0.1875, -0.1875, 0.0625, 0.1875, 0.5, 0.5 }, }, - groups = { - handy = 1, axey = 1, - dig_by_water=1, destroy_by_lava_flow=1, dig_by_piston=1, - attached_node_facedir=1, - not_in_creative_inventory=1, - cocoa=1 + { desc = S("Mature Cocoa Pod"), + longdesc = S("A mature cocoa pod grew on a jungle tree to its full size and it is ready to be harvested for cocoa beans. It won't grow any further."), + tiles = { + -- The following 2 textures were derived from the original + -- because the size of the top/bottom is slightly different :-( + -- TODO: Find a way to *only* use the base texture + "mcl_cocoas_cocoa_top_stage_2.png", + "mcl_cocoas_cocoa_top_stage_2.png^[transformFY", + "mcl_cocoas_cocoa_stage_2.png", + "mcl_cocoas_cocoa_stage_2.png^[transformFX", + "[combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png", + "[combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png", + }, + n_box = {-0.25, -0.3125, -0.0625, 0.25, 0.25, 0.4375}, + s_box = {-0.25, -0.3125, -0.0625, 0.25, 0.5, 0.5 }, }, - sounds = mcl_sounds.node_sound_wood_defaults(), - on_rotate = false, - _mcl_blast_resistance = 3, - _mcl_hardness = 0.2, - _mcl_on_bonemealing = function(pointed_thing, placer) - local pos = pointed_thing.under - mcl_cocoas.grow(pos) - return true +} + +for i = 1, 3 do + local def = { + description = podinfo[i].desc, + _doc_items_create_entry = true, + _doc_items_longdesc = podinfo[i].longdesc, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + tiles = podinfo[i].tiles, + use_texture_alpha = "clip", + node_box = { + type = "fixed", + fixed = { + podinfo[i].n_box, -- Pod + -- FIXME: This has a thickness of 0. Is this OK in Minetest? + { 0, 0.25, 0.25, 0, 0.5, 0.5 }, }, -- Stem + }, + collision_box = { + type = "fixed", + fixed = podinfo[i].n_box + }, + selection_box = { + type = "fixed", + fixed = podinfo[i].s_box + }, + groups = { + handy = 1, axey = 1, attached_node_facedir = 1, + dig_by_water = 1, destroy_by_lava_flow = 1, dig_by_piston = 1, + cocoa = i, not_in_creative_inventory = 1, + }, + sunlight_propagates = true, + walkable = true, + drop = "mcl_cocoas:cocoa_beans", + sounds = mcl_sounds.node_sound_wood_defaults(), + on_rotate = false, + _mcl_blast_resistance = 3, + _mcl_hardness = 0.2, + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + return cocoa_grow(pos) + end, + } + + if i == 2 then + def._doc_items_longdesc = nil + def._doc_items_create_entry = false + end + if i == 3 then + def.drop = "mcl_cocoas:cocoa_beans 3" end -} --- 2nd stage -minetest.register_node("mcl_cocoas:cocoa_1", table.copy(crop_def)) - -crop_def.description = S("Medium Cocoa Pod") -crop_def._doc_items_create_entry = false -crop_def.groups.cocoa = 2 -crop_def.mesh = "mcl_cocoas_cocoa_stage_1.obj" -crop_def.tiles = {"mcl_cocoas_cocoa_stage_1.png"} -crop_def.collision_box = { - type = "fixed", - fixed = { - {-0.1875, -0.1875, 0.0625, 0.1875, 0.25, 0.4375}, -- Pod - }, -} -crop_def.selection_box = { - type = "fixed", - fixed = { - {-0.1875, -0.1875, 0.0625, 0.1875, 0.5, 0.5}, - }, -} - -minetest.register_node("mcl_cocoas:cocoa_2", table.copy(crop_def)) - --- Final stage -crop_def.description = S("Mature Cocoa Pod") -crop_def._doc_items_longdesc = S("A mature cocoa pod grew on a jungle tree to its full size and it is ready to be harvested for cocoa beans. It won't grow any further.") -crop_def._doc_items_create_entry = true -crop_def.groups.cocoa = 3 -crop_def.mesh = "mcl_cocoas_cocoa_stage_2.obj" -crop_def.tiles = {"mcl_cocoas_cocoa_stage_2.png"} -crop_def.collision_box = { - type = "fixed", - fixed = { - {-0.25, -0.3125, -0.0625, 0.25, 0.25, 0.4375}, -- Pod - }, -} -crop_def.selection_box = { - type = "fixed", - fixed = { - {-0.25, -0.3125, -0.0625, 0.25, 0.5, 0.5}, - }, -} -crop_def.drop = "mcl_cocoas:cocoa_beans 3" -crop_def._mcl_on_bonemealing = nil -minetest.register_node("mcl_cocoas:cocoa_3", table.copy(crop_def)) + minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def)) +end minetest.register_craftitem("mcl_cocoas:cocoa_beans", { - description = S("Cocoa Beans"), + inventory_image = "mcl_cocoa_beans.png", _tt_help = S("Grows at the side of jungle trees"), - _doc_items_longdesc = S("Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye."), - _doc_items_usagehelp = S("Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa."), - inventory_image = "mcl_cocoas_cocoa_beans.png", - groups = {craftitem = 1, compostability = 65}, + _doc_items_longdesc = S("Cocoa beans can be used to plant cocoa, bake cookies or cract brown dye."), + _doc_items_usagehelp = S("Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa."), + description = S("Cocoa Beans"), + stack_max = 64, + groups = { + dye = 1, craftitem = 1, compostability = 65, + basecolor_brown = 1, excolor_orange = 1, unicolor_dark_orange = 1, + }, on_place = function(itemstack, placer, pointed_thing) return cocoa_place(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1") end, diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.de.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.de.tr index 3740c41cf..ba0eb433e 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.de.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.de.tr @@ -2,7 +2,7 @@ Cocoa Beans=Kakaobohnen Grows at the side of jungle trees=Wächst an der Seite von Dschungelbäumen Cocoa beans can be used to plant cocoa pods, bake chocolate cookies or craft brown dye.=Kakaobohnen können benutzt werden, um Kakao anzupflanzen, Kekse zu backen oder braune Farbstoffe herzustellen. -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Rechtsklicken Sie an die Seite eines Dschungelbaumstamms (Dschungelholz), um eine junge Kakaoschote zu pflanzen. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Rechtsklicken Sie auf ein Schaf, um die Wolle braun einzufärben. Rechtsklicken Sie an die Seite eines Dschungelbaumstamms (Dschungelholz), um eine junge Kakaoschote zu pflanzen. Premature Cocoa Pod=Junge Kakaoschote Cocoa pods grow on the side of jungle trees in 3 stages.=Kakaoschoten wachsen an der Seite von Dschungelbäumen in 3 Stufen. Medium Cocoa Pod=Mittelgroße Kakaoschote diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr index c76fc512f..c110a1a9a 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr @@ -2,7 +2,7 @@ Cocoa Beans=Granos de cacao Grows at the side of jungle trees=Crece al lado de los árboles de la jungla Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Los granos de cacao se pueden usar para plantar cacao, hornear galletas o hacer tintes marrones. -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en el costado del tronco de un árbol de la jungla para plantar un cacao joven. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en una oveja para convertir su lana en marrón. Haga clic derecho en el costado del tronco de un árbol de jungla para plantar un cacao joven. Premature Cocoa Pod=Vaina de cacao prematura Cocoa pods grow on the side of jungle trees in 3 stages.=Las vainas de cacao crecen al lado de los árboles de jungla en 3 etapas. Medium Cocoa Pod=Vaina de cacao mediana diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.fr.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.fr.tr index 5d64eb5be..2cd11dc93 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.fr.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.fr.tr @@ -2,7 +2,7 @@ Cocoa Beans=Fèves de Cacao Grows at the side of jungle trees=Pousse à côté des arbres de la jungle Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Les fèves de cacao peuvent être utilisées pour planter du cacao, faire des biscuits ou fabriquer de la teinture brune. -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Clic droit sur le côté d'un tronc d'arbre de la jungle (Bois Acajou) pour planter un jeune cacaoyer. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Faites un clic droit sur un mouton pour brunir sa laine. Clic droit sur le côté d'un tronc d'arbre de la jungle (Bois Acajou) pour planter un jeune cacao. Premature Cocoa Pod=Gousse de cacao prématurée Cocoa pods grow on the side of jungle trees in 3 stages.=Les cabosses de cacao poussent sur le côté des arbres d'Acajou en 3 étapes. Medium Cocoa Pod=Gousse de cacao moyenne diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.pl.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.pl.tr index 83df9be7a..5e33ca727 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.pl.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.pl.tr @@ -2,7 +2,7 @@ Cocoa Beans=Ziarna kakaowe Grows at the side of jungle trees=Rośnie na boku tropikalnych drzew Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Ziarna kakaowe mogą być używane do sadzenia kakao, pieczenia ciasteczek lub robienia brązowego barwnika. -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Naciśnij prawym na boku tropikalnego pnia (Tropikalne drewno) aby zasadzić młode kakao. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Naciśnij prawym aby zafarbować wełnę owcy na brązowo. Naciśnij prawym na boku tropikalnego pnia (Tropikalne drewno) aby zasadzić młode kakao. Premature Cocoa Pod=Niedojrzała roślina kakao Cocoa pods grow on the side of jungle trees in 3 stages.=Roślina kakao rośnie na bokach tropikalnych drzew w 3 etapach Medium Cocoa Pod=Średnio-dojrzała roślina kakao diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr index acce2fa83..2e36baadb 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr @@ -2,7 +2,8 @@ Cocoa Beans=Какао-бобы Grows at the side of jungle trees=Растут на стволах тропических деревьев Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Какао-бобы можно использовать для посадки какао, выпечки печенья или изготовления коричневого красителя. -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по боковой части ствола тропического дерева, чтобы посадить молодое какао. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по овце, чтобы сделать её шерсть коричневой. Кликните правой по боковой части ствола дерева джунглей, что +>>>>>>> 195f0dfba (Move cocoa beans item to mcl_cocoas.) Premature Cocoa Pod=Молодой стручок какао Cocoa pods grow on the side of jungle trees in 3 stages.=Стручки какао растут на деревьях джунглей в 3 этапа. Medium Cocoa Pod=Средний стручок какао diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.zh_TW.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.zh_TW.tr index 038746155..d7eec03bc 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.zh_TW.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.zh_TW.tr @@ -2,7 +2,7 @@ Cocoa Beans=可可豆 Grows at the side of jungle trees=在叢林木側生長 Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=可可豆可用於種植可可、烘烤餅乾或製作棕色染料。 -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=右鍵點擊叢林木的一側,可以種植一個可可。 +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=右鍵點擊一隻羊,使其羊毛變成褐色。右鍵點擊叢林木的一側,可以種植一個可可。 Premature Cocoa Pod=成長中的可可豆莢(第1階段) Cocoa pods grow on the side of jungle trees in 3 stages.=可可莢果分3個階段生長在叢林樹的側面。 Medium Cocoa Pod=成長中的可可豆莢(第2階段) diff --git a/mods/ITEMS/mcl_cocoas/locale/template.txt b/mods/ITEMS/mcl_cocoas/locale/template.txt index cb8c5bbfd..06d6e2480 100644 --- a/mods/ITEMS/mcl_cocoas/locale/template.txt +++ b/mods/ITEMS/mcl_cocoas/locale/template.txt @@ -2,7 +2,7 @@ Cocoa Beans= Grows at the side of jungle trees= Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.= -Right click on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.= +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.= Premature Cocoa Pod= Cocoa pods grow on the side of jungle trees in 3 stages.= Medium Cocoa Pod= diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr index a2769934a..2069d4d76 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.de.tr @@ -17,7 +17,3 @@ Magenta Dye=Magenta Farbstoff Pink Dye=Rosa Farbstoff This item is a dye which is used for dyeing and crafting.=Dieser Gegenstand ist ein Farbstoff, der zum Einfärben und in der Herstellung benutzt werden kann. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Rechtsklicken Sie auf ein Schaf, um seine Wolle zu färben. Andere Dinge werden mit der Fertigung eingefärbt. -Cocoa beans are a brown dye and can be used to plant cocoas.=Kakaobohnen sind ein brauner Farbstoff und werden benutzt, um Kakao anzupflanzen. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Rechtsklicken Sie auf ein Schaf, um die Wolle braun einzufärben. Rechtsklicken Sie an die Seite eines Dschungelbaumstamms (Dschungelholz), um eine junge Kakaoschote zu pflanzen. -Cocoa Beans=Kakaobohnen -Grows at the side of jungle trees=Wächst an der Seite von Dschungelbäumen diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr index e363a63b5..542e367f9 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.es.tr @@ -17,6 +17,3 @@ Magenta Dye=Tinte magenta Pink Dye=Tinte rosado This item is a dye which is used for dyeing and crafting.=Este artículo es un tinte que se utiliza para teñir y elaborar. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Haga clic derecho sobre una oveja para teñir su lana. Otras cosas pueden ser teñidas mediante la elaboración. -Cocoa beans are a brown dye and can be used to plant cocoas.=Los granos de cacao son un tinte marrón y se pueden usar para plantar cacao. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en una oveja para convertir su lana en marrón. Haga clic derecho en el costado del tronco de un árbol de jungla para plantar un cacao joven. -Cocoa Beans=Granos de cacao diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr index efb8d5bb9..eddd5edf4 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.fr.tr @@ -17,7 +17,3 @@ Magenta Dye=Teinture Magenta Pink Dye=Teinture Rose This item is a dye which is used for dyeing and crafting.=Cet objet est un colorant utilisé pour la teinture et l'artisanat. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Clic droit sur un mouton pour teindre sa laine. D'autres choses sont teintes par l'artisanat. -Cocoa beans are a brown dye and can be used to plant cocoas.=Les fèves de cacao ont une teinture brune et peuvent être utilisées pour planter du cacao. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Faites un clic droit sur un mouton pour brunir sa laine. Clic droit sur le côté d'un tronc d'arbre de la jungle (Bois Acajou) pour planter un jeune cacao. -Cocoa Beans=Fèves de Cacao -Grows at the side of jungle trees=Pousse à côté des arbres de la jungle diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr index ae8d00641..c665b2b43 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.pl.tr @@ -17,7 +17,3 @@ Magenta Dye=Karmazynowa farba Pink Dye=Różowa farba This item is a dye which is used for dyeing and crafting.=Ten przedmiot to farba wykorzystywana to farbowania i wytwarzania. Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=Kliknij prawym na owcę aby zafarbować jej wełnę. Inne rzeczy mogą być zafarbowane przy wytwarzaniu. -Cocoa beans are a brown dye and can be used to plant cocoas.=Ziarna kakaowe mogą być wykorzystane do sadzenia kakao. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Naciśnij prawym aby zafarbować wełnę owcy na brązowo. Naciśnij prawym na boku tropikalnego pnia (Tropikalne drewno) aby zasadzić młode kakao. -Cocoa Beans=Ziarna kakaowe -Grows at the side of jungle trees=Rośnie na boku tropikalnych drzew diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.ru.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.ru.tr index d595bb6a1..fa1d031c4 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.ru.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.ru.tr @@ -22,6 +22,3 @@ Bone meal is a white dye and also useful as a fertilizer to speed up the growth Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Кликните правой по овце, чтобы сделать её шерсть белой. Кликните правой по растению, чтобы ускорить его рост. Имейте в виду, что не все растения можно удобрять таким способом. Если вы кликнете по травяному блоку, то на этом месте вырастет высокая трава и цветы. Cocoa beans are a brown dye and can be used to plant cocoas.=Какао-бобы являются коричневым красителем. Их также можно использовать, чтобы посадить какао. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по овце, чтобы сделать её шерсть коричневой. Кликните правой по боковой части ствола тропического дерева, чтобы посадить молодое какао. -Cocoa Beans=Какао-бобы -Grows at the side of jungle trees=Растут на стволах тропических деревьев -Speeds up plant growth=Ускоряет рост растений diff --git a/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr b/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr index 4552c5ce5..7ea308119 100644 --- a/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr +++ b/mods/ITEMS/mcl_dye/locale/mcl_dye.zh_TW.tr @@ -17,6 +17,3 @@ Magenta Dye=洋紅色染料 Pink Dye=粉紅色染料 This item is a dye which is used for dyeing and crafting.=這個物品是一種用於染色和合成的染料。 Rightclick on a sheep to dye its wool. Other things are dyed by crafting.=右鍵單擊綿羊以染它的毛。其他東西是通過合成染色的。 -Cocoa beans are a brown dye and can be used to plant cocoas.=可可豆是一種棕色染料,也可用於種植可可。 -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=右鍵點擊一隻羊,使其羊毛變成褐色。右鍵點擊叢林木的一側,可以種植一個可可。 -Grows at the side of jungle trees=在叢林木側生長 diff --git a/mods/ITEMS/mcl_dye/locale/template.txt b/mods/ITEMS/mcl_dye/locale/template.txt index 123df4514..e07f6ef54 100644 --- a/mods/ITEMS/mcl_dye/locale/template.txt +++ b/mods/ITEMS/mcl_dye/locale/template.txt @@ -17,7 +17,3 @@ Magenta Dye= Pink Dye= This item is a dye which is used for dyeing and crafting.= Rightclick on a sheep to dye its wool. Other things are dyed by crafting.= -Cocoa beans are a brown dye and can be used to plant cocoas.= -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.= -Cocoa Beans= -Grows at the side of jungle trees= diff --git a/textures/mcl_cocoas_cocoa_beans.png b/textures/mcl_cocoa_beans.png similarity index 100% rename from textures/mcl_cocoas_cocoa_beans.png rename to textures/mcl_cocoa_beans.png From e5cf4bd225ac726c686b962723b490f57b6a0f05 Mon Sep 17 00:00:00 2001 From: kabou Date: Tue, 3 May 2022 13:29:37 +0200 Subject: [PATCH 43/93] Add missing es translation to mcl_bone_meal. --- mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr index 267f244bb..4d991624f 100644 --- a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr @@ -2,3 +2,4 @@ Bone Meal=Harina de hueso Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La harina de hueso es un tinte blanco y también es útil como fertilizante para acelerar el crecimiento de muchas plantas. Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=RHaga clic derecho en una oveja para volver su lana blanca. Haga clic derecho en una planta para acelerar su crecimiento. Tenga en cuenta que no todas las plantas pueden ser fertilizadas de esta manera. Cuando haces clic derecho en un bloque de hierba, crecerán hierba alta y flores por todo el lugar. +Speeds up plant growth=Acelera el crecimiento de las plantas From c2c7df820fe61e9d589c6df12bdc03608f2c6804 Mon Sep 17 00:00:00 2001 From: kabou Date: Tue, 3 May 2022 15:05:10 +0200 Subject: [PATCH 44/93] Improve mcl_bone_meal fr translations. * Changed the wording after suggestions by AFCMS. --- mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr index 5cb6c42b6..61df77d59 100644 --- a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr @@ -1,5 +1,6 @@ # textdomain: mcl_bone_meal Bone Meal=Farine d'Os -Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La farine d'os est une teinture blanche et également utile comme engrais pour accélérer la croissance de nombreuses plantes. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Notez que toutes les plantes ne peuvent pas être fertilisées comme ça. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent partout. +Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La farine d'os est une teinture blanche et est également utile comme engrais pour accélérer la croissance de nombreuses plantes. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.= +Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Cependant, toutes les plantes ne peuvent pas être fertilisées de cette manière. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent autour. Speeds up plant growth=Accélère la croissance des plantes From 8acddab74f42d9b170c4a519e9f7e7505ef844d6 Mon Sep 17 00:00:00 2001 From: kabou Date: Wed, 4 May 2022 12:17:51 +0200 Subject: [PATCH 45/93] Bonemealing mechanics bugfix. When applying bonemeal to eg. farm crops, these have a chance to grow in response to the application of bone meal. When a node can be bonemealed, the applied bone meal item should always be spent after using it, regardless of the results. Currently this does not work correctly, if the result of bonemealing has no effect on the node, the used bone meal item is not spent. This commit fixes the behavior of the bone meal item to always be taken when used on a node that defines a `_mcl_on_bonemealing()` callback. The nodes that implement the callback imay use the handler's return value only to signal if the bonemealing was succesful, not to signal if it was at all possible. For this reason, some nodes need to be made more strictly conforming to the API. * Always take the used bone meal item (if user is not in creative mode), regardless of whether the bonemealed node's handler returned `true`. * Make dispensers spawn particles after succesful bonemealing. * Trivial comment fix. * Ripe cocoa pod cannot be bonemealed. * Update API.md to describe the stricter API semantics. --- mods/ITEMS/mcl_bone_meal/API.md | 19 ++++++++++++++----- mods/ITEMS/mcl_bone_meal/init.lua | 11 ++++++----- mods/ITEMS/mcl_cocoas/init.lua | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/API.md b/mods/ITEMS/mcl_bone_meal/API.md index f0402aae3..46a28fadb 100644 --- a/mods/ITEMS/mcl_bone_meal/API.md +++ b/mods/ITEMS/mcl_bone_meal/API.md @@ -8,7 +8,17 @@ The bone meal API provides a callback definition that nodes can use to register a handler that is executed when a bone meal item is used on it. Nodes that wish to use the bone meal API should in their node registration -define a callback handler named `_mcl_on_bonemealing`. This handler is a +define a callback handler named `_mcl_on_bonemealing`. + +Note that by registering the callback handler, the node declares that bone +meal can be used on it and as a result, when the user is not in creative +mode, the used bone meal is spent and taken from the itemstack passed to +the `on_place()` handler of the bone meal item used. + +It is for all intents and purposes up to the callback defined in the node to +decide how to handle the specific effect that bone meal has on that node. + +The `_mcl_on_bonemealing` callback handler is a `function(pointed_thing, placer)` @@ -17,10 +27,9 @@ Its arguments are: bone meal is applied * `placer`: ObjectRef of the player who aplied the bone meal, can be nil! -The function should return `true` if the bonemealing was succesful. - -It is for all intents and purposes up to the callback defined in the node to -decide how to handle the effect that bone meal has on that particular node. +The return value of the handler function indicates if the bonemealing had +its intended effect. If `true`, 'bone meal particles' are spawned at the +position of the bonemealed node. The `on_place` code in the bone meal item will spawn bone meal particles and decrease the bone meal itemstack if the handler returned `true` and the diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index a5487d57e..8898b9e5a 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -49,7 +49,7 @@ end -- mcl_bone_meal.bone_meal_callbacks = {} --- Shims for the old API are still available in mcl_dye and refer to +-- Shims for the old API are still available in mcl_dye and defer to -- the real functions in mcl_bone_meal. -- function mcl_bone_meal.register_on_bone_meal_apply(func) @@ -117,9 +117,9 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", { if ndef and ndef._mcl_on_bonemealing then if ndef._mcl_on_bonemealing(pointed_thing, placer) then mcl_bone_meal.add_bone_meal_particle(pos) - if not minetest.is_creative_enabled(placer:get_player_name()) then - itemstack:take_item() - end + end + if not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() end -- Otherwise try the legacy API. elseif apply_bone_meal(pointed_thing, placer) and @@ -140,8 +140,9 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", { -- If the pointed node can be bonemealed, let it handle the processing. if ndef and ndef._mcl_on_bonemealing then if ndef._mcl_on_bonemealing(pointed_thing, nil) then - itemstack:take_item() + mcl_bone_meal.add_bone_meal_particle(pos) end + itemstack:take_item() else -- Otherwise try the legacy API. if apply_bone_meal(pointed_thing, nil) then diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index dc065f0ca..726c72feb 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -167,6 +167,7 @@ for i = 1, 3 do end if i == 3 then def.drop = "mcl_cocoas:cocoa_beans 3" + def._mcl_on_bonemealing = nil end minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def)) From 7938fba4a5fd2ddeca0ea81d2f06b3df7472fac1 Mon Sep 17 00:00:00 2001 From: kabou Date: Wed, 4 May 2022 13:50:52 +0200 Subject: [PATCH 46/93] Remove expired bone meal API.md from mcl_dye. --- mods/ITEMS/mcl_dye/API.md | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 mods/ITEMS/mcl_dye/API.md diff --git a/mods/ITEMS/mcl_dye/API.md b/mods/ITEMS/mcl_dye/API.md deleted file mode 100644 index 04169f966..000000000 --- a/mods/ITEMS/mcl_dye/API.md +++ /dev/null @@ -1,14 +0,0 @@ -# mcl_dye - -# Bone meal API -Callback and particle functions. - -## mcl_dye.add_bone_meal_particle(pos, def) -Spawns standard or custom bone meal particles. -* `pos`: position, is ignored if you define def.minpos and def.maxpos -* `def`: (optional) particle definition - -## mcl_dye.register_on_bone_meal_apply(function(pointed_thing, user)) -Called when the bone meal is applied anywhere. -* `pointed_thing`: exact pointing location (see Minetest API), where the bone meal is applied -* `user`: ObjectRef of the player who aplied the bone meal, can be nil! \ No newline at end of file From ba1e0e4301b9810b7b0654841e77163c40768e84 Mon Sep 17 00:00:00 2001 From: kabou Date: Wed, 4 May 2022 14:55:19 +0200 Subject: [PATCH 47/93] Also generate double grass when bonemealing grass blocks. --- mods/ITEMS/mcl_flowers/bonemealing.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index 297c297e8..26fc8a44c 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -71,8 +71,18 @@ local biome_flowers_tables = { -- local function add_random_flower(pos, color) -- 90% tall grass, 10% flower - if math.random(1,100) <= 90 then + local rnd = math.random(1,100) + if rnd <= 60 then minetest.add_node(pos, {name="mcl_flowers:tallgrass", param2=color}) + elseif rnd <= 80 then + -- double tallgrass + local toppos = vector.offset(pos, 0, 1, 0) + local topnode = minetest.get_node(toppos) + if minetest.registered_nodes[topnode.name].buildable_to then + minetest.set_node(pos, { name = "mcl_flowers:double_grass", param2 = color }) + minetest.set_node(toppos, { name = "mcl_flowers:double_grass_top", param2 = color }) + return true + end else local flowers_table if mg_name == "v6" then From 4449f747425c29c9907d5793e6679d684899d73c Mon Sep 17 00:00:00 2001 From: kabou Date: Thu, 5 May 2022 13:51:05 +0200 Subject: [PATCH 48/93] Remove color specifications from cocoa beans. * The cocoa beans craftitem definition still had color specifications from its past as a dye substitute. These can be removed now. --- mods/ITEMS/mcl_cocoas/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 726c72feb..d23c06a7e 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -181,8 +181,7 @@ minetest.register_craftitem("mcl_cocoas:cocoa_beans", { description = S("Cocoa Beans"), stack_max = 64, groups = { - dye = 1, craftitem = 1, compostability = 65, - basecolor_brown = 1, excolor_orange = 1, unicolor_dark_orange = 1, + craftitem = 1, compostability = 65, }, on_place = function(itemstack, placer, pointed_thing) return cocoa_place(itemstack, placer, pointed_thing, "mcl_cocoas:cocoa_1") From f61a7ab4cb7e4f4b5c14efa8015717b5e933e68e Mon Sep 17 00:00:00 2001 From: kabou Date: Thu, 5 May 2022 13:58:12 +0200 Subject: [PATCH 49/93] Remove color specifications from bone meal. * The bone meal craftitem definition still had color specifications from its past as a dye substitute. These can be removed now. * Also remove default stack_max setting. --- mods/ITEMS/mcl_bone_meal/init.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 8898b9e5a..e989d47f1 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -96,13 +96,12 @@ end -- End legacy bone meal API minetest.register_craftitem("mcl_bone_meal:bone_meal", { - inventory_image = "mcl_bone_meal.png", description = S("Bone Meal"), _tt_help = S("Speeds up plant growth"), _doc_items_longdesc = longdesc, _doc_items_usagehelp = usagehelp, - stack_max = 64, - groups = {craftitem=1, dye=1, basecolor_white=1, excolor_white=1, unicolor_white=1}, + inventory_image = "mcl_bone_meal.png", + groups = {craftitem=1}, on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local node = minetest.get_node(pos) From 5b1fcf76f6f5d1f4255bc0b82a87243c21ec25ed Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 19 Mar 2024 07:12:04 +0000 Subject: [PATCH 50/93] Fix mod dependencies --- mods/ITEMS/mcl_beds/mod.conf | 2 +- mods/ITEMS/mcl_signs/mod.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_beds/mod.conf b/mods/ITEMS/mcl_beds/mod.conf index fc6d54f1f..fd54cd7e1 100644 --- a/mods/ITEMS/mcl_beds/mod.conf +++ b/mods/ITEMS/mcl_beds/mod.conf @@ -2,4 +2,4 @@ name = mcl_beds author = BlockMen description = depends = playerphysics -optional_depends = mcl_sounds, mcl_worlds, mcl_wool, mcl_dye, mcl_explosions, mcl_weather, mcl_spawn, doc, mesecons \ No newline at end of file +optional_depends = mcl_sounds, mcl_worlds, mcl_wool, mcl_dye, mcl_explosions, mcl_weather, mcl_spawn, doc, mesecons, mesecons_mvps diff --git a/mods/ITEMS/mcl_signs/mod.conf b/mods/ITEMS/mcl_signs/mod.conf index e2fe9d40a..878d8d2f7 100644 --- a/mods/ITEMS/mcl_signs/mod.conf +++ b/mods/ITEMS/mcl_signs/mod.conf @@ -1,4 +1,4 @@ name = mcl_signs description = New and Improved signs - can be colored and made to glow. -depends = mcl_core, mcl_sounds, mcl_dye, mcl_colors, mcl_util +depends = mcl_core, mcl_sounds, mcl_dye, mcl_colors, mcl_util, mesecons_mvps optional_depends = doc From f44102c23838f4b42a42fd4920320ac612de178b Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 19 Mar 2024 07:12:42 +0000 Subject: [PATCH 51/93] Display call stack to assist in removing deprecated function calls --- mods/ITEMS/mcl_bone_meal/init.lua | 1 + mods/ITEMS/mcl_dye/init.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index e989d47f1..a32f2d253 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -54,6 +54,7 @@ mcl_bone_meal.bone_meal_callbacks = {} -- function mcl_bone_meal.register_on_bone_meal_apply(func) minetest.log("warning", "register_on_bone_meal_apply(func) is deprecated. Read mcl_bone_meal/API.md!") + print(debug.traceback()) table.insert(mcl_bone_meal.bone_meal_callbacks, func) end diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 40f75e252..b8c5dbf26 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -119,6 +119,7 @@ end -- function mcl_dye.add_bone_meal_particle(pos, def) minetest.log("warning", "mcl_dye.add_bone_meal_particles() is deprecated. Read mcl_bone_meal/API.md!") + print(debug.traceback()) mcl_bone_meal.add_bone_meal_particle(pos, def) end From 1e0f7618ba292bdba7dac43839a0157cc9374f5a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 19 Mar 2024 07:25:04 +0000 Subject: [PATCH 52/93] Remove bone meal definition in mcl_dye, make textures in mcl_cocoas match master branch --- mods/ITEMS/mcl_cocoas/init.lua | 18 -------------- mods/ITEMS/mcl_dye/init.lua | 43 ---------------------------------- 2 files changed, 61 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index d23c06a7e..91026ce83 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -78,24 +78,14 @@ local podinfo = { { desc = S("Premature Cocoa Pod"), longdesc = S("Cocoa pods grow on the side of jungle trees in 3 stages."), tiles = { - "[combine:16x16:6,1=mcl_cocoas_cocoa_stage_0.png", - "[combine:16x16:6,11=mcl_cocoas_cocoa_stage_0.png", "mcl_cocoas_cocoa_stage_0.png", - "mcl_cocoas_cocoa_stage_0.png^[transformFX", - "[combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png", - "[combine:16x16:-5,0=mcl_cocoas_cocoa_stage_0.png", }, n_box = {-0.125, -0.0625, 0.1875, 0.125, 0.25, 0.4375}, s_box = {-0.125, -0.0625, 0.1875, 0.125, 0.5, 0.5 }, }, { desc = S("Medium Cocoa Pod"), tiles = { - "[combine:16x16:5,1=mcl_cocoas_cocoa_stage_1.png", - "[combine:16x16:5,9=mcl_cocoas_cocoa_stage_1.png", "mcl_cocoas_cocoa_stage_1.png", - "mcl_cocoas_cocoa_stage_1.png^[transformFX", - "[combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png", - "[combine:16x16:-4,0=mcl_cocoas_cocoa_stage_1.png", }, n_box = {-0.1875, -0.1875, 0.0625, 0.1875, 0.25, 0.4375}, s_box = {-0.1875, -0.1875, 0.0625, 0.1875, 0.5, 0.5 }, @@ -103,15 +93,7 @@ local podinfo = { { desc = S("Mature Cocoa Pod"), longdesc = S("A mature cocoa pod grew on a jungle tree to its full size and it is ready to be harvested for cocoa beans. It won't grow any further."), tiles = { - -- The following 2 textures were derived from the original - -- because the size of the top/bottom is slightly different :-( - -- TODO: Find a way to *only* use the base texture - "mcl_cocoas_cocoa_top_stage_2.png", - "mcl_cocoas_cocoa_top_stage_2.png^[transformFY", "mcl_cocoas_cocoa_stage_2.png", - "mcl_cocoas_cocoa_stage_2.png^[transformFX", - "[combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png", - "[combine:16x16:-3,0=mcl_cocoas_cocoa_stage_2.png", }, n_box = {-0.25, -0.3125, -0.0625, 0.25, 0.25, 0.4375}, s_box = {-0.25, -0.3125, -0.0625, 0.25, 0.5, 0.5 }, diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index b8c5dbf26..4836435fc 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -128,49 +128,6 @@ function mcl_dye.register_on_bone_meal_apply(func) mcl_bone_meal.register_on_bone_meal_apply(func) end --- Bone meal item registration. --- --- To be moved into its own mod. --- -minetest.register_craftitem(":mcl_bone_meal:bone_meal", { - inventory_image = "mcl_bone_meal_bone_meal.png", - description = S("Bone Meal"), - _tt_help = S("Speeds up plant growth"), - _doc_items_longdesc = S("Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants."), - _doc_items_usagehelp = S("Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place."), - stack_max = 64, - on_place = function(itemstack, user, pointed_thing) - -- Use pointed node's on_rightclick function first, if present - local node = minetest.get_node(pointed_thing.under) - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack - end - end - - -- Use the bone meal on the ground - if (apply_bone_meal(pointed_thing, user) and (not minetest.is_creative_enabled(user:get_player_name()))) then - itemstack:take_item() - end - return itemstack - end, - _on_dispense = function(stack, pos, droppos, dropnode, dropdir) - -- Apply bone meal, if possible - local pointed_thing - if dropnode.name == "air" then - pointed_thing = { above = droppos, under = { x=droppos.x, y=droppos.y-1, z=droppos.z } } - else - pointed_thing = { above = pos, under = droppos } - end - local success = apply_bone_meal(pointed_thing, nil) - if success then - stack:take_item() - end - return stack - end, - _dispense_into_walkable = true -}) - minetest.register_craft({ output = "mcl_bone_meal:bone_meal 3", recipe = {{"mcl_mobitems:bone"}}, From a4f1ccd0eef57b612529e4ea38892466f6ca22c9 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 19 Mar 2024 07:57:58 +0000 Subject: [PATCH 53/93] Update mcl_crimson to use bonemealing API --- mods/ITEMS/mcl_crimson/init.lua | 72 +++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 9ec326a3c..1d4194e60 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -83,17 +83,20 @@ minetest.register_node("mcl_crimson:warped_fungus", { light_source = 1, sounds = mcl_sounds.node_sound_leaves_defaults(), node_placement_prediction = "", - on_rightclick = function(pos, node, pointed_thing, player, itemstack) - if pointed_thing:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - local nodepos = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}) - if nodepos.name == "mcl_crimson:warped_nylium" or nodepos.name == "mcl_nether:netherrack" then - local random = math.random(1, 5) - if random == 1 then - minetest.remove_node(pos) - generate_warped_tree(pos) - end + _mcl_on_bonemealing = function(pointed_thing, player) + local pos = pointed_thing.under + local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) + + if nodepos.name == "mcl_crimson:warped_nylium" or nodepos.name == "mcl_nether:netherrack" then + local random = math.random(1, 5) + if random == 1 then + minetest.remove_node(pos) + generate_warped_tree(pos) + return true end end + + return false end, _mcl_blast_resistance = 0, }) @@ -102,6 +105,12 @@ mcl_flowerpots.register_potted_flower("mcl_crimson:warped_fungus", { name = "warped_fungus", desc = S("Warped Fungus"), image = "mcl_crimson_warped_fungus.png", + _mcl_on_bonemealing = function(pt,user) + local n = has_nylium_neighbor(pt.under) + if n then + minetest.set_node(pt.under,n) + end + end, }) minetest.register_node("mcl_crimson:twisting_vines", { @@ -393,6 +402,11 @@ minetest.register_node("mcl_crimson:warped_nylium", { _mcl_hardness = 0.4, _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, + _mcl_on_bonemealing = function(pt,user) + local node = minetest.get_node(pt.under) + spread_nether_plants(pt.under,node) + return true + end, }) --Stem bark, stripped stem and bark @@ -525,17 +539,21 @@ minetest.register_node("mcl_crimson:crimson_fungus", { fixed = { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 }, }, node_placement_prediction = "", - on_rightclick = function(pos, node, pointed_thing, player) - if pointed_thing:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) - if nodepos.name == "mcl_crimson:crimson_nylium" or nodepos.name == "mcl_nether:netherrack" then - local random = math.random(1, 5) - if random == 1 then - minetest.remove_node(pos) - generate_crimson_tree(pos) - end + _mcl_on_bonemealing = function(pointed_thing, player) + local pos = pointed_thing.under + local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) + if nodepos.name == "mcl_crimson:crimson_nylium" or nodepos.name == "mcl_nether:netherrack" then + local random = math.random(1, 5) + if random == 1 then + minetest.remove_node(pos) + generate_crimson_tree(pos) + + return true end end + + -- Failed to spread nylium + return false end, _mcl_blast_resistance = 0, }) @@ -682,6 +700,11 @@ minetest.register_node("mcl_crimson:crimson_nylium", { _mcl_hardness = 0.4, _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, + _mcl_on_bonemealing = function(pt,user) + local node = minetest.get_node(pt.under) + spread_nether_plants(pt.under,node) + return true + end, }) minetest.register_craft({ @@ -723,19 +746,6 @@ minetest.register_craft({ mcl_stairs.register_stair("crimson_hyphae_wood", "mcl_crimson:crimson_hyphae_wood", wood_stair_groups, false, S("Crimson Stair")) mcl_stairs.register_slab("crimson_hyphae_wood", "mcl_crimson:crimson_hyphae_wood", wood_slab_groups, false, S("Crimson Slab")) -mcl_dye.register_on_bone_meal_apply(function(pt,user) - if not pt.type == "node" then return end - local node = minetest.get_node(pt.under) - if node.name == "mcl_nether:netherrack" then - local n = has_nylium_neighbor(pt.under) - if n then - minetest.set_node(pt.under,n) - end - elseif node.name == "mcl_crimson:warped_nylium" or node.name == "mcl_crimson:crimson_nylium" then - spread_nether_plants(pt.under,node) - end -end) - minetest.register_abm({ label = "Turn Crimson Nylium and Warped Nylium below solid block into Netherrack", nodenames = {"mcl_crimson:crimson_nylium","mcl_crimson:warped_nylium"}, From d5684ca305be400c29091ae647ba216232a96362 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 20 Mar 2024 07:42:29 +0000 Subject: [PATCH 54/93] Add new API call mcl_bone_meal.use_bone_meal and use this to remove duplicate code, update mcl_farming:sweet_berries to use bonemeal API, add stub for bonemeal mod compatibility --- mods/ITEMS/mcl_bone_meal/API.md | 9 +++ mods/ITEMS/mcl_bone_meal/init.lua | 82 ++++++++++++-------------- mods/ITEMS/mcl_farming/sweet_berry.lua | 30 ++++++++-- mods/MISC/bonemeal/init.lua | 0 mods/MISC/bonemeal/mod.conf | 4 ++ 5 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 mods/MISC/bonemeal/init.lua create mode 100644 mods/MISC/bonemeal/mod.conf diff --git a/mods/ITEMS/mcl_bone_meal/API.md b/mods/ITEMS/mcl_bone_meal/API.md index 46a28fadb..a404d29a9 100644 --- a/mods/ITEMS/mcl_bone_meal/API.md +++ b/mods/ITEMS/mcl_bone_meal/API.md @@ -42,6 +42,15 @@ Spawns standard or custom bone meal particles. * `def`: (optional) particle definition; see minetest.add_particlespawner() for more details. +## mcl_bone_meal.use_bone_meal(itemstack, placer, pointed_thing) +For use in on_rightclick handlers that need support bone meal processing in addition +to other behaviors. Before calling, verify that the player is wielding bone meal. +* `itemstack`: The stack of bone meal being used +* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! +* `pointed_thing`: exact pointing location (see Minetest API), where the + bone meal is applied + +Returns itemstack with one bone meal consumed if not in creative mode. # Legacy API The bone meal API also provides a legacy compatibility function. This diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index a32f2d253..23c66ea98 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -60,26 +60,14 @@ end -- Legacy registered users of the old API are handled through this function. -- -local function apply_bone_meal(pointed_thing, placer) +local function legacy_apply_bone_meal(pointed_thing, placer) + -- Legacy API support for _, func in pairs(mcl_bone_meal.bone_meal_callbacks) do if func(pointed_thing, placer) then return true end end - local pos = pointed_thing.under - local n = minetest.get_node(pos) - if n.name == "" then return false end - - -- Wheat, Potato, Carrot, Pumpkin Stem, Melon Stem: Advance by 2-5 stages - if string.find(n.name, "mcl_farming:sweet_berry_bush_") then - mcl_dye.add_bone_meal_particle(pos) - 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, 0, true) - end - return true --[[ Here for when Bonemeal becomes an api, there's code if needed for handling applying to bamboo. -- Handle applying bonemeal to bamboo. @@ -90,12 +78,42 @@ local function apply_bone_meal(pointed_thing, placer) end return success --]] - end return false end -- End legacy bone meal API +mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) + local pos = pointed_thing.under + + -- Check protection + if mcl_util.check_area_protection(pos, pointed_thing.above, placer) then return false end + + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local success = false + + -- If the pointed node can be bonemealed, let it handle the processing. + if ndef and ndef._mcl_on_bonemealing then + success = ndef._mcl_on_bonemealing(pointed_thing, placer) + else + -- Otherwise try the legacy API. + success = legacy_apply_bone_meal(pointed_thing, placer) + end + + -- Particle effects + if success then + mcl_bone_meal.add_bone_meal_particle(pos) + end + + -- Take the item + if not placer or not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() + end + + return itemstack +end + minetest.register_craftitem("mcl_bone_meal:bone_meal", { description = S("Bone Meal"), _tt_help = S("Speeds up plant growth"), @@ -107,26 +125,15 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", { local pos = pointed_thing.under local node = minetest.get_node(pos) local ndef = minetest.registered_nodes[node.name] + -- Use pointed node's on_rightclick function first, if present. if placer and not placer:get_player_control().sneak then if ndef and ndef.on_rightclick then return ndef.on_rightclick(pos, node, placer, itemstack, pointed_thing) or itemstack end end - -- If the pointed node can be bonemealed, let it handle the processing. - if ndef and ndef._mcl_on_bonemealing then - if ndef._mcl_on_bonemealing(pointed_thing, placer) then - mcl_bone_meal.add_bone_meal_particle(pos) - end - if not minetest.is_creative_enabled(placer:get_player_name()) then - itemstack:take_item() - end - -- Otherwise try the legacy API. - elseif apply_bone_meal(pointed_thing, placer) and - not minetest.is_creative_enabled(placer:get_player_name()) then - itemstack:take_item() - end - return itemstack + + return mcl_bone_meal.use_bone_meal(itemstack, placer, pointed_thing) end, _on_dispense = function(itemstack, pos, droppos, dropnode, dropdir) local pointed_thing @@ -135,21 +142,8 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", { else pointed_thing = {above = pos, under = droppos} end - local node = minetest.get_node(pointed_thing.under) - local ndef = minetest.registered_nodes[node.name] - -- If the pointed node can be bonemealed, let it handle the processing. - if ndef and ndef._mcl_on_bonemealing then - if ndef._mcl_on_bonemealing(pointed_thing, nil) then - mcl_bone_meal.add_bone_meal_particle(pos) - end - itemstack:take_item() - else - -- Otherwise try the legacy API. - if apply_bone_meal(pointed_thing, nil) then - itemstack:take_item() - end - end - return itemstack + + return mcl_bone_meal.use_bone_meal(itemstack, nil, pointed_thing) end, _dispense_into_walkable = true }) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index a03eee012..a768fab37 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -12,6 +12,25 @@ for i=0, 3 do local drop_berries = (i >= 2) local berries_to_drop = drop_berries and {i - 1, i} or nil + local on_bonemealing = nil + local function do_berry_drop(pos) + 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"}) + end + if i ~= 3 then + on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + local node = minetest.get_node(pos) + return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 0, true) + end + else + on_bonemealing = function(pointed_thing, placer) + do_berry_drop(pointed_thing.under) + end + end + minetest.register_node(node_name, { drawtype = "plantlike", tiles = {texture}, @@ -45,6 +64,7 @@ for i=0, 3 do sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, _mcl_hardness = 0, + _mcl_on_bonemealing = on_bonemealing, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() if clicker:is_player() and minetest.is_protected(pos, pn) then @@ -60,11 +80,13 @@ for i=0, 3 do return end - if drop_berries then - for j=1, berries_to_drop[math.random(2)] do - minetest.add_item(pos, "mcl_farming:sweet_berry") + if i >= 2 then + do_berry_drop(pos) + else + -- Use bonemeal + 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) end - minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"}) end return itemstack end, diff --git a/mods/MISC/bonemeal/init.lua b/mods/MISC/bonemeal/init.lua new file mode 100644 index 000000000..e69de29bb diff --git a/mods/MISC/bonemeal/mod.conf b/mods/MISC/bonemeal/mod.conf new file mode 100644 index 000000000..292cc0352 --- /dev/null +++ b/mods/MISC/bonemeal/mod.conf @@ -0,0 +1,4 @@ +name = bonemeal +author = teknomunk +description = Compatibility shim for WorldEdit-Additions bonemeal support +optional_depends = mcl_bone_meal From 57678e31bc565b58323fa0541bd20a112ec6f76e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 20 Mar 2024 08:01:34 +0000 Subject: [PATCH 55/93] Move commented out bamboo bone meal code into mods/ITEMS/mcl_bamboo/bamboo_base.lua --- mods/ITEMS/mcl_bamboo/bamboo_base.lua | 6 ++++++ mods/ITEMS/mcl_bone_meal/init.lua | 11 ----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/mods/ITEMS/mcl_bamboo/bamboo_base.lua b/mods/ITEMS/mcl_bamboo/bamboo_base.lua index e1b8ba640..790ba1dcb 100644 --- a/mods/ITEMS/mcl_bamboo/bamboo_base.lua +++ b/mods/ITEMS/mcl_bamboo/bamboo_base.lua @@ -34,6 +34,12 @@ local bamboo_def = { wield_image = "mcl_bamboo_bamboo_shoot.png", _mcl_blast_resistance = 1, _mcl_hardness = 1, + --[[ + _mcl_on_bonemealing = function(pointed_thing, placer) + local pos = pointed_thing.under + return mcl_bamboo.grow_bamboo(pos, true) + end, + ]] node_box = { type = "fixed", fixed = { diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 23c66ea98..143753dc2 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -68,17 +68,6 @@ local function legacy_apply_bone_meal(pointed_thing, placer) end end ---[[ - Here for when Bonemeal becomes an api, there's code if needed for handling applying to bamboo. - -- Handle applying bonemeal to bamboo. - elseif mcl_bamboo.is_bamboo(n.name) then - local success = mcl_bamboo.grow_bamboo(pos, true) - if success then - mcl_dye.add_bone_meal_particle(pos) - end - return success ---]] - return false end -- End legacy bone meal API From 09bcf3d22bbc60b6a2e154d09c167a80b955e1f7 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 20 Mar 2024 21:16:09 +0000 Subject: [PATCH 56/93] Add untested bonemeal mod compatibility shim --- mods/MISC/bonemeal/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/MISC/bonemeal/init.lua b/mods/MISC/bonemeal/init.lua index e69de29bb..666319204 100644 --- a/mods/MISC/bonemeal/init.lua +++ b/mods/MISC/bonemeal/init.lua @@ -0,0 +1,12 @@ +bonemeal = {} + +function bonemeal:on_use(pos, strength, node) + -- Fake itemstack for bone meal + local itemstack = ItemStack("mcl_bone_meal:bone_meal") + + local pointed_thing = { + above = pos, + under = vector.offset(pos, 0, -1, 0) + } + mcl_bone_meal.use_bone_meal(itemstack, nil, pointed_thing) +end From 55b4d3d5eed6c409fef5187ee97987f5ae58d1f1 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 07:11:44 +0000 Subject: [PATCH 57/93] Rename localization files --- .../mcl_bone_meal/locale/{mcl_dye.de.tr => mcl_bonemeal.de.tr} | 0 .../mcl_bone_meal/locale/{mcl_dye.es.tr => mcl_bonemeal.es.tr} | 0 .../mcl_bone_meal/locale/{mcl_dye.fr.tr => mcl_bonemeal.fr.tr} | 0 .../mcl_bone_meal/locale/{mcl_dye.pl.tr => mcl_bonemeal.pl.tr} | 0 .../mcl_bone_meal/locale/{mcl_dye.ru.tr => mcl_bonemeal.ru.tr} | 0 .../locale/{mcl_dye.zh_TW.tr => mcl_bonemeal.zh_TW.tr} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.de.tr => mcl_bonemeal.de.tr} (100%) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.es.tr => mcl_bonemeal.es.tr} (100%) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.fr.tr => mcl_bonemeal.fr.tr} (100%) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.pl.tr => mcl_bonemeal.pl.tr} (100%) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.ru.tr => mcl_bonemeal.ru.tr} (100%) rename mods/ITEMS/mcl_bone_meal/locale/{mcl_dye.zh_TW.tr => mcl_bonemeal.zh_TW.tr} (100%) diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.de.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.de.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.de.tr diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.es.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.es.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.es.tr diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.fr.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.pl.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.pl.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.pl.tr diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.ru.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.ru.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.ru.tr diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.zh_TW.tr similarity index 100% rename from mods/ITEMS/mcl_bone_meal/locale/mcl_dye.zh_TW.tr rename to mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.zh_TW.tr From 4a865fa2df36b1b13425c4b70233e84aded51070 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 07:24:31 +0000 Subject: [PATCH 58/93] Enable bamboo bonemealing despite rightclick handling strangeness --- mods/ITEMS/mcl_bamboo/bamboo_base.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/mods/ITEMS/mcl_bamboo/bamboo_base.lua b/mods/ITEMS/mcl_bamboo/bamboo_base.lua index 790ba1dcb..3c0de0509 100644 --- a/mods/ITEMS/mcl_bamboo/bamboo_base.lua +++ b/mods/ITEMS/mcl_bamboo/bamboo_base.lua @@ -34,12 +34,10 @@ local bamboo_def = { wield_image = "mcl_bamboo_bamboo_shoot.png", _mcl_blast_resistance = 1, _mcl_hardness = 1, - --[[ _mcl_on_bonemealing = function(pointed_thing, placer) local pos = pointed_thing.under return mcl_bamboo.grow_bamboo(pos, true) end, - ]] node_box = { type = "fixed", fixed = { From 9e6d49dd38db122cdd243338bf51186f7a08717f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 07:35:51 +0000 Subject: [PATCH 59/93] Fix localization except mcl_composters.ru.tr --- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr | 1 - mods/ITEMS/mcl_composters/locale/mcl_composters.fr.tr | 2 +- mods/ITEMS/mcl_composters/locale/mcl_composters.ja.tr | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr index 2e36baadb..59f1beeef 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr @@ -3,7 +3,6 @@ Cocoa Beans=Какао-бобы Grows at the side of jungle trees=Растут на стволах тропических деревьев Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Какао-бобы можно использовать для посадки какао, выпечки печенья или изготовления коричневого красителя. Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по овце, чтобы сделать её шерсть коричневой. Кликните правой по боковой части ствола дерева джунглей, что ->>>>>>> 195f0dfba (Move cocoa beans item to mcl_cocoas.) Premature Cocoa Pod=Молодой стручок какао Cocoa pods grow on the side of jungle trees in 3 stages.=Стручки какао растут на деревьях джунглей в 3 этапа. Medium Cocoa Pod=Средний стручок какао diff --git a/mods/ITEMS/mcl_composters/locale/mcl_composters.fr.tr b/mods/ITEMS/mcl_composters/locale/mcl_composters.fr.tr index 0f4e665e6..909b889e8 100644 --- a/mods/ITEMS/mcl_composters/locale/mcl_composters.fr.tr +++ b/mods/ITEMS/mcl_composters/locale/mcl_composters.fr.tr @@ -4,4 +4,4 @@ Composters can convert various organic items into bonemeal.=Les composteurs peuv Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter.=Utiliser des objets organiques sur le composteur pour le remplir de couches de compost. Chaque fois qu'un objet est mis dans le composteur, il y a une chance d'ajouter une nouvelle couche de compost au composteur. Certains objets ont une plus grande chance que d'autres d'ajouter une couche supplémentaire. Après l'avoir rempli de 7 couches de compost, le composteur est plein. Après un délai d'approximativement une seconde, le composteur est prêt et on peut récupérer la farine d'os. Cliquer droit le composteur permet de récupérer la farine d'os et de vider le composteur. filled=rempli ready for harvest=prêt pour la récolte -Converts organic items into bonemeal=Convertit les objets organiques en farine d'os. +Converts organic items into bone meal=Convertit les objets organiques en farine d'os. diff --git a/mods/ITEMS/mcl_composters/locale/mcl_composters.ja.tr b/mods/ITEMS/mcl_composters/locale/mcl_composters.ja.tr index 6d8908486..115d53b17 100644 --- a/mods/ITEMS/mcl_composters/locale/mcl_composters.ja.tr +++ b/mods/ITEMS/mcl_composters/locale/mcl_composters.ja.tr @@ -4,4 +4,4 @@ Composters can convert various organic items into bonemeal.=コンポスター Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter."=コンポスターに有機物を入れて、堆肥の層を作りましょう。コンポスターに有機物を入れるたびに、次の堆肥の層が追加されるチャンスが起きます。 追加される確率がより高くなっているアイテムもいくつかあります。 7層分の堆肥が充填されると、コンポスターは満杯となります。その約1秒後に、骨粉を取り出せる準備が完了します。右クリックして骨粉を取り出すと、コンポスターは空になります。 filled=充足 ready for harvest=収穫可能 -Converts organic items into bonemeal=有機物を骨粉に変える +Converts organic items into bone meal=有機物を骨粉に変える From 3c2f2593db8480c1833c66fe5a9f7f776ac0d808 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 18:11:36 +0000 Subject: [PATCH 60/93] Only consume bone meal if a _mcl_on_bonemealing callback is defined or the legacy API returns true, convert vines to use new bonemeal API --- mods/ITEMS/mcl_bone_meal/init.lua | 5 ++++- mods/ITEMS/mcl_crimson/init.lua | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 143753dc2..a402ab064 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -81,13 +81,16 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) local node = minetest.get_node(pos) local ndef = minetest.registered_nodes[node.name] local success = false + local consume -- If the pointed node can be bonemealed, let it handle the processing. if ndef and ndef._mcl_on_bonemealing then success = ndef._mcl_on_bonemealing(pointed_thing, placer) + consume = true else -- Otherwise try the legacy API. success = legacy_apply_bone_meal(pointed_thing, placer) + consume = success end -- Particle effects @@ -96,7 +99,7 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) end -- Take the item - if not placer or not minetest.is_creative_enabled(placer:get_player_name()) then + if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then itemstack:take_item() end diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 1d4194e60..d0620539f 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -28,9 +28,11 @@ function grow_vines(pos, moreontop ,vine, dir) minetest.set_node(vector.offset(pos,0,i*dir,0),{name=vine}) end end - break + return true end until n.name ~= "air" and n.name ~= vine + + return false end local nether_plants = { @@ -130,6 +132,9 @@ minetest.register_node("mcl_crimson:twisting_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", + _mcl_on_bonemealing = function(pointed_thing, placer) + return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:twisting_vines") + end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn or "") then @@ -150,10 +155,7 @@ minetest.register_node("mcl_crimson:twisting_vines", { end elseif clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - grow_vines(pos, math.random(1, 3),"mcl_crimson:twisting_vines") + return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos}) end return itemstack end, @@ -220,6 +222,9 @@ minetest.register_node("mcl_crimson:weeping_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", + _mcl_on_bonemealing = function(pointed_thing, placer) + return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines") + end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() if clicker:is_player() and minetest.is_protected(vector.offset(pos,0,1,0), pn or "") then @@ -240,10 +245,7 @@ minetest.register_node("mcl_crimson:weeping_vines", { end elseif clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - grow_vines(pos, math.random(1, 3),"mcl_crimson:weeping_vines", -1) + return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos}) end return itemstack end, From eb6131b037079c8afb4dfe0c5d81140a17389600 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 18:06:14 -0500 Subject: [PATCH 61/93] Fix localization errors --- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr | 2 +- mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr | 2 +- mods/ITEMS/mcl_composters/locale/template.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr index c110a1a9a..750cb2695 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.es.tr @@ -2,7 +2,7 @@ Cocoa Beans=Granos de cacao Grows at the side of jungle trees=Crece al lado de los árboles de la jungla Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Los granos de cacao se pueden usar para plantar cacao, hornear galletas o hacer tintes marrones. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en una oveja para convertir su lana en marrón. Haga clic derecho en el costado del tronco de un árbol de jungla para plantar un cacao joven. +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Haga clic derecho en una oveja para convertir su lana en marrón. Haga clic derecho en el costado del tronco de un árbol de la jungla para plantar un cacao joven. Premature Cocoa Pod=Vaina de cacao prematura Cocoa pods grow on the side of jungle trees in 3 stages.=Las vainas de cacao crecen al lado de los árboles de jungla en 3 etapas. Medium Cocoa Pod=Vaina de cacao mediana diff --git a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr index 59f1beeef..7840c5e4a 100644 --- a/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr +++ b/mods/ITEMS/mcl_cocoas/locale/mcl_cocoas.ru.tr @@ -2,7 +2,7 @@ Cocoa Beans=Какао-бобы Grows at the side of jungle trees=Растут на стволах тропических деревьев Cocoa beans can be used to plant cocoa, bake cookies or craft brown dye.=Какао-бобы можно использовать для посадки какао, выпечки печенья или изготовления коричневого красителя. -Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по овце, чтобы сделать её шерсть коричневой. Кликните правой по боковой части ствола дерева джунглей, что +Rightclick a sheep to turn its wool brown. Rightclick on the side of a jungle tree trunk (Jungle Wood) to plant a young cocoa.=Кликните правой по овце, чтобы сделать её шерсть коричневой. Кликните правой по боковой части ствола тропического дерева, чтобы посадить молодое какао. Premature Cocoa Pod=Молодой стручок какао Cocoa pods grow on the side of jungle trees in 3 stages.=Стручки какао растут на деревьях джунглей в 3 этапа. Medium Cocoa Pod=Средний стручок какао diff --git a/mods/ITEMS/mcl_composters/locale/template.txt b/mods/ITEMS/mcl_composters/locale/template.txt index 5d8df6fdb..344e48c31 100644 --- a/mods/ITEMS/mcl_composters/locale/template.txt +++ b/mods/ITEMS/mcl_composters/locale/template.txt @@ -1,7 +1,7 @@ # textdomain: mcl_composters Composter= Composters can convert various organic items into bone meal.= -Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter."= +Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter.= filled= ready for harvest= Converts organic items into bone meal= From 44d154f594291a86c6032ab013862595de30ca02 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 18:30:34 +0000 Subject: [PATCH 62/93] Modify backtrace listing to use minetest.log --- mods/ITEMS/mcl_bone_meal/init.lua | 5 ++++- mods/ITEMS/mcl_dye/init.lua | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index a402ab064..d92e1df4f 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -54,7 +54,10 @@ mcl_bone_meal.bone_meal_callbacks = {} -- function mcl_bone_meal.register_on_bone_meal_apply(func) minetest.log("warning", "register_on_bone_meal_apply(func) is deprecated. Read mcl_bone_meal/API.md!") - print(debug.traceback()) + local lines = string.split(debug.traceback(),"\n") + for _,line in ipairs(lines) do + minetest.log("warning",line) + end table.insert(mcl_bone_meal.bone_meal_callbacks, func) end diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 4836435fc..2c10c09f7 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -119,7 +119,10 @@ end -- function mcl_dye.add_bone_meal_particle(pos, def) minetest.log("warning", "mcl_dye.add_bone_meal_particles() is deprecated. Read mcl_bone_meal/API.md!") - print(debug.traceback()) + local lines = string.split(debug.traceback(),"\n") + for _,line in ipairs(lines) do + minetest.log("warning",line) + end mcl_bone_meal.add_bone_meal_particle(pos, def) end From 7f6d456a32b7a27e4e6fb6d422e4df848969a303 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 18:44:09 +0000 Subject: [PATCH 63/93] Remove bone to bone meal recipe from mcl_dye as it now resides in mcl_bone_meal --- mods/ITEMS/mcl_dye/init.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mods/ITEMS/mcl_dye/init.lua b/mods/ITEMS/mcl_dye/init.lua index 2c10c09f7..8b1090498 100644 --- a/mods/ITEMS/mcl_dye/init.lua +++ b/mods/ITEMS/mcl_dye/init.lua @@ -131,12 +131,6 @@ function mcl_dye.register_on_bone_meal_apply(func) mcl_bone_meal.register_on_bone_meal_apply(func) end -minetest.register_craft({ - output = "mcl_bone_meal:bone_meal 3", - recipe = {{"mcl_mobitems:bone"}}, -}) - - -- Dye creation recipes. -- minetest.register_craft({ From c3a33ea2c2c01e9da83d25ab55a61c6a8c6e4f40 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 22 Mar 2024 05:39:45 +0000 Subject: [PATCH 64/93] Update mod authors, remove a TODO --- mods/ITEMS/mcl_bone_meal/init.lua | 2 +- mods/ITEMS/mcl_bone_meal/mod.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index d92e1df4f..2e79ab678 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -37,7 +37,7 @@ function mcl_bone_meal.add_bone_meal_particle(pos, def) maxexptime = def.maxexptime or 4, minsize = def.minsize or 0.7, maxsize = def.maxsize or 2.4, - texture = "mcl_particles_bonemeal.png^[colorize:#00EE00:125", -- TODO: real MC color + texture = "mcl_particles_bonemeal.png^[colorize:#00EE00:125", glow = def.glow or 1, }) end diff --git a/mods/ITEMS/mcl_bone_meal/mod.conf b/mods/ITEMS/mcl_bone_meal/mod.conf index 439973540..60dfaa59e 100644 --- a/mods/ITEMS/mcl_bone_meal/mod.conf +++ b/mods/ITEMS/mcl_bone_meal/mod.conf @@ -1,3 +1,3 @@ name = mcl_bone_meal description = Bone meal can be used as a fertilizer and as a dye. -author = kabou +author = kabou, teknomunk From 42d37210c55667a7ad61cd7a8e27ce3e093f237f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 21 Mar 2024 07:20:20 -0500 Subject: [PATCH 65/93] Fix mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr --- mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr b/mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr index 39f172199..99dfa62eb 100644 --- a/mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr +++ b/mods/ITEMS/mcl_composters/locale/mcl_composters.ru.tr @@ -4,4 +4,4 @@ Composters can convert various organic items into bonemeal.=Компостер Use organic items on the composter to fill it with layers of compost. Every time an item is put in the composter, there is a chance that the composter adds another layer of compost. Some items have a bigger chance of adding an extra layer than other items. After filling up with 7 layers of compost, the composter is full. After a delay of approximately one second the composter becomes ready and bone meal can be retrieved from it. Right-clicking the composter takes out the bone meal empties the composter.=Используйте органические предметы на компостере, чтобы заполнить его слоями перегноя. Каждый раз когда в компостер попадает предмет, есть шанс что в компостере появится новый слой перегноя. Некоторые предметы имеют больший шанс на появление нового слоя. После заполнения 7 слоями перегноя, компостер можно опустошить, забрав из него костную муку. После задержки в одну секунду компостер будет готов и костная мука будет извлечена из него. Правым кликом по компостеру чтобы забрать костную муку. filled=заполнен ready for harvest=готов к сбору -Converts organic items into bonemeal=Перерабатывает органику в костную муку +Converts organic items into bone meal=Перерабатывает органику в костную муку From e6e13bdc6764ce912f507c8e6ce786fcc0099e0a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 23 Mar 2024 16:44:41 +0000 Subject: [PATCH 66/93] Change _mcl_on_bonemealing to _on_bone_meal, update API.md to reflect this --- mods/ITEMS/mcl_bamboo/bamboo_base.lua | 2 +- mods/ITEMS/mcl_bone_meal/API.md | 16 ++++++++++------ mods/ITEMS/mcl_bone_meal/init.lua | 4 ++-- mods/ITEMS/mcl_cocoas/init.lua | 4 ++-- mods/ITEMS/mcl_core/nodes_trees.lua | 2 +- mods/ITEMS/mcl_crimson/init.lua | 14 +++++++------- mods/ITEMS/mcl_farming/beetroot.lua | 2 +- mods/ITEMS/mcl_farming/carrots.lua | 2 +- mods/ITEMS/mcl_farming/melon.lua | 2 +- mods/ITEMS/mcl_farming/potatoes.lua | 2 +- mods/ITEMS/mcl_farming/pumpkin.lua | 2 +- mods/ITEMS/mcl_farming/sweet_berry.lua | 6 +++--- mods/ITEMS/mcl_farming/wheat.lua | 2 +- mods/ITEMS/mcl_flowers/bonemealing.lua | 10 +++++----- mods/ITEMS/mcl_flowers/init.lua | 10 +++++----- mods/ITEMS/mcl_mushrooms/small.lua | 4 ++-- 16 files changed, 44 insertions(+), 40 deletions(-) diff --git a/mods/ITEMS/mcl_bamboo/bamboo_base.lua b/mods/ITEMS/mcl_bamboo/bamboo_base.lua index 3c0de0509..15f9da5b0 100644 --- a/mods/ITEMS/mcl_bamboo/bamboo_base.lua +++ b/mods/ITEMS/mcl_bamboo/bamboo_base.lua @@ -34,7 +34,7 @@ local bamboo_def = { wield_image = "mcl_bamboo_bamboo_shoot.png", _mcl_blast_resistance = 1, _mcl_hardness = 1, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under return mcl_bamboo.grow_bamboo(pos, true) end, diff --git a/mods/ITEMS/mcl_bone_meal/API.md b/mods/ITEMS/mcl_bone_meal/API.md index a404d29a9..b365c3900 100644 --- a/mods/ITEMS/mcl_bone_meal/API.md +++ b/mods/ITEMS/mcl_bone_meal/API.md @@ -3,29 +3,32 @@ Bonemealing callbacks and particle functions. -## _mcl_on_bonemealing(pointed_thing, placer) +## _on_bone_meal(itemstack, placer, pointed_thing) The bone meal API provides a callback definition that nodes can use to register a handler that is executed when a bone meal item is used on it. Nodes that wish to use the bone meal API should in their node registration -define a callback handler named `_mcl_on_bonemealing`. +define a callback handler named `_on_bone_meal`. Note that by registering the callback handler, the node declares that bone meal can be used on it and as a result, when the user is not in creative mode, the used bone meal is spent and taken from the itemstack passed to -the `on_place()` handler of the bone meal item used. +the `on_place()` handler of the bone meal item used regardless of whether +the bone meal had an effect on the node and regardless of the result of +the callback handler. It is for all intents and purposes up to the callback defined in the node to decide how to handle the specific effect that bone meal has on that node. -The `_mcl_on_bonemealing` callback handler is a +The `_on_bone_meal` callback handler is a - `function(pointed_thing, placer)` + `function(itemstack, placer, pointed_thing)` Its arguments are: +* `itemstack`: the stack of bonem eal being applied +* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! * `pointed_thing`: exact pointing location (see Minetest API), where the bone meal is applied -* `placer`: ObjectRef of the player who aplied the bone meal, can be nil! The return value of the handler function indicates if the bonemealing had its intended effect. If `true`, 'bone meal particles' are spawned at the @@ -63,6 +66,7 @@ Called when the bone meal is applied anywhere. bone meal is applied * `placer`: ObjectRef of the player who aplied the bone meal, can be nil! This function is deprecated and will be removed at some time in the future. +Bone meal is not consumed unless the provided function returns true. ## mcl_dye.add_bone_meal_particle(pos, def) ## mcl_dye.register_on_bone_meal_apply(function(pointed_thing, user)) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 2e79ab678..3a0309003 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -87,8 +87,8 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) local consume -- If the pointed node can be bonemealed, let it handle the processing. - if ndef and ndef._mcl_on_bonemealing then - success = ndef._mcl_on_bonemealing(pointed_thing, placer) + if ndef and ndef._on_bone_meal then + success = ndef._on_bone_meal(itemstack, placer, pointed_thing) consume = true else -- Otherwise try the legacy API. diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 91026ce83..1af306355 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -137,7 +137,7 @@ for i = 1, 3 do on_rotate = false, _mcl_blast_resistance = 3, _mcl_hardness = 0.2, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under return cocoa_grow(pos) end, @@ -149,7 +149,7 @@ for i = 1, 3 do end if i == 3 then def.drop = "mcl_cocoas:cocoa_beans 3" - def._mcl_on_bonemealing = nil + def._on_bone_mealing = nil end minetest.register_node("mcl_cocoas:cocoa_" .. i, table.copy(def)) diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index 96b619f73..c71693408 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -280,7 +280,7 @@ function mcl_core.register_sapling(subname, description, longdesc, tt_help, text nn == "mcl_core:podzol" or nn == "mcl_core:podzol_snow" or nn == "mcl_core:dirt" or nn == "mcl_core:mycelium" or nn == "mcl_core:coarse_dirt" end), - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) -- Saplings: 45% chance to advance growth stage diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index d0620539f..1f8273b22 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -85,7 +85,7 @@ minetest.register_node("mcl_crimson:warped_fungus", { light_source = 1, sounds = mcl_sounds.node_sound_leaves_defaults(), node_placement_prediction = "", - _mcl_on_bonemealing = function(pointed_thing, player) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) @@ -107,7 +107,7 @@ mcl_flowerpots.register_potted_flower("mcl_crimson:warped_fungus", { name = "warped_fungus", desc = S("Warped Fungus"), image = "mcl_crimson_warped_fungus.png", - _mcl_on_bonemealing = function(pt,user) + _on_bone_meal = function(itemstack, placer, pointed_thing) local n = has_nylium_neighbor(pt.under) if n then minetest.set_node(pt.under,n) @@ -132,7 +132,7 @@ minetest.register_node("mcl_crimson:twisting_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:twisting_vines") end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) @@ -222,7 +222,7 @@ minetest.register_node("mcl_crimson:weeping_vines", { fixed = { -3/16, -0.5, -3/16, 3/16, 0.5, 3/16 }, }, node_placement_prediction = "", - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines") end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) @@ -404,7 +404,7 @@ minetest.register_node("mcl_crimson:warped_nylium", { _mcl_hardness = 0.4, _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, - _mcl_on_bonemealing = function(pt,user) + _on_bone_meal = function(itemstack, placer, pointed_thing) local node = minetest.get_node(pt.under) spread_nether_plants(pt.under,node) return true @@ -541,7 +541,7 @@ minetest.register_node("mcl_crimson:crimson_fungus", { fixed = { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 }, }, node_placement_prediction = "", - _mcl_on_bonemealing = function(pointed_thing, player) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local nodepos = minetest.get_node(vector.offset(pos, 0, -1, 0)) if nodepos.name == "mcl_crimson:crimson_nylium" or nodepos.name == "mcl_nether:netherrack" then @@ -702,7 +702,7 @@ minetest.register_node("mcl_crimson:crimson_nylium", { _mcl_hardness = 0.4, _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, - _mcl_on_bonemealing = function(pt,user) + _on_bone_meal = function(itemstack, placer, pointed_thing) local node = minetest.get_node(pt.under) spread_nether_plants(pt.under,node) return true diff --git a/mods/ITEMS/mcl_farming/beetroot.lua b/mods/ITEMS/mcl_farming/beetroot.lua index 605c41005..66d47d461 100644 --- a/mods/ITEMS/mcl_farming/beetroot.lua +++ b/mods/ITEMS/mcl_farming/beetroot.lua @@ -41,7 +41,7 @@ for i = 0, 2 do }, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) -- 75% chance to advance to next stage diff --git a/mods/ITEMS/mcl_farming/carrots.lua b/mods/ITEMS/mcl_farming/carrots.lua index a008f73ed..119d108af 100644 --- a/mods/ITEMS/mcl_farming/carrots.lua +++ b/mods/ITEMS/mcl_farming/carrots.lua @@ -45,7 +45,7 @@ for i=1, 7 do groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) diff --git a/mods/ITEMS/mcl_farming/melon.lua b/mods/ITEMS/mcl_farming/melon.lua index deda6ba10..2dcaaf835 100644 --- a/mods/ITEMS/mcl_farming/melon.lua +++ b/mods/ITEMS/mcl_farming/melon.lua @@ -109,7 +109,7 @@ for s=1,7 do groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, plant_melon_stem=s}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) diff --git a/mods/ITEMS/mcl_farming/potatoes.lua b/mods/ITEMS/mcl_farming/potatoes.lua index da837009a..eae52abcd 100644 --- a/mods/ITEMS/mcl_farming/potatoes.lua +++ b/mods/ITEMS/mcl_farming/potatoes.lua @@ -49,7 +49,7 @@ for i=1, 7 do groups = {dig_immediate=3, not_in_creative_inventory=1,plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 3d6062f0b..df01d0124 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -79,7 +79,7 @@ for s=1,7 do groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1,}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_mealing = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index a768fab37..769e7b6cf 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -20,13 +20,13 @@ for i=0, 3 do minetest.swap_node(pos, {name = "mcl_farming:sweet_berry_bush_1"}) end if i ~= 3 then - on_bonemealing = function(pointed_thing, placer) + on_bonemealing = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local node = minetest.get_node(pos) return mcl_farming:grow_plant("plant_sweet_berry_bush", pos, node, 0, true) end else - on_bonemealing = function(pointed_thing, placer) + on_bonemealing = function(itemstack, placer, pointed_thing) do_berry_drop(pointed_thing.under) end end @@ -64,7 +64,7 @@ for i=0, 3 do sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, _mcl_hardness = 0, - _mcl_on_bonemealing = on_bonemealing, + _on_bone_meal = on_bonemealing, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() if clicker:is_player() and minetest.is_protected(pos, pn) then diff --git a/mods/ITEMS/mcl_farming/wheat.lua b/mods/ITEMS/mcl_farming/wheat.lua index d8ed0d0fb..c0013e2ce 100644 --- a/mods/ITEMS/mcl_farming/wheat.lua +++ b/mods/ITEMS/mcl_farming/wheat.lua @@ -60,7 +60,7 @@ for i=1,7 do dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index 26fc8a44c..d64bfe092 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -8,7 +8,7 @@ -- mcl_core, such as mcl_flowers. -- -- To work around this restriction, the bonemealing callback is defined here --- and the _mcl_on_bonemealing callback in "mcl_core:dirt_with_grass" node +-- and the _on_bone_meal callback in "mcl_core:dirt_with_grass" node -- definition is overwritten with it. local mg_name = minetest.get_mapgen_setting("mg_name") @@ -124,12 +124,12 @@ local olddef = minetest.registered_nodes[nodename] if not olddef then minetest.log("warning", "'mcl_core:dirt_with_grass' not registered, cannot add override!") else - local oldhandler = olddef._mcl_on_bonemealing - local newhandler = function (pointed_thing, placer) + local oldhandler = olddef._on_bone_meal + local newhandler = function(itemstack, placer, pointed_thing) bonemeal_grass(pointed_thing, placer) if oldhandler then - oldhandler(pointed_thing, placer) + oldhandler(itemstack, placer, pointed_thing) end end - minetest.override_item(nodename, {_mcl_on_bonemealing = newhandler}) + minetest.override_item(nodename, {_on_bone_meal = newhandler}) end diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 20c153dfa..311b7d8ce 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -162,7 +162,7 @@ local def_tallgrass = { _mcl_fortune_drop = fortune_wheat_seed_drop, node_placement_prediction = "", on_place = on_place_flower, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) -- Grow into double tallgrass @@ -192,7 +192,7 @@ def_fern.selection_box = { fixed = { -6/16, -0.5, -6/16, 6/16, 5/16, 6/16 }, } def_fern.groups.compostability = 65 -def_fern._mcl_on_bonemealing = function(pointed_thing, placer) +def_fern._on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) -- Grow into double fern. @@ -272,7 +272,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im bottom_groups.flower = 1 bottom_groups.place_flowerlike = 1 bottom_groups.dig_immediate = 3 - on_bonemealing = function(pointed_thing, placer) + on_bonemealing = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under minetest.add_item(pos, "mcl_flowers:"..name) return true @@ -411,7 +411,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im minetest.remove_node(top) end end, - _mcl_on_bonemealing = on_bonemealing, + _on_bone_meal = on_bonemealing, groups = bottom_groups, sounds = mcl_sounds.node_sound_leaves_defaults(), mesh = mesh @@ -450,7 +450,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im minetest.remove_node(bottom) end end, - _mcl_on_bonemealing = on_bonemealing, + _on_bone_meal = on_bonemealing, groups = top_groups, sounds = mcl_sounds.node_sound_leaves_defaults(), }) diff --git a/mods/ITEMS/mcl_mushrooms/small.lua b/mods/ITEMS/mcl_mushrooms/small.lua index 260fe700a..a32507e78 100644 --- a/mods/ITEMS/mcl_mushrooms/small.lua +++ b/mods/ITEMS/mcl_mushrooms/small.lua @@ -88,7 +88,7 @@ minetest.register_node("mcl_mushrooms:mushroom_brown", { }, node_placement_prediction = "", on_place = on_place, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local schematic = schempath .. "mcl_mushrooms_huge_brown.mts" local offset = vector.new(-3, -1, -3) return apply_bonemeal(pointed_thing.under, schematic, offset) @@ -120,7 +120,7 @@ minetest.register_node("mcl_mushrooms:mushroom_red", { }, node_placement_prediction = "", on_place = on_place, - _mcl_on_bonemealing = function(pointed_thing, placer) + _on_bone_meal = function(itemstack, placer, pointed_thing) local schematic = schempath .. "mcl_mushrooms_huge_red.mts" local offset = vector.new(-2, -1, -2) return apply_bonemeal(pointed_thing.under, schematic, offset) From 7112369917956f0a7c9247574a6af53ab50848cb Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 18 Apr 2024 23:27:08 +0000 Subject: [PATCH 67/93] Fix crashes when using bonemeal on nether nodes --- mods/ITEMS/mcl_crimson/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 1f8273b22..64a1e35e0 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -108,9 +108,9 @@ mcl_flowerpots.register_potted_flower("mcl_crimson:warped_fungus", { desc = S("Warped Fungus"), image = "mcl_crimson_warped_fungus.png", _on_bone_meal = function(itemstack, placer, pointed_thing) - local n = has_nylium_neighbor(pt.under) + local n = has_nylium_neighbor(pointed_thing.under) if n then - minetest.set_node(pt.under,n) + minetest.set_node(pointed_thing.under,n) end end, }) @@ -405,7 +405,7 @@ minetest.register_node("mcl_crimson:warped_nylium", { _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, _on_bone_meal = function(itemstack, placer, pointed_thing) - local node = minetest.get_node(pt.under) + local node = minetest.get_node(pointed_thing.under) spread_nether_plants(pt.under,node) return true end, @@ -703,8 +703,8 @@ minetest.register_node("mcl_crimson:crimson_nylium", { _mcl_blast_resistance = 0.4, _mcl_silk_touch_drop = true, _on_bone_meal = function(itemstack, placer, pointed_thing) - local node = minetest.get_node(pt.under) - spread_nether_plants(pt.under,node) + local node = minetest.get_node(pointed_thing.under) + spread_nether_plants(pointed_thing.under,node) return true end, }) From cf1325d466d9b75b30f8c9c4429d76f029d08c9b Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 18 Apr 2024 23:28:58 +0000 Subject: [PATCH 68/93] Fix crash at one more spot --- mods/ITEMS/mcl_crimson/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 64a1e35e0..3f68921d1 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -406,7 +406,7 @@ minetest.register_node("mcl_crimson:warped_nylium", { _mcl_silk_touch_drop = true, _on_bone_meal = function(itemstack, placer, pointed_thing) local node = minetest.get_node(pointed_thing.under) - spread_nether_plants(pt.under,node) + spread_nether_plants(pointed_thing.under,node) return true end, }) From 354160e9e60581c1b298109a3483ae0c672a845e Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 19 Apr 2024 10:31:45 +0000 Subject: [PATCH 69/93] Check both above and below in pointed_thing for bonemealing (and pass thru the position as .under), make crimson vines and twisting vines compostable by rightclicking on the composter --- mods/ITEMS/mcl_bone_meal/init.lua | 51 +++++++++++++++++-------------- mods/ITEMS/mcl_crimson/init.lua | 30 ++++++++++++------ 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 3a0309003..2b3bf7041 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -76,34 +76,39 @@ end -- End legacy bone meal API mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.under + local positions = {pointed_thing.under, pointed_thing.above} + for i = 1,2 do + local pos = positions[i] - -- Check protection - if mcl_util.check_area_protection(pos, pointed_thing.above, placer) then return false end + -- Check protection + if mcl_util.check_area_protection(pos, pointed_thing.above, placer) then return false end - local node = minetest.get_node(pos) - local ndef = minetest.registered_nodes[node.name] - local success = false - local consume + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local success = false + local consume - -- If the pointed node can be bonemealed, let it handle the processing. - if ndef and ndef._on_bone_meal then - success = ndef._on_bone_meal(itemstack, placer, pointed_thing) - consume = true - else - -- Otherwise try the legacy API. - success = legacy_apply_bone_meal(pointed_thing, placer) - consume = success - end + -- If the pointed node can be bonemealed, let it handle the processing. + if ndef and ndef._on_bone_meal then + success = ndef._on_bone_meal(itemstack, placer, {under = pos, above = vector.offset(pos, 0, 1, 0)}) + consume = true + else + -- Otherwise try the legacy API. + success = legacy_apply_bone_meal(pointed_thing, placer) + consume = success + end - -- Particle effects - if success then - mcl_bone_meal.add_bone_meal_particle(pos) - end + -- Particle effects + if success then + mcl_bone_meal.add_bone_meal_particle(pos) + end - -- Take the item - if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then - itemstack:take_item() + -- Take the item + if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then + itemstack:take_item() + end + + if success then return itemstack end end return itemstack diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 3f68921d1..e5c86841f 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -161,17 +161,22 @@ minetest.register_node("mcl_crimson:twisting_vines", { end, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under - local above = pointed_thing.above local unode = minetest.get_node(under) + local unode_def = minetest.registered_nodes[unode.name] + + local above = pointed_thing.above + local anode = minetest.get_node(above) + local anode_def = minetest.registered_nodes[anode.name] + if under.y < above.y then minetest.set_node(above, {name = "mcl_crimson:twisting_vines"}) if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end - else - if unode.name == "mcl_crimson:twisting_vines" then - return minetest.registered_nodes[unode.name].on_rightclick(under, unode, placer, itemstack, pointed_thing) - end + elseif unode_def and unode_def.on_rightclick then + return unode_def.on_rightclick(under, unode, placer, itemstack, pointed_thing) + elseif anode_def and anode_def.on_rightclick then + return unode_def.on_rightclick(above, anode, placer, itemstack, pointed_thing) end return itemstack end, @@ -251,17 +256,22 @@ minetest.register_node("mcl_crimson:weeping_vines", { end, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under - local above = pointed_thing.above local unode = minetest.get_node(under) + local unode_def = minetest.registered_nodes[unode.name] + + local above = pointed_thing.above + local anode = minetest.get_node(above) + local anode_def = minetest.registered_nodes[anode.name] + if under.y > above.y then minetest.set_node(above, {name = "mcl_crimson:weeping_vines"}) if not minetest.is_creative_enabled(placer:get_player_name()) then itemstack:take_item() end - else - if unode.name == "mcl_crimson:weeping_vines" then - return minetest.registered_nodes[unode.name].on_rightclick(under, unode, placer, itemstack, pointed_thing) - end + elseif unode_def and unode_def.on_rightclick then + return unode_def.on_rightclick(under, unode, placer, itemstack, pointed_thing) + elseif anode_def and anode_def.on_rightclick then + return unode_def.on_rightclick(above, anode, placer, itemstack, pointed_thing) end return itemstack end, From d09791db7b8efa8144b7bbe2248bbe89f9f9f2bc Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 20 May 2024 07:21:52 +0000 Subject: [PATCH 70/93] Fix typo that prevented bone mealing pumpkin plants --- mods/ITEMS/mcl_farming/pumpkin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index df01d0124..998a82c18 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -79,7 +79,7 @@ for s=1,7 do groups = {dig_immediate=3, not_in_creative_inventory=1, plant=1,attached_node=1, dig_by_water=1,destroy_by_lava_flow=1,}, sounds = mcl_sounds.node_sound_leaves_defaults(), _mcl_blast_resistance = 0, - _on_bone_mealing = function(itemstack, placer, pointed_thing) + _on_bone_meal = function(itemstack, placer, pointed_thing) local pos = pointed_thing.under local n = minetest.get_node(pos) local stages = math.random(2, 5) From 6741c5a8093aca0b95bb25f29b4406e845997ef5 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 26 May 2024 17:12:44 +0000 Subject: [PATCH 71/93] Make composter_progress_chance local, as it is not used anywhere except in mcl_composters --- mods/ITEMS/mcl_composters/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_composters/init.lua b/mods/ITEMS/mcl_composters/init.lua index b635760ca..69065d927 100644 --- a/mods/ITEMS/mcl_composters/init.lua +++ b/mods/ITEMS/mcl_composters/init.lua @@ -90,7 +90,7 @@ end ---@param pos Vector Position of the node ---@param node node ---@param chance integer Value of "compostability" group of inserted item -function composter_progress_chance(pos, node, chance) +local function composter_progress_chance(pos, node, chance) -- calculate leveling up chance local rand = math.random(0,100) if chance >= rand then From 70e8ba9a8999379ee8ddd9c2cb8fc309bdbf0764 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 8 Jun 2024 14:51:29 -0500 Subject: [PATCH 72/93] Remove TODO pending future discussions, revert timer change in composter code --- mods/ITEMS/mcl_cocoas/init.lua | 3 +-- mods/ITEMS/mcl_composters/init.lua | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 1af306355..970090a1c 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -67,8 +67,7 @@ function mcl_cocoas.grow(pos) return true end --- only caller was mcl_dye, now these can be local functions. --- TODO: remove aliases, replace global functions with local functions. +-- only caller was mcl_dye, consider converting these into local functions. local cocoa_place = mcl_cocoas.place local cocoa_grow = mcl_cocoas.grow diff --git a/mods/ITEMS/mcl_composters/init.lua b/mods/ITEMS/mcl_composters/init.lua index 69065d927..7d4d135bd 100644 --- a/mods/ITEMS/mcl_composters/init.lua +++ b/mods/ITEMS/mcl_composters/init.lua @@ -114,7 +114,9 @@ local function composter_progress_chance(pos, node, chance) -- the block will get updated by the node timer callback set in node reg def if level == 7 then local timer = get_node_timer(pos) - timer:start(1) + if not timer:is_started() then + timer:start(1) + end end end end From 8f53074b58158a387ba0867a39063336394fad34 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 8 Jul 2024 21:40:11 -0500 Subject: [PATCH 73/93] Reorder functions to prevent crash --- mods/ITEMS/mcl_composters/init.lua | 70 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/mods/ITEMS/mcl_composters/init.lua b/mods/ITEMS/mcl_composters/init.lua index 7d4d135bd..28883dc48 100644 --- a/mods/ITEMS/mcl_composters/init.lua +++ b/mods/ITEMS/mcl_composters/init.lua @@ -48,6 +48,41 @@ local vector_offset = vector.offset local is_protected = minetest.is_protected local record_protection_violation = minetest.record_protection_violation +--- Math and node swap during compost progression +---@param pos Vector Position of the node +---@param node node +---@param chance integer Value of "compostability" group of inserted item +local function composter_progress_chance(pos, node, chance) + -- calculate leveling up chance + local rand = math.random(0,100) + if chance >= rand then + -- get current compost level + local level = registered_nodes[node.name]["_mcl_compost_level"] + -- spawn green particles above new layer + mcl_bone_meal.add_bone_meal_particle(vector_offset(pos, 0, level/8, 0)) + -- update composter block + if level < 7 then + level = level + 1 + else + level = "ready" + end + swap_node(pos, {name = "mcl_composters:composter_" .. level}) + minetest.sound_play({name="default_grass_footstep", gain=0.4}, { + pos = pos, + gain= 0.4, + max_hear_distance = 16, + }, true) + -- a full composter becomes ready for harvest after one second + -- the block will get updated by the node timer callback set in node reg def + if level == 7 then + local timer = get_node_timer(pos) + if not timer:is_started() then + timer:start(1) + end + end + end +end + --- Fill the composter when rightclicked. -- -- `on_rightclick` handler for composter blocks of all fill levels except @@ -86,41 +121,6 @@ local function composter_add_item(pos, node, player, itemstack, pointed_thing) return itemstack end ---- Math and node swap during compost progression ----@param pos Vector Position of the node ----@param node node ----@param chance integer Value of "compostability" group of inserted item -local function composter_progress_chance(pos, node, chance) - -- calculate leveling up chance - local rand = math.random(0,100) - if chance >= rand then - -- get current compost level - local level = registered_nodes[node.name]["_mcl_compost_level"] - -- spawn green particles above new layer - mcl_bone_meal.add_bone_meal_particle(vector_offset(pos, 0, level/8, 0)) - -- update composter block - if level < 7 then - level = level + 1 - else - level = "ready" - end - swap_node(pos, {name = "mcl_composters:composter_" .. level}) - minetest.sound_play({name="default_grass_footstep", gain=0.4}, { - pos = pos, - gain= 0.4, - max_hear_distance = 16, - }, true) - -- a full composter becomes ready for harvest after one second - -- the block will get updated by the node timer callback set in node reg def - if level == 7 then - local timer = get_node_timer(pos) - if not timer:is_started() then - timer:start(1) - end - end - end -end - --- Update a full composter block to ready for harvesting. -- -- `on_timer` handler. The timer is set in function 'composter_add_item' From afc270195aae7522df670649cbe40765c0dc20ae Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sun, 18 Aug 2024 21:31:01 -0500 Subject: [PATCH 74/93] Fix crash when bonemealing weaping and twisting vines, fix weaping vine growth --- mods/ITEMS/mcl_crimson/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index e5c86841f..4bc97c743 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -155,7 +155,7 @@ minetest.register_node("mcl_crimson:twisting_vines", { end elseif clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos}) + return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos, above=pos}) end return itemstack end, @@ -228,7 +228,7 @@ minetest.register_node("mcl_crimson:weeping_vines", { }, node_placement_prediction = "", _on_bone_meal = function(itemstack, placer, pointed_thing) - return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines") + return grow_vines(pointed_thing.under, math.random(1, 3),"mcl_crimson:weeping_vines", -1) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local pn = clicker:get_player_name() @@ -250,7 +250,7 @@ minetest.register_node("mcl_crimson:weeping_vines", { end elseif clicker:get_wielded_item():get_name() == "mcl_bone_meal:bone_meal" then - return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos}) + return mcl_bone_meal.use_bone_meal(itemstack, clicker, {under=pos, above=pos}) end return itemstack end, From 4eda77acd1d37b0b15ebf8439cb0e745acf0f487 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 21 Aug 2024 22:22:19 -0500 Subject: [PATCH 75/93] Prevent bonemealing grass from making flowers and also bonemealing the block above the grass --- mods/ITEMS/mcl_flowers/bonemealing.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_flowers/bonemealing.lua b/mods/ITEMS/mcl_flowers/bonemealing.lua index d64bfe092..44bce6eef 100644 --- a/mods/ITEMS/mcl_flowers/bonemealing.lua +++ b/mods/ITEMS/mcl_flowers/bonemealing.lua @@ -126,10 +126,11 @@ if not olddef then else local oldhandler = olddef._on_bone_meal local newhandler = function(itemstack, placer, pointed_thing) - bonemeal_grass(pointed_thing, placer) + local res = bonemeal_grass(pointed_thing, placer) if oldhandler then - oldhandler(itemstack, placer, pointed_thing) + res = oldhandler(itemstack, placer, pointed_thing) or res end + return res end minetest.override_item(nodename, {_on_bone_meal = newhandler}) end From 66b5a369f1198552e60ea33debe20e8e0d6861d8 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 22 Aug 2024 06:58:39 -0500 Subject: [PATCH 76/93] Add mcl_util.trace_node(), rewrite bamboo growth code to fix bone meal growth --- mods/CORE/mcl_util/init.lua | 22 ++++ mods/ITEMS/mcl_bamboo/globals.lua | 212 +++++++++--------------------- 2 files changed, 84 insertions(+), 150 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 6143bfb41..bdb0303c3 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1131,3 +1131,25 @@ if not vector.in_area then (pos.z >= min.z) and (pos.z <= max.z) end end + +-- Traces along a line of nodes vertically to find the next possition that isn't an allowed node +---@param pos The position to start tracing from +---@param dir The direction to trace in (1 is up, -1 is down) +---@param allowed_nodes A table of node names to trace along +---@param limit The maximum number of steps to make. Defaults to 16 if nil or missing +---@return Three return values: +--- the position of the next node that isn't allowed or nil if no such node was found, +--- the distance from the start where that node was found, +--- the node table if a node was found +function mcl_util.trace_nodes(pos, dir, allowed_nodes, limit) + if not dir or dir == 0 or #allowed_nodes == 0 then return nil, 0, nil end + limit = limit or 16 + + for i = 1,limit do + pos = vector.offset(pos, 0, dir, 0) + local node = minetest.get_node(pos) + if table.indexof(allowed_nodes, node.name) == -1 then return pos, i, node end + end + + return nil, limit, nil +end diff --git a/mods/ITEMS/mcl_bamboo/globals.lua b/mods/ITEMS/mcl_bamboo/globals.lua index 9c7db5486..250f9b926 100644 --- a/mods/ITEMS/mcl_bamboo/globals.lua +++ b/mods/ITEMS/mcl_bamboo/globals.lua @@ -94,172 +94,84 @@ end --]] function mcl_bamboo.grow_bamboo(pos, bonemeal_applied) + local log = mcl_bamboo.mcl_log local node_above = minetest.get_node(vector.offset(pos, 0, 1, 0)) - mcl_bamboo.mcl_log("Grow bamboo called; bonemeal: " .. tostring(bonemeal_applied)) + log("Grow bamboo called; bonemeal: " .. tostring(bonemeal_applied)) - if not bonemeal_applied and mcl_bamboo.is_bamboo(node_above.name) ~= false then - return false -- short circuit this function if we're trying to grow (std) the bamboo and it's not the top shoot. + if not bonemeal_applied then + -- Only allow natural growth at the top of the bamboo + if mcl_bamboo.is_bamboo(node_above.name) ~= false then return false end + + -- Don't perform natual growth in low light + if minetest.get_node_light(pos) < 8 then return false end end - if minetest.get_node_light(pos) < 8 then + + -- Determine the location of soil + local soil_pos + soil_pos,a,b = mcl_util.trace_nodes(pos, -1, mcl_bamboo.bamboo_index, BAMBOO_MAX_HEIGHT - 1) + + -- No soil found, return false so that bonemeal isn't used + if not soil_pos then return false end + log("Grow bamboo; soil found. ") + + -- Find the first bamboo shoot and retrieve data about it + local first_shoot = vector.offset(soil_pos, 0, 1, 0) + local first_shoot_meta = minetest.get_meta(first_shoot) + + -- Get or initialize bamboo height + local height = (first_shoot_meta and first_shoot_meta:get_int("height", -1)) or -1 + if height == -1 then + height = rand(BAM_MAX_HEIGHT_STPCHK + 1, BAM_MAX_HEIGHT_TOP + 1) + first_shoot_meta:set_int("height", height) + end + log("Grow bamboo; height: " .. height) + + -- Locate the bamboo tip + local bamboo_tip,actual_height,bamboo_tip_node = mcl_util.trace_nodes(first_shoot, 1, mcl_bamboo.bamboo_index, height - 1) + log("Current height: "..tostring(actual_height)) + + -- Short circuit growth if the bamboo is already finished growing + if not bamboo_tip or not actual_height or actual_height >= height then + log("Bamboo is already as large as it can grow") return false end - -- variables used in more than one spot. - local first_shoot - local chk_pos - local soil_pos - local node_name = "" - local dist = 0 - local node_below - -- ------------------- + -- Now that we are actually going to add nodes, initialize some more information + local first_shoot_node_name = minetest.get_node(first_shoot).name - mcl_bamboo.mcl_log("Grow bamboo; checking for soil: ") - -- the soil node below the bamboo. - for py = -1, BAMBOO_SOIL_DIST, -1 do - chk_pos = vector.offset(pos, 0, py, 0) - node_name = minetest.get_node(chk_pos).name - if mcl_bamboo.is_dirt(node_name) then - soil_pos = chk_pos - break - end - if mcl_bamboo.is_bamboo(node_name) == false then - break - end - end - -- requires knowing where the soil node is. - if soil_pos == nil then - return false -- returning false means don't use up the bonemeal. - end - - mcl_bamboo.mcl_log("Grow bamboo; soil found. ") - local grow_amount = rand(1, GROW_DOUBLE_CHANCE) - grow_amount = rand(1, GROW_DOUBLE_CHANCE) - grow_amount = rand(1, GROW_DOUBLE_CHANCE) -- because yeah, not truly random, or even a good prng. - grow_amount = rand(1, GROW_DOUBLE_CHANCE) - local init_height = rand(BAM_MAX_HEIGHT_STPCHK + 1, BAM_MAX_HEIGHT_TOP + 1) - mcl_bamboo.mcl_log("Grow bamboo; random height: " .. init_height) - - node_name = "" - - -- update: add randomized max height to first node's meta data. - first_shoot = vector.offset(soil_pos, 0, 1, 0) - local meta = minetest.get_meta(first_shoot) - node_below = minetest.get_node(first_shoot).name - - mcl_bamboo.mcl_log("Grow bamboo; checking height meta ") - -- check the meta data for the first node, to see how high to make the stalk. - if not meta then - -- if no metadata, set the metadata!!! - meta:set_int("height", init_height) - end - local height = meta:get_int("height", -1) - mcl_bamboo.mcl_log("Grow bamboo; meta-height: " .. height) - if height <= 10 then - height = init_height - meta:set_int("height", init_height) - end - - mcl_bamboo.mcl_log("Grow bamboo; height: " .. height) - - -- Bonemeal: Grows the bamboo by 1-2 stems. (per the minecraft wiki.) + -- If applying bonemeal, randomly grow two segments instead of one + local grow_amount = 1 if bonemeal_applied then - -- handle applying bonemeal. - for py = 1, BAM_MAX_HEIGHT_TOP do - -- find the top node of bamboo. - chk_pos = vector.offset(pos, 0, py, 0) - node_name = minetest.get_node(chk_pos).name - dist = vector.distance(soil_pos, chk_pos) - if mcl_bamboo.is_bamboo(node_name) == false or node_name == BAMBOO_ENDCAP_NAME then - break - end - end - - mcl_bamboo.mcl_log("Grow bamboo; dist: " .. dist) - - if node_name == BAMBOO_ENDCAP_NAME then - -- prevent overgrowth - return false - end - - -- check to see if we have a full stalk of bamboo. - if dist >= height - 1 then - if dist == height - 1 then - -- equals top of the stalk before the cap - if node_name == "air" then - mcl_bamboo.mcl_log("Grow bamboo; Placing endcap") - minetest.set_node(vector.offset(chk_pos, 0, 1, 0), { name = BAMBOO_ENDCAP_NAME }) - return true -- returning true means use up the bonemeal. - else - return false - end - else - -- okay, we're higher than the end cap, fail out. - return false -- returning false means don't use up the bonemeal. - end - end - - -- and now, the meat of the section... add bamboo to the stalk. - -- at this point, we should be lower than the generated maximum height. ~ about height -2 or lower. - if dist <= height - 2 then - if node_name == "air" then - -- here we can check to see if we can do up to 2 bamboo shoots onto the stalk - mcl_bamboo.mcl_log("Grow bamboo; Placing bamboo.") - minetest.set_node(chk_pos, { name = node_below }) - -- handle growing a second node. - if grow_amount == 2 then - chk_pos = vector.offset(chk_pos, 0, 1, 0) - if minetest.get_node(chk_pos).name == "air" then - mcl_bamboo.mcl_log("Grow bamboo; OOOH! It's twofer day!") - minetest.set_node(chk_pos, { name = node_below }) - end - end - return true -- exit out with a success. We've added 1-2 nodes, per the wiki. - end + local rng = PcgRandom(minetest.hash_node_position(pos) + minetest.get_us_time()) + if rng:next(1, GROW_DOUBLE_CHANGE) == 1 then + grow_amount = 2 end end + log("Growing up to "..grow_amount.." segments") - -- Non-Bonemeal growth. - for py = 1, BAM_MAX_HEIGHT_TOP do - -- Find the topmost node above the stalk, and check it for "air" - chk_pos = vector.offset(pos, 0, py, 0) - node_below = minetest.get_node(pos).name - node_name = minetest.get_node(chk_pos).name - dist = vector.distance(soil_pos, chk_pos) - - if node_name ~= "air" and mcl_bamboo.is_bamboo(node_name) == false then - break + -- Perform bamboo growth + for i = 1,grow_amount do + -- Check for air to grow into + local bamboo_tip_node = minetest.get_node(bamboo_tip) + if not bamboo_tip_node or bamboo_tip_node.name ~= "air" then + -- Something is blocking growth, stop and signal that use bonemeal has been used if at least on segment has grown + return i ~= 1 end - -- stop growing check. ie, handle endcap placement. - if dist >= height - 1 then - local above_node_name = minetest.get_node(vector.offset(chk_pos, 0, 1, 0)).name - if node_name == "air" and above_node_name == "air" then - if height - 1 == dist then - mcl_bamboo.mcl_log("Grow bamboo; Placing endcap") - minetest.set_node(chk_pos, { name = BAMBOO_ENDCAP_NAME }) - end - end - break + if actual_height + 1 == height then + -- This is the end cap + minetest.set_node(bamboo_tip, { name = BAMBOO_ENDCAP_NAME }) + return true + else + -- This isn't the end cap, add a bamboo segment + minetest.set_node(bamboo_tip, { name = first_shoot_node_name }) + actual_height = actual_height + 1 end - -- handle regular node placement. - -- find the air node above the top shoot. place a node. And then, if short enough, - -- check for second node placement. - if node_name == "air" then - mcl_bamboo.mcl_log("Grow bamboo; dist: " .. dist) - mcl_bamboo.mcl_log("Grow bamboo; Placing bamboo.") - minetest.set_node(chk_pos, { name = node_below }) - -- handle growing a second node. (1 in 32 chance.) - if grow_amount == 2 and dist <= height - 2 then - chk_pos = vector.offset(chk_pos, 0, 1, 0) - if minetest.get_node(chk_pos).name == "air" then - mcl_bamboo.mcl_log("Grow bamboo; OOOH! It's twofer day!") - minetest.set_node(chk_pos, { name = node_below }) - end - end - break - end + bamboo_tip = vector.offset(bamboo_tip, 0, 1, 0) end + + return true end -- Add Groups function, courtesy of Warr1024. From 981cddddd4ca69eefd5850afe45b78463f96ee6c Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 22 Aug 2024 07:29:35 -0500 Subject: [PATCH 77/93] Add growth limits to crimson/twisting vines --- mods/ITEMS/mcl_crimson/init.lua | 44 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 4bc97c743..bf1b0ca80 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -5,6 +5,8 @@ local modpath = minetest.get_modpath(modname) -- by debiankaios -- adapted for mcl2 by cora +local MAXIMUM_VINE_HEIGHT = 25 + local wood_slab_groups = {handy = 1, axey = 1, material_wood = 1, wood_slab = 1} local wood_stair_groups = {handy = 1, axey = 1, material_wood = 1, wood_stairs = 1} @@ -16,23 +18,35 @@ function generate_crimson_tree(pos) minetest.place_schematic(pos,modpath.."/schematics/crimson_fungus_1.mts","random",nil,false,"place_center_x,place_center_z") end -function grow_vines(pos, moreontop ,vine, dir) +function grow_vines(pos, moreontop, vine, dir) + -- Sanity checks if dir == nil then dir = 1 end - local n - repeat - pos = vector.offset(pos,0,dir,0) - n = minetest.get_node(pos) - if n.name == "air" then - for i=0,math.max(moreontop,1) do - if minetest.get_node(pos).name == "air" then - minetest.set_node(vector.offset(pos,0,i*dir,0),{name=vine}) - end - end - return true - end - until n.name ~= "air" and n.name ~= vine + if not moreontop or moreontop < 1 then return false end - return false + local allowed_nodes = {vine} + + -- Find the root, tip and calculate height + local root,_,root_node = mcl_util.trace_nodes(pos, -dir, allowed_nodes, MAXIMUM_VINE_HEIGHT) + if not root then return false end + local tip,height,tip_node = mcl_util.trace_nodes(vector.offset(root, 0, dir, 0), dir, allowed_nodes, MAXIMUM_VINE_HEIGHT) + if not tip then return false end + + local res = false + for i = 1,moreontop do + -- Check if we can grow into this position + if height >= MAXIMUM_VINE_HEIGHT then return res end + if tip_node.name ~= "air" then return res end + + -- Update world map data + minetest.set_node(tip, {name = vine}) + + -- Move to the next position and flag that growth has occured + tip = vector.offset(tip, 0, dir, 0) + tip_node = minetest.get_node(tip) + height = height + 1 + res = true + end + return res end local nether_plants = { From 189a2c62adef3549a10640a42b2560884c1e7b88 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 24 Aug 2024 10:27:34 -0500 Subject: [PATCH 78/93] Address review comments on mcl_util.trace_nodes --- mods/CORE/mcl_util/init.lua | 8 ++++---- mods/ITEMS/mcl_bamboo/globals.lua | 8 ++++++-- mods/ITEMS/mcl_crimson/init.lua | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index bdb0303c3..a9d815f58 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1134,21 +1134,21 @@ end -- Traces along a line of nodes vertically to find the next possition that isn't an allowed node ---@param pos The position to start tracing from ----@param dir The direction to trace in (1 is up, -1 is down) ----@param allowed_nodes A table of node names to trace along +---@param dir The direction to trace in. 1 is up, -1 is down, all other values are not allowed. +---@param allowed_nodes A set of node names to trace along. ---@param limit The maximum number of steps to make. Defaults to 16 if nil or missing ---@return Three return values: --- the position of the next node that isn't allowed or nil if no such node was found, --- the distance from the start where that node was found, --- the node table if a node was found function mcl_util.trace_nodes(pos, dir, allowed_nodes, limit) - if not dir or dir == 0 or #allowed_nodes == 0 then return nil, 0, nil end + if ( dir ~= -1 ) and ( dir ~= 1 ) then return nil, 0, nil end limit = limit or 16 for i = 1,limit do pos = vector.offset(pos, 0, dir, 0) local node = minetest.get_node(pos) - if table.indexof(allowed_nodes, node.name) == -1 then return pos, i, node end + if not allowed_nodes[node.name] then return pos, i, node end end return nil, limit, nil diff --git a/mods/ITEMS/mcl_bamboo/globals.lua b/mods/ITEMS/mcl_bamboo/globals.lua index 250f9b926..eea779b90 100644 --- a/mods/ITEMS/mcl_bamboo/globals.lua +++ b/mods/ITEMS/mcl_bamboo/globals.lua @@ -44,6 +44,10 @@ mcl_bamboo.bamboo_index = { "mcl_bamboo:bamboo_2", "mcl_bamboo:bamboo_3", } +mcl_bamboo.bamboo_set = {} +for _,key in pairs(mcl_bamboo.bamboo_index) do + mcl_bamboo.bamboo_set[key] = true +end function mcl_bamboo.is_bamboo(node_name) local index = table.indexof(mcl_bamboo.bamboo_index, node_name) @@ -108,7 +112,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied) -- Determine the location of soil local soil_pos - soil_pos,a,b = mcl_util.trace_nodes(pos, -1, mcl_bamboo.bamboo_index, BAMBOO_MAX_HEIGHT - 1) + soil_pos,a,b = mcl_util.trace_nodes(pos, -1, mcl_bamboo.bamboo_set, BAMBOO_MAX_HEIGHT - 1) -- No soil found, return false so that bonemeal isn't used if not soil_pos then return false end @@ -127,7 +131,7 @@ function mcl_bamboo.grow_bamboo(pos, bonemeal_applied) log("Grow bamboo; height: " .. height) -- Locate the bamboo tip - local bamboo_tip,actual_height,bamboo_tip_node = mcl_util.trace_nodes(first_shoot, 1, mcl_bamboo.bamboo_index, height - 1) + local bamboo_tip,actual_height,bamboo_tip_node = mcl_util.trace_nodes(first_shoot, 1, mcl_bamboo.bamboo_set, height - 1) log("Current height: "..tostring(actual_height)) -- Short circuit growth if the bamboo is already finished growing diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index bf1b0ca80..6920c4dc6 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -23,7 +23,8 @@ function grow_vines(pos, moreontop, vine, dir) if dir == nil then dir = 1 end if not moreontop or moreontop < 1 then return false end - local allowed_nodes = {vine} + local allowed_nodes = {} + allowed_nodes[vine] = true -- Find the root, tip and calculate height local root,_,root_node = mcl_util.trace_nodes(pos, -dir, allowed_nodes, MAXIMUM_VINE_HEIGHT) From 6ada1a34772c89aae77a1465c34d6ec67b9e298f Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 24 Aug 2024 18:07:27 -0500 Subject: [PATCH 79/93] Remove check with mcl_core.check_vines_supported for twisted and crimson vines --- mods/ITEMS/mcl_crimson/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_crimson/init.lua b/mods/ITEMS/mcl_crimson/init.lua index 6920c4dc6..919538860 100644 --- a/mods/ITEMS/mcl_crimson/init.lua +++ b/mods/ITEMS/mcl_crimson/init.lua @@ -199,7 +199,7 @@ minetest.register_node("mcl_crimson:twisting_vines", { local above = vector.offset(pos,0,1,0) local abovenode = minetest.get_node(above) minetest.node_dig(pos, node, digger) - if abovenode.name == node.name and (not mcl_core.check_vines_supported(above, abovenode)) then + if abovenode.name == node.name then minetest.registered_nodes[node.name].on_dig(above, node, digger) end end, @@ -294,7 +294,7 @@ minetest.register_node("mcl_crimson:weeping_vines", { local below = vector.offset(pos,0,-1,0) local belownode = minetest.get_node(below) minetest.node_dig(pos, node, digger) - if belownode.name == node.name and (not mcl_core.check_vines_supported(below, belownode)) then + if belownode.name == node.name then minetest.registered_nodes[node.name].on_dig(below, node, digger) end end, From 49c8ae2fa01132f467a1f73792f72de7d085072d Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 20 Sep 2024 06:22:44 -0500 Subject: [PATCH 80/93] Quick patch to get cherry saplings growing pending inclusing of a proper tree API --- mods/ITEMS/mcl_core/functions.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 399b2d15c..49395b588 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -962,6 +962,7 @@ end -- pos: Position -- node: Node table of the node at this position, from minetest.get_node -- Returns true on success and false on failure +-- TODO: replace this with a proper tree API function mcl_core.grow_sapling(pos, node) if node.name == "mcl_core:sapling" then grow_oak(pos) @@ -975,6 +976,8 @@ function mcl_core.grow_sapling(pos, node) grow_spruce(pos) elseif node.name == "mcl_core:birchsapling" then grow_birch(pos) + elseif node.name == "mcl_cherry_blossom:cherrysapling" then + return mcl_cherry_blossom.generate_cherry_tree(pos) else return false end From cfdef2435a3adcecd11f9448786f301341489725 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 20 Sep 2024 06:51:56 -0500 Subject: [PATCH 81/93] Show particles regardless of success --- mods/ITEMS/mcl_bone_meal/init.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 2b3bf7041..319f6cce2 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -99,9 +99,7 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) end -- Particle effects - if success then - mcl_bone_meal.add_bone_meal_particle(pos) - end + mcl_bone_meal.add_bone_meal_particle(pos) -- Take the item if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then From 6b1aa43238c838823a9d3135958f34cf03c79b73 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 20 Sep 2024 07:05:14 -0500 Subject: [PATCH 82/93] Only show particles if bone meal is consumed, don't continue testing positions if bonemeal was used on the first check position --- mods/ITEMS/mcl_bone_meal/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index 319f6cce2..dd13f6e58 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -99,7 +99,9 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) end -- Particle effects - mcl_bone_meal.add_bone_meal_particle(pos) + if consume then + mcl_bone_meal.add_bone_meal_particle(pos) + end -- Take the item if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then @@ -107,6 +109,7 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) end if success then return itemstack end + if consume then return itemstack end end return itemstack From 94d9e4c881736b477aa7bf0b0f7768bf6c49a042 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 20 Sep 2024 08:39:11 -0500 Subject: [PATCH 83/93] Address review comments --- mods/CORE/mcl_util/init.lua | 2 +- mods/ITEMS/mcl_bone_meal/init.lua | 33 ++++++++++++++++--------------- mods/ITEMS/mcl_cocoas/init.lua | 3 ++- mods/ITEMS/mcl_cocoas/mod.conf | 4 ++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index a9d815f58..2d2b8a609 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1142,7 +1142,7 @@ end --- the distance from the start where that node was found, --- the node table if a node was found function mcl_util.trace_nodes(pos, dir, allowed_nodes, limit) - if ( dir ~= -1 ) and ( dir ~= 1 ) then return nil, 0, nil end + if (dir ~= -1) and (dir ~= 1) then return nil, 0, nil end limit = limit or 16 for i = 1,limit do diff --git a/mods/ITEMS/mcl_bone_meal/init.lua b/mods/ITEMS/mcl_bone_meal/init.lua index dd13f6e58..e899ca765 100644 --- a/mods/ITEMS/mcl_bone_meal/init.lua +++ b/mods/ITEMS/mcl_bone_meal/init.lua @@ -13,7 +13,7 @@ local usagehelp = S( mcl_bone_meal = {} --- Bone meal particle api: +-- Bone meal particle API: --- Spawns bone meal particles. -- pos: where the particles spawn @@ -21,9 +21,7 @@ mcl_bone_meal = {} -- details on these parameters. -- function mcl_bone_meal.add_bone_meal_particle(pos, def) - if not def then - def = {} - end + def = def or {} minetest.add_particlespawner({ amount = def.amount or 10, time = def.time or 0.1, @@ -65,8 +63,9 @@ end -- local function legacy_apply_bone_meal(pointed_thing, placer) -- Legacy API support - for _, func in pairs(mcl_bone_meal.bone_meal_callbacks) do - if func(pointed_thing, placer) then + local callbacks = mcl_bone_meal.bone_meal_callbacks + for i = 1,#callbacks do + if callbacks[i](pointed_thing, placer) then return true end end @@ -75,7 +74,7 @@ local function legacy_apply_bone_meal(pointed_thing, placer) end -- End legacy bone meal API -mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) +function mcl_bone_meal.use_bone_meal(itemstack, placer, pointed_thing) local positions = {pointed_thing.under, pointed_thing.above} for i = 1,2 do local pos = positions[i] @@ -98,18 +97,19 @@ mcl_bone_meal.use_bone_meal = function(itemstack, placer, pointed_thing) consume = success end - -- Particle effects - if consume then - mcl_bone_meal.add_bone_meal_particle(pos) - end - -- Take the item - if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then - itemstack:take_item() + if consume then + -- Particle effects + mcl_bone_meal.add_bone_meal_particle(pos) + + if not placer or not minetest.is_creative_enabled(placer:get_player_name()) then + itemstack:take_item() + end + + return itemstack end if success then return itemstack end - if consume then return itemstack end end return itemstack @@ -130,7 +130,8 @@ minetest.register_craftitem("mcl_bone_meal:bone_meal", { -- Use pointed node's on_rightclick function first, if present. if placer and not placer:get_player_control().sneak then if ndef and ndef.on_rightclick then - return ndef.on_rightclick(pos, node, placer, itemstack, pointed_thing) or itemstack + local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pointed_thing) + if new_stack and new_stack ~= itemstack then return new_stack end end end diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 970090a1c..2d1a0efd6 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -23,7 +23,8 @@ function mcl_cocoas.place(itemstack, placer, pt, plantname) -- Am I right-clicking on something that has a custom on_rightclick set? if placer and not placer:get_player_control().sneak then if def and def.on_rightclick then - return def.on_rightclick(pt.under, node, placer, itemstack) or itemstack + local new_stack = mcl_util.call_on_rightclick(itemstack, placer, pt) + if new_stack and new_stack ~= itemstack then return new_stack end end end diff --git a/mods/ITEMS/mcl_cocoas/mod.conf b/mods/ITEMS/mcl_cocoas/mod.conf index 867636191..fb084f39a 100644 --- a/mods/ITEMS/mcl_cocoas/mod.conf +++ b/mods/ITEMS/mcl_cocoas/mod.conf @@ -1,4 +1,4 @@ name = mcl_cocoas description = Cocoa pods which grow at jungle trees. Does not include cocoa beans. -depends = mcl_sounds, mcl_core -optional_depends = doc \ No newline at end of file +depends = mcl_sounds, mcl_core, mcl_util +optional_depends = doc From 3514fe211f5e403b37f02406b3c6232f803b4270 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 23 Sep 2024 06:31:02 -0500 Subject: [PATCH 84/93] Implement more bonemeal mod shim, update bonemeal dependencies --- mods/MISC/bonemeal/init.lua | 23 ++++++++++++++++++++++- mods/MISC/bonemeal/mod.conf | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mods/MISC/bonemeal/init.lua b/mods/MISC/bonemeal/init.lua index 666319204..40c60878a 100644 --- a/mods/MISC/bonemeal/init.lua +++ b/mods/MISC/bonemeal/init.lua @@ -1,4 +1,12 @@ -bonemeal = {} +bonemeal = { + item_list = { + bucket_water = "mcl_buckets:bucket_water", + bucket_empty = "mcl_buckets:bucket_empty", + dirt = "mcl_core:dirt", + torch = "mcl_torches:torch", + coral = "mcl_ocean:dead_horn_coral_block" + } +} function bonemeal:on_use(pos, strength, node) -- Fake itemstack for bone meal @@ -10,3 +18,16 @@ function bonemeal:on_use(pos, strength, node) } mcl_bone_meal.use_bone_meal(itemstack, nil, pointed_thing) end + +function bonemeal:is_creative(player_name) + return minetest.is_creative_enabled(player_name) +end + +function bonemeal:add_deco(list) + minetest.log("TODO: implement bonemeal:add_deco("..dump(list).."..)") + for i = 1,#list do + local item = list[i] + end +end + +minetest.register_alias("mcl_mobitems:bone", "bonemeal:bone") diff --git a/mods/MISC/bonemeal/mod.conf b/mods/MISC/bonemeal/mod.conf index 292cc0352..3117bd1ed 100644 --- a/mods/MISC/bonemeal/mod.conf +++ b/mods/MISC/bonemeal/mod.conf @@ -1,4 +1,4 @@ name = bonemeal author = teknomunk description = Compatibility shim for WorldEdit-Additions bonemeal support -optional_depends = mcl_bone_meal +depends = mcl_bone_meal, mcl_mobitems, mcl_flowers From a46833eaa4564603b213c636a8d7e27d6c8d638a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 23 Sep 2024 06:33:05 -0500 Subject: [PATCH 85/93] Fix alias --- mods/MISC/bonemeal/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/MISC/bonemeal/init.lua b/mods/MISC/bonemeal/init.lua index 40c60878a..13f52e7fe 100644 --- a/mods/MISC/bonemeal/init.lua +++ b/mods/MISC/bonemeal/init.lua @@ -30,4 +30,4 @@ function bonemeal:add_deco(list) end end -minetest.register_alias("mcl_mobitems:bone", "bonemeal:bone") +minetest.register_alias("bonemeal:bone", "mcl_mobitems:bone") From f6f5481f30e685446539c40ed71294e5e7dda8fc Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 10 Nov 2024 11:41:19 +0100 Subject: [PATCH 86/93] Attempt to fix chest minecarts, at least for 5.9 (#4684) Not using the `RecheckCartHack` on >5.9 seems to help with #4670 - not tested on older minetest; chest minecarts might still be empty there when the block is unloaded in the meantime. For <5.9, maybe it helps to decrease the time interval, 3 seconds seems to fairly long. This also makes the minecarts random: 40% minecart, 40% chest minecart, 20% tnt minecart. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4684 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/MAPGEN/tsm_railcorridors/gameconfig.lua | 14 ++++++++++---- mods/MAPGEN/tsm_railcorridors/init.lua | 13 ++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua index 2e80c60c8..9f924f00b 100644 --- a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua +++ b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua @@ -36,7 +36,11 @@ else end end -tsm_railcorridors.carts = { "mcl_minecarts:chest_minecart" } +tsm_railcorridors.carts = { + "mcl_minecarts:minecart", "mcl_minecarts:minecart", + "mcl_minecarts:chest_minecart", "mcl_minecarts:chest_minecart", + "mcl_minecarts:tnt_minecart" +} -- This is called after a spawner has been placed by the game. -- Use this to properly set up the metadata and stuff. @@ -54,9 +58,11 @@ end function tsm_railcorridors.on_construct_cart(_, cart, pr_carts) local l = cart:get_luaentity() local inv = mcl_entity_invs.load_inv(l,27) - local items = tsm_railcorridors.get_treasures(pr_carts) - mcl_loot.fill_inventory(inv, "main", items, pr_carts) - mcl_entity_invs.save_inv(l) + if inv then -- otherwise probably not a chest minecart + local items = tsm_railcorridors.get_treasures(pr_carts) + mcl_loot.fill_inventory(inv, "main", items, pr_carts) + mcl_entity_invs.save_inv(l) + end end -- Fallback function. Returns a random treasure. This function is called for chests diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 66b4d779b..9895ab44c 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -397,7 +397,9 @@ end -- This is a workaround thanks to the fact that minetest.add_entity is unreliable as fuck -- See: https://github.com/minetest/minetest/issues/4759 -- FIXME: Kill this horrible hack with fire as soon you can. -local function RecheckCartHack(params) +local RecheckCartHack = nil +if not minetest.features.random_state_restore then -- proxy for minetest > 5.9.0, this feature will not be removed +RecheckCartHack = function(params) local pos = params[1] local cart_id = params[2] -- Find cart @@ -412,6 +414,7 @@ local function RecheckCartHack(params) end minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos)) end +end -- Try to place a cobweb. -- pos: Position of cobweb @@ -935,13 +938,17 @@ local function spawn_carts() -- See local cart_id = tsm_railcorridors.carts[cart_type] minetest.log("info", "[tsm_railcorridors] Cart spawn attempt: "..minetest.pos_to_string(cpos)) - minetest.add_entity(cpos, cart_id) + local obj = minetest.add_entity(cpos, cart_id) -- This checks if the cart is actually spawned, it's a giant hack! -- Note that the callback function is also called there. -- TODO: Move callback function to this position when the -- minetest.add_entity bug has been fixed (supposedly in 5.9.0?) - minetest.after(3, RecheckCartHack, {cpos, cart_id}) + if RecheckCartHack then + minetest.after(3, RecheckCartHack, {cpos, cart_id}) + else + tsm_railcorridors.on_construct_cart(cpos, obj, pr_carts) + end end end carts_table = {} From fb3c85e289bd4a4a16926861455603b53de11849 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 10 Nov 2024 12:02:20 +0100 Subject: [PATCH 87/93] Improve stalker textures (#4674) - don't change back to default texture when falling, but rather keep the previous texture - use a colorized default texture for gaps in the texture Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4674 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/ENTITIES/mobs_mc/stalker.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/stalker.lua b/mods/ENTITIES/mobs_mc/stalker.lua index 962fbdea9..bcb5a5d7e 100644 --- a/mods/ENTITIES/mobs_mc/stalker.lua +++ b/mods/ENTITIES/mobs_mc/stalker.lua @@ -7,12 +7,13 @@ local S = minetest.get_translator("mobs_mc") --################### -local function get_texture(self) - local on_name = self.standing_on +local function get_texture(self, prev) + local standing_on = minetest.registered_nodes[self.standing_on] + -- TODO: we do not have access to param2 here (color palette index) yet local texture local texture_suff = "" - if on_name and on_name ~= "air" then - local tiles = minetest.registered_nodes[on_name].tiles + if standing_on and (standing_on.walkable or standing_on.groups.liquid) then + local tiles = standing_on.tiles if tiles then local tile = tiles[1] local color @@ -25,7 +26,7 @@ local function get_texture(self) texture = tile end if not color then - color = minetest.colorspec_to_colorstring(minetest.registered_nodes[on_name].color) + color = minetest.colorspec_to_colorstring(standing_on.color) end if color then texture_suff = "^[multiply:" .. color .. "^[hsl:0:0:20" @@ -33,14 +34,19 @@ local function get_texture(self) end end if not texture or texture == "" then + -- try to keep last texture when, e.g., falling + if prev and (not (not self.attack)) == (string.find(prev, "vl_mobs_stalker_overlay_angry.png") ~= nil) then + return prev + end texture = "vl_stalker_default.png" - end - texture = texture:gsub("([\\^:\\[])","\\%1") -- escape texture modifiers - texture = "([combine:16x24:0,0=(" .. texture .. "):0,16=(" .. texture ..")".. texture_suff - if self.attack then - texture = texture .. ")^vl_mobs_stalker_overlay_angry.png" else - texture = texture .. ")^vl_mobs_stalker_overlay.png" + texture = texture:gsub("([\\^:\\[])", "\\%1") -- escape texture modifiers + texture = "(vl_stalker_default.png^[combine:16x24:0,0=(" .. texture .. "):0,16=(" .. texture .. ")" .. texture_suff .. ")" + end + if self.attack then + texture = texture .. "^vl_mobs_stalker_overlay_angry.png" + else + texture = texture .. "^vl_mobs_stalker_overlay.png" end return texture end @@ -132,7 +138,7 @@ mcl_mobs.register_mob("mobs_mc:stalker", { self:boom(mcl_util.get_object_center(self.object), self.explosion_strength) end end - local new_texture = get_texture(self) + local new_texture = get_texture(self, self._stalker_texture) if self._stalker_texture ~= new_texture then self.object:set_properties({textures={new_texture, "mobs_mc_empty.png"}}) self._stalker_texture = new_texture From bd9ab16762fdcf9519cd0f29030d26e3b46a8ee1 Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 18:30:59 +0200 Subject: [PATCH 88/93] Add touch_interaction to (cross)bow and spyglass --- mods/ITEMS/mcl_bows/bow.lua | 2 ++ mods/ITEMS/mcl_bows/crossbow.lua | 3 +++ mods/ITEMS/mcl_spyglass/init.lua | 1 + 3 files changed, 6 insertions(+) diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 34784ab07..88bea6444 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -169,6 +169,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) @@ -235,6 +236,7 @@ for level=0, 2 do on_place = function(itemstack) return itemstack end, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) end diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index b6dc31dd0..0810e6a8c 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -159,6 +159,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 326, }) @@ -194,6 +195,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula return itemstack end, groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1}, + touch_interaction = "short_dig_long_place", _mcl_uses = 326, }) @@ -257,6 +259,7 @@ for level=0, 2 do on_place = function(itemstack) return itemstack end, + touch_interaction = "short_dig_long_place", _mcl_uses = 385, }) end diff --git a/mods/ITEMS/mcl_spyglass/init.lua b/mods/ITEMS/mcl_spyglass/init.lua index afa7adaf4..c0854d3b6 100644 --- a/mods/ITEMS/mcl_spyglass/init.lua +++ b/mods/ITEMS/mcl_spyglass/init.lua @@ -6,6 +6,7 @@ minetest.register_tool("mcl_spyglass:spyglass",{ inventory_image = "mcl_spyglass.png", stack_max = 1, _mcl_toollike_wield = true, + touch_interaction = "short_dig_long_place", }) minetest.register_craft({ From cb624fe1d95c642209e2ecefc7bc5bb6106d967f Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 19:31:27 +0200 Subject: [PATCH 89/93] Creative inventory: Make the whole tab button clickable Previously, only the tab icon was clickable. Clicking next to the icon would just close the inventory. The icon is still kept clickable too since that gives a nicer press animation. I didn't end up using image_button because that resulted in a different image size and position, even with the exact same coordinates. --- mods/HUD/mcl_inventory/creative.lua | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 4ddbd0823..7ae4a1098 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -566,8 +566,10 @@ function mcl_inventory.set_creative_formspec(player) bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png" end return table.concat({ - "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]", - "image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]", + "style[" .. this_tab .. ";border=false;noclip=true;bgimg=;bgimg_pressed=]", + "style[" .. this_tab .. "_outer;border=false;noclip=true;bgimg=" .. bg_img .. + ";bgimg_pressed=" .. bg_img .. "]", + "button[" .. offset[this_tab] .. ";1.5,1.44;" .. this_tab .. "_outer;]", "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]", }) end @@ -581,8 +583,6 @@ function mcl_inventory.set_creative_formspec(player) "formspec_version[6]", "size[13,8.75]", - "style_type[image;noclip=true]", - -- Hotbar mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1), "list[current_player;main;0.375,7.375;9,1;]", @@ -655,54 +655,54 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local name = player:get_player_name() - if fields.blocks then + if fields.blocks or fields.blocks_outer then if players[name].page == "blocks" then return end set_inv_page("blocks", player) page = "blocks" - elseif fields.deco then + elseif fields.deco or fields.deco_outer then if players[name].page == "deco" then return end set_inv_page("deco", player) page = "deco" - elseif fields.redstone then + elseif fields.redstone or fields.redstone_outer then if players[name].page == "redstone" then return end set_inv_page("redstone", player) page = "redstone" - elseif fields.rail then + elseif fields.rail or fields.rail_outer then if players[name].page == "rail" then return end set_inv_page("rail", player) page = "rail" - elseif fields.misc then + elseif fields.misc or fields.misc_outer then if players[name].page == "misc" then return end set_inv_page("misc", player) page = "misc" - elseif fields.nix then + elseif fields.nix or fields.nix_outer then set_inv_page("all", player) page = "nix" - elseif fields.food then + elseif fields.food or fields.food_outer then if players[name].page == "food" then return end set_inv_page("food", player) page = "food" - elseif fields.tools then + elseif fields.tools or fields.tools_outer then if players[name].page == "tools" then return end set_inv_page("tools", player) page = "tools" - elseif fields.combat then + elseif fields.combat or fields.combat_outer then if players[name].page == "combat" then return end set_inv_page("combat", player) page = "combat" - elseif fields.mobs then + elseif fields.mobs or fields.mobs_outer then if players[name].page == "mobs" then return end set_inv_page("mobs", player) page = "mobs" - elseif fields.brew then + elseif fields.brew or fields.brew_outer then if players[name].page == "brew" then return end set_inv_page("brew", player) page = "brew" - elseif fields.matr then + elseif fields.matr or fields.matr_outer then if players[name].page == "matr" then return end set_inv_page("matr", player) page = "matr" - elseif fields.inv then + elseif fields.inv or fields.inv_outer then if players[name].page == "inv" then return end page = "inv" elseif fields.search == "" and not fields.creative_next and not fields.creative_prev then From 02b354f54ac9894237ee987558f9d56098a4a58b Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 19:53:20 +0200 Subject: [PATCH 90/93] Avoid tab buttons going off-screen with high scaling values --- mods/HUD/mcl_inventory/creative.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 7ae4a1098..0effcc1bc 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -566,8 +566,8 @@ function mcl_inventory.set_creative_formspec(player) bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png" end return table.concat({ - "style[" .. this_tab .. ";border=false;noclip=true;bgimg=;bgimg_pressed=]", - "style[" .. this_tab .. "_outer;border=false;noclip=true;bgimg=" .. bg_img .. + "style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=]", + "style[" .. this_tab .. "_outer;border=false;bgimg=" .. bg_img .. ";bgimg_pressed=" .. bg_img .. "]", "button[" .. offset[this_tab] .. ";1.5,1.44;" .. this_tab .. "_outer;]", "item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]", @@ -581,7 +581,13 @@ function mcl_inventory.set_creative_formspec(player) local formspec = table.concat({ "formspec_version[6]", - "size[13,8.75]", + -- Original formspec height was 8.75, increased to include tab buttons. + -- This avoids tab buttons going off-screen with high scaling values. + "size[13,11.43]", + + "no_prepend[]", mcl_vars.gui_nonbg, mcl_vars.gui_bg_color, + "background9[0,1.34;13,8.75;mcl_base_textures_background9.png;;7]", + "container[0,1.34]", -- Hotbar mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1), @@ -638,6 +644,7 @@ function mcl_inventory.set_creative_formspec(player) "set_focus[search;true]", }) end + formspec = formspec .. "container_end[]" if pagenum then formspec = formspec .. "p" .. tostring(pagenum) end player:set_inventory_formspec(formspec) end From 3954acdfb7c86970a03f00d37dff6403e74c4879 Mon Sep 17 00:00:00 2001 From: grorp Date: Wed, 25 Sep 2024 20:56:59 +0200 Subject: [PATCH 91/93] Creative inventory: padding[-0.015,-0.015] on mobile - less wasted screen space - matches old layout --- mods/HUD/mcl_inventory/creative.lua | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 0effcc1bc..ece965156 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -418,6 +418,18 @@ minetest.register_on_joinplayer(function(player) end end) +---@param player mt.PlayerObjectRef +local function is_touch_enabled(playername) + -- Minetest < 5.7.0 support + if not minetest.get_player_window_information then + return false + end + local window = minetest.get_player_window_information(playername) + -- Always return a boolean (not nil) to avoid false-negatives when + -- comparing to a boolean later. + return window and window.touch_controls or false +end + ---@param player mt.PlayerObjectRef function mcl_inventory.set_creative_formspec(player) local playername = player:get_player_name() @@ -579,11 +591,17 @@ function mcl_inventory.set_creative_formspec(player) caption = "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, filtername[name])) .. "]" end + local touch_enabled = is_touch_enabled(playername) + players[playername].last_touch_enabled = touch_enabled + local formspec = table.concat({ "formspec_version[6]", -- Original formspec height was 8.75, increased to include tab buttons. -- This avoids tab buttons going off-screen with high scaling values. "size[13,11.43]", + -- Use as much space as possible on mobile - the tab buttons are a lot + -- of padding already. + touch_enabled and "padding[-0.015,-0.015]" or "", "no_prepend[]", mcl_vars.gui_nonbg, mcl_vars.gui_bg_color, "background9[0,1.34;13,8.75;mcl_base_textures_background9.png;;7]", @@ -825,3 +843,17 @@ minetest.register_on_player_inventory_action(function(player, action, inventory, player:get_inventory():set_stack("main", inventory_info.index, stack) end end) + +-- This is necessary because get_player_window_information may return nil in +-- on_joinplayer. +-- (Also, Minetest plans to add support for toggling touchscreen mode in-game.) +mcl_player.register_globalstep_slow(function(player) + local name = player:get_player_name() + + if minetest.is_creative_enabled(name) then + local touch_enabled = is_touch_enabled(name) + if touch_enabled ~= players[name].last_touch_enabled then + mcl_inventory.set_creative_formspec(player) + end + end +end) From 88c3c4558bf2e5bfcd7aa08863c779ec2dcff63b Mon Sep 17 00:00:00 2001 From: grorp Date: Thu, 17 Oct 2024 14:05:51 +0200 Subject: [PATCH 92/93] Fix for VoxeLibre --- mods/HUD/mcl_inventory/creative.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index ece965156..18b3b4c5e 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -847,13 +847,15 @@ end) -- This is necessary because get_player_window_information may return nil in -- on_joinplayer. -- (Also, Minetest plans to add support for toggling touchscreen mode in-game.) -mcl_player.register_globalstep_slow(function(player) - local name = player:get_player_name() +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() - if minetest.is_creative_enabled(name) then - local touch_enabled = is_touch_enabled(name) - if touch_enabled ~= players[name].last_touch_enabled then - mcl_inventory.set_creative_formspec(player) + if minetest.is_creative_enabled(name) then + local touch_enabled = is_touch_enabled(name) + if touch_enabled ~= players[name].last_touch_enabled then + mcl_inventory.set_creative_formspec(player) + end end end end) From 4dc5d0939c499e5f9e5b29ef14bd1e91f8b0419a Mon Sep 17 00:00:00 2001 From: marro Date: Mon, 11 Nov 2024 03:49:43 +0100 Subject: [PATCH 93/93] Whitespace fix in translation (#4701) Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4701 Reviewed-by: the-real-herowl Co-authored-by: marro Co-committed-by: marro --- mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr index 61df77d59..197151a36 100644 --- a/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr +++ b/mods/ITEMS/mcl_bone_meal/locale/mcl_bonemeal.fr.tr @@ -1,6 +1,5 @@ # textdomain: mcl_bone_meal Bone Meal=Farine d'Os Bone meal is a white dye and also useful as a fertilizer to speed up the growth of many plants.=La farine d'os est une teinture blanche et est également utile comme engrais pour accélérer la croissance de nombreuses plantes. -Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.= -Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Cependant, toutes les plantes ne peuvent pas être fertilisées de cette manière. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent autour. +Rightclick a sheep to turn its wool white. Rightclick a plant to speed up its growth. Note that not all plants can be fertilized like this. When you rightclick a grass block, tall grass and flowers will grow all over the place.=Cliquez avec le bouton droit sur un mouton pour blanchir sa laine. Cliquez avec le bouton droit sur une plante pour accélérer sa croissance. Cependant, toutes les plantes ne peuvent pas être fertilisées de cette manière. Lorsque vous cliquez avec le bouton droit sur un bloc d'herbe, les hautes herbes et les fleurs poussent autour. Speeds up plant growth=Accélère la croissance des plantes