2022-05-01 12:33:19 +02:00
|
|
|
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,
|
2024-03-22 06:39:45 +01:00
|
|
|
texture = "mcl_particles_bonemeal.png^[colorize:#00EE00:125",
|
2022-05-01 12:33:19 +02:00
|
|
|
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 = {}
|
|
|
|
|
2022-05-04 12:17:51 +02:00
|
|
|
-- Shims for the old API are still available in mcl_dye and defer to
|
2022-05-01 12:33:19 +02:00
|
|
|
-- 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!")
|
2024-03-21 19:30:34 +01:00
|
|
|
local lines = string.split(debug.traceback(),"\n")
|
|
|
|
for _,line in ipairs(lines) do
|
|
|
|
minetest.log("warning",line)
|
|
|
|
end
|
2022-05-01 12:33:19 +02:00
|
|
|
table.insert(mcl_bone_meal.bone_meal_callbacks, func)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Legacy registered users of the old API are handled through this function.
|
|
|
|
--
|
2024-03-20 08:42:29 +01:00
|
|
|
local function legacy_apply_bone_meal(pointed_thing, placer)
|
|
|
|
-- Legacy API support
|
2022-05-01 12:33:19 +02:00
|
|
|
for _, func in pairs(mcl_bone_meal.bone_meal_callbacks) do
|
|
|
|
if func(pointed_thing, placer) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
-- End legacy bone meal API
|
|
|
|
|
2024-03-20 08:42:29 +01:00
|
|
|
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
|
2024-03-21 19:11:36 +01:00
|
|
|
local consume
|
2024-03-20 08:42:29 +01:00
|
|
|
|
|
|
|
-- If the pointed node can be bonemealed, let it handle the processing.
|
2024-03-23 17:44:41 +01:00
|
|
|
if ndef and ndef._on_bone_meal then
|
|
|
|
success = ndef._on_bone_meal(itemstack, placer, pointed_thing)
|
2024-03-21 19:11:36 +01:00
|
|
|
consume = true
|
2024-03-20 08:42:29 +01:00
|
|
|
else
|
|
|
|
-- Otherwise try the legacy API.
|
|
|
|
success = legacy_apply_bone_meal(pointed_thing, placer)
|
2024-03-21 19:11:36 +01:00
|
|
|
consume = success
|
2024-03-20 08:42:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Particle effects
|
|
|
|
if success then
|
|
|
|
mcl_bone_meal.add_bone_meal_particle(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Take the item
|
2024-03-21 19:11:36 +01:00
|
|
|
if consume and ( not placer or not minetest.is_creative_enabled(placer:get_player_name()) ) then
|
2024-03-20 08:42:29 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2022-05-01 12:33:19 +02:00
|
|
|
minetest.register_craftitem("mcl_bone_meal:bone_meal", {
|
|
|
|
description = S("Bone Meal"),
|
|
|
|
_tt_help = S("Speeds up plant growth"),
|
|
|
|
_doc_items_longdesc = longdesc,
|
|
|
|
_doc_items_usagehelp = usagehelp,
|
2022-05-05 13:58:12 +02:00
|
|
|
inventory_image = "mcl_bone_meal.png",
|
|
|
|
groups = {craftitem=1},
|
2022-05-01 12:33:19 +02:00
|
|
|
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]
|
2024-03-20 08:42:29 +01:00
|
|
|
|
2022-05-01 12:33:19 +02:00
|
|
|
-- 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
|
2024-03-20 08:42:29 +01:00
|
|
|
|
|
|
|
return mcl_bone_meal.use_bone_meal(itemstack, placer, pointed_thing)
|
2022-05-01 12:33:19 +02:00
|
|
|
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
|
2024-03-20 08:42:29 +01:00
|
|
|
|
|
|
|
return mcl_bone_meal.use_bone_meal(itemstack, nil, pointed_thing)
|
2022-05-01 12:33:19 +02:00
|
|
|
end,
|
|
|
|
_dispense_into_walkable = true
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "mcl_bone_meal:bone_meal 3",
|
|
|
|
recipe = {{"mcl_mobitems:bone"}},
|
|
|
|
})
|