2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
bonemeal = {}
|
|
|
|
|
2020-01-25 11:02:51 +01:00
|
|
|
local path = minetest.get_modpath("bonemeal")
|
|
|
|
local min, max, random = math.min, math.max, math.random
|
|
|
|
|
|
|
|
|
2022-11-02 15:30:24 +01:00
|
|
|
-- translation support
|
2023-03-10 15:46:38 +01:00
|
|
|
local S = function(s) return s end -- default boilerplate function
|
2022-11-02 15:30:24 +01:00
|
|
|
if minetest.get_translator ~= nil then
|
|
|
|
S = minetest.get_translator("bonemeal") -- 5.x translation function
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- creative check
|
|
|
|
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
2020-08-03 21:27:47 +02:00
|
|
|
function bonemeal.is_creative(name)
|
2019-03-07 17:02:51 +01:00
|
|
|
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- default crops
|
|
|
|
local crops = {
|
|
|
|
{"farming:cotton_", 8, "farming:seed_cotton"},
|
2020-01-25 11:02:51 +01:00
|
|
|
{"farming:wheat_", 8, "farming:seed_wheat"}
|
2019-03-07 17:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- special pine check for nearby snow
|
|
|
|
local function pine_grow(pos)
|
|
|
|
|
|
|
|
if minetest.find_node_near(pos, 1,
|
|
|
|
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) then
|
|
|
|
|
|
|
|
default.grow_new_snowy_pine_tree(pos)
|
|
|
|
else
|
|
|
|
default.grow_new_pine_tree(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-04-01 12:51:55 +02:00
|
|
|
-- special function for cactus growth
|
|
|
|
local function cactus_grow(pos)
|
|
|
|
default.grow_cactus(pos, minetest.get_node(pos))
|
|
|
|
end
|
|
|
|
|
|
|
|
-- special function for papyrus growth
|
|
|
|
local function papyrus_grow(pos)
|
|
|
|
default.grow_papyrus(pos, minetest.get_node(pos))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- default saplings
|
|
|
|
local saplings = {
|
|
|
|
{"default:sapling", default.grow_new_apple_tree, "soil"},
|
|
|
|
{"default:junglesapling", default.grow_new_jungle_tree, "soil"},
|
2019-03-22 18:38:10 +01:00
|
|
|
{"default:emergent_jungle_sapling", default.grow_new_emergent_jungle_tree, "soil"},
|
2019-03-07 17:02:51 +01:00
|
|
|
{"default:acacia_sapling", default.grow_new_acacia_tree, "soil"},
|
|
|
|
{"default:aspen_sapling", default.grow_new_aspen_tree, "soil"},
|
|
|
|
{"default:pine_sapling", pine_grow, "soil"},
|
|
|
|
{"default:bush_sapling", default.grow_bush, "soil"},
|
|
|
|
{"default:acacia_bush_sapling", default.grow_acacia_bush, "soil"},
|
2019-03-22 18:38:10 +01:00
|
|
|
{"default:large_cactus_seedling", default.grow_large_cactus, "sand"},
|
|
|
|
{"default:blueberry_bush_sapling", default.grow_blueberry_bush, "soil"},
|
2021-04-01 12:51:55 +02:00
|
|
|
{"default:pine_bush_sapling", default.grow_pine_bush, "soil"},
|
|
|
|
{"default:cactus", cactus_grow, "sand"},
|
2022-05-08 11:29:10 +02:00
|
|
|
{"default:papyrus", papyrus_grow, "soil"}
|
2019-03-07 17:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- helper tables ( "" denotes a blank item )
|
|
|
|
local green_grass = {
|
|
|
|
"default:grass_2", "default:grass_3", "default:grass_4",
|
|
|
|
"default:grass_5", "", ""
|
|
|
|
}
|
|
|
|
|
|
|
|
local dry_grass = {
|
|
|
|
"default:dry_grass_2", "default:dry_grass_3", "default:dry_grass_4",
|
|
|
|
"default:dry_grass_5", "", ""
|
|
|
|
}
|
|
|
|
|
2021-02-20 16:33:03 +01:00
|
|
|
-- loads mods then add all in-game flowers except waterlily
|
2020-01-25 11:02:51 +01:00
|
|
|
local flowers = {}
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2021-02-20 16:33:03 +01:00
|
|
|
minetest.after(0.1, function()
|
2020-01-25 11:02:51 +01:00
|
|
|
|
2021-02-20 16:33:03 +01:00
|
|
|
for node, def in pairs(minetest.registered_nodes) do
|
|
|
|
|
2021-02-20 16:52:36 +01:00
|
|
|
if def.groups
|
|
|
|
and def.groups.flower
|
|
|
|
and not node:find("waterlily")
|
2022-07-08 10:21:32 +02:00
|
|
|
and not node:find("xdecor:potted_")
|
|
|
|
and not node:find("df_farming:") then
|
2021-02-20 16:33:03 +01:00
|
|
|
flowers[#flowers + 1] = node
|
|
|
|
end
|
2020-01-25 11:02:51 +01:00
|
|
|
end
|
2021-02-20 16:33:03 +01:00
|
|
|
end)
|
2019-03-24 21:37:06 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- default biomes deco
|
|
|
|
local deco = {
|
2022-07-08 10:21:32 +02:00
|
|
|
{"default:dirt", green_grass, flowers},
|
|
|
|
{"default:dirt_with_grass", green_grass, flowers},
|
2021-06-20 09:06:35 +02:00
|
|
|
{"default:dry_dirt", dry_grass, {}},
|
|
|
|
{"default:dry_dirt_with_dry_grass", dry_grass, {}},
|
2019-03-07 17:02:51 +01:00
|
|
|
{"default:dirt_with_dry_grass", dry_grass, flowers},
|
|
|
|
{"default:sand", {}, {"default:dry_shrub", "", "", ""} },
|
|
|
|
{"default:desert_sand", {}, {"default:dry_shrub", "", "", ""} },
|
|
|
|
{"default:silver_sand", {}, {"default:dry_shrub", "", "", ""} },
|
2022-03-19 08:55:03 +01:00
|
|
|
{"default:dirt_with_rainforest_litter", {}, {"default:junglegrass", "", "", ""}}
|
2019-03-07 17:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
--
|
|
|
|
-- local functions
|
|
|
|
--
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- particles
|
|
|
|
local function particle_effect(pos)
|
|
|
|
|
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = 4,
|
|
|
|
time = 0.15,
|
|
|
|
minpos = pos,
|
|
|
|
maxpos = pos,
|
|
|
|
minvel = {x = -1, y = 2, z = -1},
|
|
|
|
maxvel = {x = 1, y = 4, z = 1},
|
|
|
|
minacc = {x = -1, y = -1, z = -1},
|
|
|
|
maxacc = {x = 1, y = 1, z = 1},
|
|
|
|
minexptime = 1,
|
|
|
|
maxexptime = 1,
|
|
|
|
minsize = 1,
|
|
|
|
maxsize = 3,
|
2022-11-02 15:30:24 +01:00
|
|
|
texture = "bonemeal_particle.png",
|
|
|
|
glow = 5
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- tree type check
|
|
|
|
local function grow_tree(pos, object)
|
|
|
|
|
|
|
|
if type(object) == "table" and object.axiom then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- grow L-system tree
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
minetest.spawn_tree(pos, object)
|
|
|
|
|
|
|
|
elseif type(object) == "string" and minetest.registered_nodes[object] then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- place node
|
|
|
|
minetest.set_node(pos, {name = object})
|
|
|
|
|
|
|
|
elseif type(object) == "function" then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- function
|
|
|
|
object(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- sapling check
|
2022-07-01 12:20:06 +02:00
|
|
|
local function check_sapling(pos, sapling_node, light_ok)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- what is sapling placed on?
|
|
|
|
local under = minetest.get_node({
|
|
|
|
x = pos.x,
|
|
|
|
y = pos.y - 1,
|
|
|
|
z = pos.z
|
|
|
|
})
|
|
|
|
|
|
|
|
local can_grow, grow_on
|
|
|
|
|
|
|
|
-- check list for sapling and function
|
|
|
|
for n = 1, #saplings do
|
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
if saplings[n][1] == sapling_node then
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
grow_on = saplings[n][3] or ""
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
-- backwards compatibility, add 'group:' to older grouping
|
|
|
|
if grow_on == "soil" or grow_on == "sand" then
|
|
|
|
grow_on = "group:" .. grow_on
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
-- sapling grows on top of specific node group
|
|
|
|
if grow_on:find("group:") then
|
|
|
|
|
|
|
|
local group = grow_on:split(":")[2]
|
|
|
|
|
|
|
|
if minetest.get_item_group(under.name, group) > 0 then
|
|
|
|
can_grow = true
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
-- sapling grows on specific node
|
|
|
|
elseif grow_on == under.name then
|
2019-03-07 17:02:51 +01:00
|
|
|
can_grow = true
|
|
|
|
end
|
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
-- check if we can grow sapling at current light level
|
|
|
|
if can_grow and (light_ok or saplings[n][4] == true) then
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
particle_effect(pos)
|
2022-07-01 12:20:06 +02:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
grow_tree(pos, saplings[n][2])
|
2022-07-01 12:20:06 +02:00
|
|
|
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- crops check
|
2022-07-01 12:20:06 +02:00
|
|
|
local function check_crops(pos, nodename, strength, light_ok)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
local mod, crop, stage, nod, def
|
|
|
|
|
|
|
|
-- grow registered crops
|
|
|
|
for n = 1, #crops do
|
|
|
|
|
2022-07-01 12:20:06 +02:00
|
|
|
-- check if crop can grow in current light level
|
|
|
|
if (light_ok or crops[n][4] == true)
|
|
|
|
and (nodename:find(crops[n][1])
|
|
|
|
or nodename == crops[n][3]) then
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- separate mod and node name
|
|
|
|
mod = nodename:split(":")[1] .. ":"
|
|
|
|
crop = nodename:split(":")[2]
|
|
|
|
|
|
|
|
-- get stage number or set to 0 for seed
|
2022-06-30 13:48:18 +02:00
|
|
|
if crop:split("_")[3] then
|
|
|
|
stage = crop:split("_")[3]
|
|
|
|
else
|
|
|
|
stage = crop:split("_")[2]
|
|
|
|
end
|
|
|
|
|
|
|
|
stage = tonumber(stage) or 0
|
|
|
|
|
2020-01-25 11:02:51 +01:00
|
|
|
stage = min(stage + strength, crops[n][2])
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- check for place_param setting
|
|
|
|
nod = crops[n][1] .. stage
|
|
|
|
def = minetest.registered_nodes[nod]
|
2022-06-30 13:48:18 +02:00
|
|
|
|
|
|
|
-- make sure crop exists or isn't fully grown already
|
|
|
|
if not def or nod == nodename then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
def = def and def.place_param2 or 0
|
|
|
|
|
|
|
|
minetest.set_node(pos, {name = nod, param2 = def})
|
|
|
|
|
|
|
|
particle_effect(pos)
|
|
|
|
|
2022-06-30 14:00:50 +02:00
|
|
|
minetest.get_node_timer(pos):start(10) -- restart any timers
|
|
|
|
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- check soil for specific decoration placement
|
|
|
|
local function check_soil(pos, nodename, strength)
|
|
|
|
|
|
|
|
-- set radius according to strength
|
|
|
|
local side = strength - 1
|
2020-01-25 11:02:51 +01:00
|
|
|
local tall = max(strength - 2, 0)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- get area of land with free space above
|
|
|
|
local dirt = minetest.find_nodes_in_area_under_air(
|
|
|
|
{x = pos.x - side, y = pos.y - tall, z = pos.z - side},
|
2022-07-08 10:21:32 +02:00
|
|
|
{x = pos.x + side, y = pos.y + tall, z = pos.z + side}, {nodename})
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- set default grass and decoration
|
2022-07-08 10:21:32 +02:00
|
|
|
local grass, decor
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- choose grass and decoration to use on dirt patch
|
|
|
|
for n = 1, #deco do
|
|
|
|
|
|
|
|
-- do we have a grass match?
|
|
|
|
if nodename == deco[n][1] then
|
2022-07-08 10:21:32 +02:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
grass = deco[n][2] or {}
|
|
|
|
decor = deco[n][3] or {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local pos2, nod, def
|
|
|
|
|
|
|
|
-- loop through soil
|
2020-02-14 12:13:49 +01:00
|
|
|
for _, n in pairs(dirt) do
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2020-01-25 11:02:51 +01:00
|
|
|
if random(5) == 5 then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-11-26 13:34:53 +01:00
|
|
|
if decor and #decor > 0 then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-11-26 13:34:53 +01:00
|
|
|
-- place random decoration (rare)
|
|
|
|
local dnum = #decor or 1
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-01-25 11:02:51 +01:00
|
|
|
nod = decor[random(dnum)] or ""
|
2019-11-26 13:34:53 +01:00
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
else
|
2019-11-26 13:34:53 +01:00
|
|
|
if grass and #grass > 0 then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-11-26 13:34:53 +01:00
|
|
|
-- place random grass (common)
|
|
|
|
local dgra = #grass or 1
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-01-25 11:02:51 +01:00
|
|
|
nod = #grass > 0 and grass[random(dgra)] or ""
|
2019-11-26 13:34:53 +01:00
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
pos2 = n
|
|
|
|
|
|
|
|
pos2.y = pos2.y + 1
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
if nod and nod ~= "" then
|
2020-02-14 19:21:56 +01:00
|
|
|
|
|
|
|
-- get crop param2 value
|
2019-03-07 17:02:51 +01:00
|
|
|
def = minetest.registered_nodes[nod]
|
2020-02-14 19:21:56 +01:00
|
|
|
def = def and def.place_param2
|
|
|
|
|
|
|
|
-- if param2 not preset then get from existing node
|
|
|
|
if not def then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-02-14 19:21:56 +01:00
|
|
|
local node = minetest.get_node_or_nil(pos2)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-02-14 19:21:56 +01:00
|
|
|
def = node and node.param2 or 0
|
|
|
|
end
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
minetest.set_node(pos2, {name = nod, param2 = def})
|
|
|
|
end
|
|
|
|
|
|
|
|
particle_effect(pos2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2022-11-03 09:53:52 +01:00
|
|
|
-- helper function
|
|
|
|
local function use_checks(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
|
|
|
|
|
2023-05-11 08:11:23 +02:00
|
|
|
-- does node have groups set
|
2022-11-03 09:53:52 +01:00
|
|
|
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 node
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- global functions
|
|
|
|
|
|
|
|
|
|
|
|
-- add to sapling list
|
2022-07-01 12:20:06 +02:00
|
|
|
-- {sapling node, schematic or function name, "soil"|"sand"|specific_node|"group:"}
|
2019-03-07 17:02:51 +01:00
|
|
|
--e.g. {"default:sapling", default.grow_new_apple_tree, "soil"}
|
|
|
|
|
|
|
|
function bonemeal:add_sapling(list)
|
|
|
|
|
|
|
|
for n = 1, #list do
|
2020-02-14 12:13:49 +01:00
|
|
|
saplings[#saplings + 1] = list[n]
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- add to crop list to force grow
|
|
|
|
-- {crop name start_, growth steps, seed node (if required)}
|
|
|
|
-- e.g. {"farming:wheat_", 8, "farming:seed_wheat"}
|
|
|
|
function bonemeal:add_crop(list)
|
|
|
|
|
|
|
|
for n = 1, #list do
|
2020-02-14 12:13:49 +01:00
|
|
|
crops[#crops + 1] = list[n]
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- add grass and flower/plant decoration for specific dirt types
|
|
|
|
-- {dirt_node, {grass_nodes}, {flower_nodes}
|
|
|
|
-- e.g. {"default:dirt_with_dry_grass", dry_grass, flowers}
|
|
|
|
-- if an entry already exists for a given dirt type, it will add new entries and all empty
|
|
|
|
-- entries, allowing to both add decorations and decrease their frequency.
|
|
|
|
function bonemeal:add_deco(list)
|
|
|
|
|
|
|
|
for l = 1, #list do
|
|
|
|
|
|
|
|
for n = 1, #deco do
|
|
|
|
|
|
|
|
-- update existing entry
|
|
|
|
if list[l][1] == deco[n][1] then
|
|
|
|
|
|
|
|
-- adding grass types
|
2020-02-14 12:13:49 +01:00
|
|
|
for _, extra in pairs(list[l][2]) do
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
if extra ~= "" then
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
for _, entry in pairs(deco[n][2]) do
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
if extra == entry then
|
|
|
|
extra = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if extra then
|
2020-02-14 12:13:49 +01:00
|
|
|
deco[n][2][#deco[n][2] + 1] = extra
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- adding decoration types
|
2020-02-14 12:13:49 +01:00
|
|
|
for _, extra in ipairs(list[l][3]) do
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
if extra ~= "" then
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
for __, entry in pairs(deco[n][3]) do
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
if extra == entry then
|
|
|
|
extra = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if extra then
|
2020-02-14 12:13:49 +01:00
|
|
|
deco[n][3][#deco[n][3] + 1] = extra
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
list[l] = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if list[l] then
|
2020-02-14 12:13:49 +01:00
|
|
|
deco[#deco + 1] = list[l]
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- definitively set a decration scheme
|
|
|
|
-- this function will either add a new entry as is, or replace the existing one
|
|
|
|
function bonemeal:set_deco(list)
|
|
|
|
|
|
|
|
for l = 1, #list do
|
|
|
|
|
|
|
|
for n = 1, #deco do
|
|
|
|
|
|
|
|
-- replace existing entry
|
|
|
|
if list[l][1] == deco[n][1] then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
deco[n][2] = list[l][2]
|
|
|
|
deco[n][3] = list[l][3]
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
list[l] = false
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if list[l] then
|
2020-02-14 12:13:49 +01:00
|
|
|
deco[#deco + 1] = list[l]
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- global on_use function for bonemeal
|
|
|
|
function bonemeal:on_use(pos, strength, node)
|
|
|
|
|
|
|
|
-- get node pointed at
|
|
|
|
local node = node or minetest.get_node(pos)
|
|
|
|
|
|
|
|
-- return if nothing there
|
|
|
|
if node.name == "ignore" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make sure strength is between 1 and 4
|
|
|
|
strength = strength or 1
|
2020-01-25 11:02:51 +01:00
|
|
|
strength = max(strength, 1)
|
|
|
|
strength = min(strength, 4)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- papyrus and cactus
|
|
|
|
if node.name == "default:papyrus" then
|
|
|
|
|
|
|
|
default.grow_papyrus(pos, node)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
particle_effect(pos)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
elseif node.name == "default:cactus" then
|
|
|
|
|
|
|
|
default.grow_cactus(pos, node)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
particle_effect(pos)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- grow grass and flowers
|
|
|
|
if minetest.get_item_group(node.name, "soil") > 0
|
2019-03-07 17:38:42 +01:00
|
|
|
or minetest.get_item_group(node.name, "sand") > 0
|
|
|
|
or minetest.get_item_group(node.name, "can_bonemeal") > 0 then
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
check_soil(pos, node.name, strength)
|
2022-11-02 15:30:24 +01:00
|
|
|
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- light check depending on strength (strength of 4 = no light needed)
|
2022-07-01 12:20:06 +02:00
|
|
|
local light_ok = true
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
if (minetest.get_node_light(pos) or 0) < (12 - (strength * 3)) then
|
2022-07-01 12:20:06 +02:00
|
|
|
light_ok = nil
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
2022-07-01 15:36:36 +02:00
|
|
|
-- check for sapling growth
|
|
|
|
if random(5 - strength) == 1
|
|
|
|
and check_sapling(pos, node.name, light_ok) then
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- check for crop growth
|
2022-07-01 12:20:06 +02:00
|
|
|
if check_crops(pos, node.name, strength, light_ok) then
|
2020-12-13 19:17:11 +01:00
|
|
|
return true
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
--
|
|
|
|
-- items
|
|
|
|
--
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- mulch (strength 1)
|
|
|
|
minetest.register_craftitem("bonemeal:mulch", {
|
|
|
|
description = S("Mulch"),
|
|
|
|
inventory_image = "bonemeal_mulch.png",
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
2022-11-02 15:30:24 +01:00
|
|
|
-- use helper function to do checks and return position and node
|
2022-11-03 09:53:52 +01:00
|
|
|
local node = use_checks(user, pointed_thing)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
if node then
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
-- call global on_use function with strength of 1
|
2023-05-11 08:11:23 +02:00
|
|
|
local used = bonemeal:on_use(pointed_thing.under, 1, node)
|
2020-12-13 19:17:11 +01:00
|
|
|
|
|
|
|
-- take item if not in creative
|
2023-05-11 08:11:23 +02:00
|
|
|
if used and not bonemeal.is_creative(user:get_player_name()) then
|
2020-12-13 19:17:11 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
return itemstack
|
2020-01-25 11:02:51 +01:00
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- bonemeal (strength 2)
|
|
|
|
minetest.register_craftitem("bonemeal:bonemeal", {
|
|
|
|
description = S("Bone Meal"),
|
|
|
|
inventory_image = "bonemeal_item.png",
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
2022-11-02 15:30:24 +01:00
|
|
|
-- use helper function to do checks and return position and node
|
2022-11-03 09:53:52 +01:00
|
|
|
local node = use_checks(user, pointed_thing)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
if node then
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
-- call global on_use function with strength of 2
|
2023-05-11 08:11:23 +02:00
|
|
|
local used = bonemeal:on_use(pointed_thing.under, 2, node)
|
2020-12-13 19:17:11 +01:00
|
|
|
|
|
|
|
-- take item if not in creative
|
2023-05-11 08:11:23 +02:00
|
|
|
if used and not bonemeal.is_creative(user:get_player_name()) then
|
2020-12-13 19:17:11 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
return itemstack
|
2020-01-25 11:02:51 +01:00
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- fertiliser (strength 3)
|
|
|
|
minetest.register_craftitem("bonemeal:fertiliser", {
|
|
|
|
description = S("Fertiliser"),
|
|
|
|
inventory_image = "bonemeal_fertiliser.png",
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
2022-11-02 15:30:24 +01:00
|
|
|
-- use helper function to do checks and return position and node
|
2022-11-03 09:53:52 +01:00
|
|
|
local node = use_checks(user, pointed_thing)
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
if node then
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-11-30 16:24:50 +01:00
|
|
|
-- call global on_use function with strength of 3
|
2023-05-11 08:11:23 +02:00
|
|
|
local used = bonemeal:on_use(pointed_thing.under, 3, node)
|
2020-12-13 19:17:11 +01:00
|
|
|
|
|
|
|
-- take item if not in creative
|
2023-05-11 08:11:23 +02:00
|
|
|
if used and not bonemeal.is_creative(user:get_player_name()) then
|
2020-12-13 19:17:11 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
return itemstack
|
2020-01-25 11:02:51 +01:00
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- bone
|
|
|
|
minetest.register_craftitem("bonemeal:bone", {
|
|
|
|
description = S("Bone"),
|
|
|
|
inventory_image = "bonemeal_bone.png",
|
2020-05-03 21:48:12 +02:00
|
|
|
groups = {bone = 1}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- gelatin powder
|
|
|
|
minetest.register_craftitem("bonemeal:gelatin_powder", {
|
|
|
|
description = S("Gelatin Powder"),
|
|
|
|
inventory_image = "bonemeal_gelatin_powder.png",
|
2020-01-25 11:02:51 +01:00
|
|
|
groups = {food_gelatin = 1, flammable = 2}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-02-14 12:13:49 +01:00
|
|
|
--
|
|
|
|
-- crafting recipes
|
|
|
|
--
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- gelatin powder
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "bonemeal:gelatin_powder 4",
|
|
|
|
recipe = {
|
2020-05-03 21:48:12 +02:00
|
|
|
{"group:bone", "group:bone", "group:bone"},
|
2019-03-07 17:02:51 +01:00
|
|
|
{"bucket:bucket_water", "bucket:bucket_water", "bucket:bucket_water"},
|
2022-07-01 12:20:06 +02:00
|
|
|
{"bucket:bucket_water", "default:torch", "bucket:bucket_water"}
|
2019-03-07 17:02:51 +01:00
|
|
|
},
|
|
|
|
replacements = {
|
2022-07-01 12:20:06 +02:00
|
|
|
{"bucket:bucket_water", "bucket:bucket_empty 5"}
|
2020-01-25 11:02:51 +01:00
|
|
|
}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- bonemeal (from bone)
|
|
|
|
minetest.register_craft({
|
2023-06-10 09:01:13 +02:00
|
|
|
type = "cooking",
|
2019-03-07 17:02:51 +01:00
|
|
|
output = "bonemeal:bonemeal 2",
|
2023-06-10 09:01:13 +02:00
|
|
|
recipe = "group:bone",
|
|
|
|
cooktime = 4
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- bonemeal (from player bones)
|
2023-01-11 19:55:21 +01:00
|
|
|
if minetest.settings:get_bool("bonemeal.disable_deathbones_recipe") ~= true then
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2023-06-10 09:01:13 +02:00
|
|
|
output = "bonemeal:bone 2",
|
2023-01-11 19:55:21 +01:00
|
|
|
recipe = {{"bones:bones"}}
|
|
|
|
})
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- bonemeal (from coral skeleton)
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "bonemeal:bonemeal 2",
|
2021-04-13 22:00:25 +02:00
|
|
|
recipe = {{"default:coral_skeleton"}}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- mulch
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "bonemeal:mulch 4",
|
|
|
|
recipe = {
|
2021-04-13 22:00:25 +02:00
|
|
|
{"group:tree", "group:leaves", "group:leaves"},
|
|
|
|
{"group:leaves", "group:leaves", "group:leaves"},
|
|
|
|
{"group:leaves", "group:leaves", "group:leaves"}
|
2020-01-25 11:02:51 +01:00
|
|
|
}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
2020-11-10 19:00:11 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "bonemeal:mulch",
|
|
|
|
recipe = {
|
2021-04-13 22:00:25 +02:00
|
|
|
{"group:seed", "group:seed", "group:seed"},
|
|
|
|
{"group:seed", "group:seed", "group:seed"},
|
|
|
|
{"group:seed", "group:seed", "group:seed"}
|
2020-11-10 19:00:11 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-03-07 17:02:51 +01:00
|
|
|
-- fertiliser
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "bonemeal:fertiliser 2",
|
2021-04-13 22:00:25 +02:00
|
|
|
recipe = {{"bonemeal:bonemeal", "bonemeal:mulch"}}
|
2019-03-07 17:02:51 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
-- add bones to dirt
|
2020-01-04 16:55:07 +01:00
|
|
|
local drop = minetest.registered_items["default:dirt"].drop
|
|
|
|
if drop then
|
|
|
|
table.insert(drop.items, 1, {items = {"bonemeal:bone"}, rarity = 30})
|
|
|
|
else
|
2019-03-07 17:02:51 +01:00
|
|
|
drop = {
|
|
|
|
max_items = 1,
|
|
|
|
items = {
|
|
|
|
{
|
|
|
|
items = {"bonemeal:bone"},
|
2020-05-20 13:58:34 +02:00
|
|
|
rarity = 40
|
2019-03-07 17:02:51 +01:00
|
|
|
},
|
|
|
|
{
|
2020-01-25 11:02:51 +01:00
|
|
|
items = {"default:dirt"}
|
2019-03-07 17:02:51 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-04 16:55:07 +01:00
|
|
|
}
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
|
|
|
-- add support for other mods
|
|
|
|
dofile(path .. "/mods.lua")
|
2022-11-02 15:30:24 +01:00
|
|
|
|
|
|
|
-- lucky block support
|
|
|
|
if minetest.get_modpath("lucky_block") then
|
|
|
|
dofile(path .. "/lucky_block.lua")
|
|
|
|
end
|
2019-03-07 17:02:51 +01:00
|
|
|
|
2022-05-08 11:29:10 +02:00
|
|
|
|
2023-01-11 19:55:21 +01:00
|
|
|
print ("[MOD] Bonemeal loaded")
|