add helper function and new screenshot

This commit is contained in:
tenplus1 2022-11-02 14:30:24 +00:00
parent 757b85d02f
commit 9049dbfefa
13 changed files with 89 additions and 132 deletions

View File

@ -35,5 +35,6 @@ Changelog:
- 1.3 - Ability to craft dye from mulch, bonemeal and fertiliser (thanks orbea) - 1.3 - Ability to craft dye from mulch, bonemeal and fertiliser (thanks orbea)
- 1.4 - Add support for fern saplings from plantlife mod (thanks nixnoxus) - 1.4 - Add support for fern saplings from plantlife mod (thanks nixnoxus)
- 1.5 - Add support for farming redo's asparagus, eggplant, spinach - 1.5 - Add support for farming redo's asparagus, eggplant, spinach
- 1.6 - Add helper function for position and protection check, add ginger support
Lucky Blocks: 6 Lucky Blocks: 6

View File

@ -1,5 +1,4 @@
default default
intllib?
farming? farming?
ethereal? ethereal?
moretrees? moretrees?

110
init.lua
View File

@ -5,9 +5,13 @@ local path = minetest.get_modpath("bonemeal")
local min, max, random = math.min, math.max, math.random local min, max, random = math.min, math.max, math.random
-- Load support for intllib. -- translation support
local S = minetest.get_translator and minetest.get_translator("bonemeal") or local S
dofile(path .. "/intllib.lua") if minetest.get_translator ~= nil then
S = minetest.get_translator("bonemeal") -- 5.x translation function
else -- boilerplate function
S = function(s) return s end
end
-- creative check -- creative check
@ -129,7 +133,8 @@ local function particle_effect(pos)
maxexptime = 1, maxexptime = 1,
minsize = 1, minsize = 1,
maxsize = 3, maxsize = 3,
texture = "bonemeal_particle.png" texture = "bonemeal_particle.png",
glow = 5
}) })
end end
@ -138,15 +143,18 @@ end
local function grow_tree(pos, object) local function grow_tree(pos, object)
if type(object) == "table" and object.axiom then if type(object) == "table" and object.axiom then
-- grow L-system tree -- grow L-system tree
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.spawn_tree(pos, object) minetest.spawn_tree(pos, object)
elseif type(object) == "string" and minetest.registered_nodes[object] then elseif type(object) == "string" and minetest.registered_nodes[object] then
-- place node -- place node
minetest.set_node(pos, {name = object}) minetest.set_node(pos, {name = object})
elseif type(object) == "function" then elseif type(object) == "function" then
-- function -- function
object(pos) object(pos)
end end
@ -288,15 +296,20 @@ local function check_soil(pos, nodename, strength)
for _, n in pairs(dirt) do for _, n in pairs(dirt) do
if random(5) == 5 then if random(5) == 5 then
if decor and #decor > 0 then if decor and #decor > 0 then
-- place random decoration (rare) -- place random decoration (rare)
local dnum = #decor or 1 local dnum = #decor or 1
nod = decor[random(dnum)] or "" nod = decor[random(dnum)] or ""
end end
else else
if grass and #grass > 0 then if grass and #grass > 0 then
-- place random grass (common) -- place random grass (common)
local dgra = #grass or 1 local dgra = #grass or 1
nod = #grass > 0 and grass[random(dgra)] or "" nod = #grass > 0 and grass[random(dgra)] or ""
end end
end end
@ -313,7 +326,9 @@ local function check_soil(pos, nodename, strength)
-- if param2 not preset then get from existing node -- if param2 not preset then get from existing node
if not def then if not def then
local node = minetest.get_node_or_nil(pos2) local node = minetest.get_node_or_nil(pos2)
def = node and node.param2 or 0 def = node and node.param2 or 0
end end
@ -425,9 +440,12 @@ function bonemeal:set_deco(list)
-- replace existing entry -- replace existing entry
if list[l][1] == deco[n][1] then if list[l][1] == deco[n][1] then
deco[n][2] = list[l][2] deco[n][2] = list[l][2]
deco[n][3] = list[l][3] deco[n][3] = list[l][3]
list[l] = false list[l] = false
break break
end end
end end
@ -459,13 +477,17 @@ function bonemeal:on_use(pos, strength, node)
if node.name == "default:papyrus" then if node.name == "default:papyrus" then
default.grow_papyrus(pos, node) default.grow_papyrus(pos, node)
particle_effect(pos) particle_effect(pos)
return true return true
elseif node.name == "default:cactus" then elseif node.name == "default:cactus" then
default.grow_cactus(pos, node) default.grow_cactus(pos, node)
particle_effect(pos) particle_effect(pos)
return true return true
end end
@ -473,7 +495,9 @@ function bonemeal:on_use(pos, strength, node)
if minetest.get_item_group(node.name, "soil") > 0 if minetest.get_item_group(node.name, "soil") > 0
or minetest.get_item_group(node.name, "sand") > 0 or minetest.get_item_group(node.name, "sand") > 0
or minetest.get_item_group(node.name, "can_bonemeal") > 0 then or minetest.get_item_group(node.name, "can_bonemeal") > 0 then
check_soil(pos, node.name, strength) check_soil(pos, node.name, strength)
return true return true
end end
@ -497,6 +521,39 @@ function bonemeal:on_use(pos, strength, node)
end end
-- helper function
local function find_pos(user, pointed_thing)
-- make sure we use on node
if pointed_thing.type ~= "node" then
return false
end
-- get position and node info
local pos = pointed_thing.under
local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name]
local dirt = def and def.groups
-- does node exist
if not dirt then
return false
end
-- if we're using on ground, move position up
if dirt.soil or dirt.sand or dirt.can_bonemeal then
pos = pointed_thing.above
end
-- check if protected
if minetest.is_protected(pos, user:get_player_name()) then
return false
end
return pos, node
end
-- --
-- items -- items
-- --
@ -509,18 +566,11 @@ minetest.register_craftitem("bonemeal:mulch", {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- did we point at a node? -- use helper function to do checks and return position and node
if pointed_thing.type ~= "node" then local pos, node = find_pos(user, pointed_thing)
return
end
-- is area protected?
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
return
end
-- call global on_use function with strength of 1 -- call global on_use function with strength of 1
if bonemeal:on_use(pointed_thing.under, 1) then if pos and bonemeal:on_use(pointed_thing.under, 1, node) then
-- take item if not in creative -- take item if not in creative
if not bonemeal.is_creative(user:get_player_name()) then if not bonemeal.is_creative(user:get_player_name()) then
@ -540,18 +590,11 @@ minetest.register_craftitem("bonemeal:bonemeal", {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- did we point at a node? -- use helper function to do checks and return position and node
if pointed_thing.type ~= "node" then local pos, node = find_pos(user, pointed_thing)
return
end
-- is area protected?
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
return
end
-- call global on_use function with strength of 2 -- call global on_use function with strength of 2
if bonemeal:on_use(pointed_thing.under, 2) then if pos and bonemeal:on_use(pointed_thing.under, 2, node) then
-- take item if not in creative -- take item if not in creative
if not bonemeal.is_creative(user:get_player_name()) then if not bonemeal.is_creative(user:get_player_name()) then
@ -571,18 +614,11 @@ minetest.register_craftitem("bonemeal:fertiliser", {
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- did we point at a node? -- use helper function to do checks and return position and node
if pointed_thing.type ~= "node" then local pos, node = find_pos(user, pointed_thing)
return
end
-- is area protected?
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
return
end
-- call global on_use function with strength of 3 -- call global on_use function with strength of 3
if bonemeal:on_use(pointed_thing.under, 3) then if pos and bonemeal:on_use(pointed_thing.under, 3, node) then
-- take item if not in creative -- take item if not in creative
if not bonemeal.is_creative(user:get_player_name()) then if not bonemeal.is_creative(user:get_player_name()) then
@ -691,7 +727,11 @@ minetest.override_item("default:dirt", {
-- add support for other mods -- add support for other mods
dofile(path .. "/mods.lua") dofile(path .. "/mods.lua")
dofile(path .. "/lucky_block.lua")
-- lucky block support
if minetest.get_modpath("lucky_block") then
dofile(path .. "/lucky_block.lua")
end
print ("[MOD] bonemeal loaded") print ("[MOD] bonemeal loaded")

View File

@ -1,45 +0,0 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -1,7 +0,0 @@
# init.lua
Mulch = Mantillo
Bone Meal = Comida de hueso
Fertiliser = Fertilizante
Bone = Hueso
[MOD] bonemeal loaded = [MOD] bonemeal cargado

View File

@ -1,7 +0,0 @@
# init.lua
Mulch = Paillis
Bone Meal = Poudre d'os
Fertiliser = Engrais
Bone = Os
[MOD] bonemeal loaded = [MOD] bonemeal chargé

View File

@ -1,7 +0,0 @@
# init.lua
Mulch = Pacciame
Bone Meal = Pasto osseo
Fertiliser = Fertilizzante
Bone = Ossa
[MOD] bonemeal loaded = [MOD] bonemeal caricata

View File

@ -1,7 +0,0 @@
# init.lua
Mulch = Мульча
Bone Meal = Костная Мука
Fertiliser = Удобрение
Bone = Кость
[MOD] bonemeal loaded = [MOD] костная мука загружена

View File

@ -1,7 +0,0 @@
# init.lua
Mulch =
Bone Meal =
Fertiliser =
Bone =
[MOD] bonemeal loaded =

View File

@ -11,9 +11,7 @@ local function growy(pos, player)
end end
if minetest.get_modpath("lucky_block") then lucky_block:add_blocks({
lucky_block:add_blocks({
{"lig"}, {"lig"},
{"dro", {"bonemeal:mulch"}, 10}, {"dro", {"bonemeal:mulch"}, 10},
{"dro", {"bonemeal:bonemeal"}, 10}, {"dro", {"bonemeal:bonemeal"}, 10},
@ -24,5 +22,4 @@ if minetest.get_modpath("lucky_block") then
{name = "bonemeal:bonemeal", max = 15}, {name = "bonemeal:bonemeal", max = 15},
{name = "bonemeal:fertiliser", max = 10} {name = "bonemeal:fertiliser", max = 10}
}} }}
}) })
end

View File

@ -1,4 +1,4 @@
name = bonemeal name = bonemeal
depends = default depends = default
optional_depends = intllib, lucky_block, farming, ethereal, moretrees, technic_worldgen, flowers, dye, ferns, dryplants, df_trees, df_farming, df_primordial_items optional_depends = lucky_block, farming, ethereal, moretrees, technic_worldgen, flowers, dye, ferns, dryplants, df_trees, df_farming, df_primordial_items
description = Adds bone and bonemeal giving the ability to quickly grow plants and saplings. description = Adds bone and bonemeal giving the ability to quickly grow plants and saplings.

BIN
screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB