mirror of
https://codeberg.org/tenplus1/bonemeal.git
synced 2025-07-21 01:20:24 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
133
init.lua
133
init.lua
@ -5,9 +5,11 @@ local path = minetest.get_modpath("bonemeal")
|
||||
local min, max, random = math.min, math.max, math.random
|
||||
|
||||
|
||||
-- Load support for intllib.
|
||||
local S = minetest.get_translator and minetest.get_translator("bonemeal") or
|
||||
dofile(path .. "/intllib.lua")
|
||||
-- translation support
|
||||
local S = function(s) return s end -- default boilerplate function
|
||||
if minetest.get_translator ~= nil then
|
||||
S = minetest.get_translator("bonemeal") -- 5.x translation function
|
||||
end
|
||||
|
||||
|
||||
-- creative check
|
||||
@ -129,7 +131,8 @@ local function particle_effect(pos)
|
||||
maxexptime = 1,
|
||||
minsize = 1,
|
||||
maxsize = 3,
|
||||
texture = "bonemeal_particle.png"
|
||||
texture = "bonemeal_particle.png",
|
||||
glow = 5
|
||||
})
|
||||
end
|
||||
|
||||
@ -138,15 +141,18 @@ end
|
||||
local function grow_tree(pos, object)
|
||||
|
||||
if type(object) == "table" and object.axiom then
|
||||
|
||||
-- grow L-system tree
|
||||
minetest.remove_node(pos)
|
||||
minetest.spawn_tree(pos, object)
|
||||
|
||||
elseif type(object) == "string" and minetest.registered_nodes[object] then
|
||||
|
||||
-- place node
|
||||
minetest.set_node(pos, {name = object})
|
||||
|
||||
elseif type(object) == "function" then
|
||||
|
||||
-- function
|
||||
object(pos)
|
||||
end
|
||||
@ -288,15 +294,20 @@ local function check_soil(pos, nodename, strength)
|
||||
for _, n in pairs(dirt) do
|
||||
|
||||
if random(5) == 5 then
|
||||
|
||||
if decor and #decor > 0 then
|
||||
|
||||
-- place random decoration (rare)
|
||||
local dnum = #decor or 1
|
||||
|
||||
nod = decor[random(dnum)] or ""
|
||||
end
|
||||
else
|
||||
if grass and #grass > 0 then
|
||||
|
||||
-- place random grass (common)
|
||||
local dgra = #grass or 1
|
||||
|
||||
nod = #grass > 0 and grass[random(dgra)] or ""
|
||||
end
|
||||
end
|
||||
@ -313,7 +324,9 @@ local function check_soil(pos, nodename, strength)
|
||||
|
||||
-- if param2 not preset then get from existing node
|
||||
if not def then
|
||||
|
||||
local node = minetest.get_node_or_nil(pos2)
|
||||
|
||||
def = node and node.param2 or 0
|
||||
end
|
||||
|
||||
@ -325,6 +338,39 @@ local function check_soil(pos, nodename, strength)
|
||||
end
|
||||
|
||||
|
||||
-- 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
|
||||
|
||||
-- does node have groups set
|
||||
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
|
||||
|
||||
|
||||
-- global functions
|
||||
|
||||
|
||||
@ -425,9 +471,12 @@ function bonemeal:set_deco(list)
|
||||
|
||||
-- replace existing entry
|
||||
if list[l][1] == deco[n][1] then
|
||||
|
||||
deco[n][2] = list[l][2]
|
||||
deco[n][3] = list[l][3]
|
||||
|
||||
list[l] = false
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -459,13 +508,17 @@ function bonemeal:on_use(pos, strength, node)
|
||||
if node.name == "default:papyrus" then
|
||||
|
||||
default.grow_papyrus(pos, node)
|
||||
|
||||
particle_effect(pos)
|
||||
|
||||
return true
|
||||
|
||||
elseif node.name == "default:cactus" then
|
||||
|
||||
default.grow_cactus(pos, node)
|
||||
|
||||
particle_effect(pos)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -473,7 +526,9 @@ function bonemeal:on_use(pos, strength, node)
|
||||
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, "can_bonemeal") > 0 then
|
||||
|
||||
check_soil(pos, node.name, strength)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
@ -509,21 +564,16 @@ minetest.register_craftitem("bonemeal:mulch", {
|
||||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
-- did we point at a node?
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
-- use helper function to do checks and return position and node
|
||||
local node = use_checks(user, pointed_thing)
|
||||
|
||||
-- is area protected?
|
||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
return
|
||||
end
|
||||
if node then
|
||||
|
||||
-- call global on_use function with strength of 1
|
||||
if bonemeal:on_use(pointed_thing.under, 1) then
|
||||
-- call global on_use function with strength of 1
|
||||
local used = bonemeal:on_use(pointed_thing.under, 1, node)
|
||||
|
||||
-- take item if not in creative
|
||||
if not bonemeal.is_creative(user:get_player_name()) then
|
||||
if used and not bonemeal.is_creative(user:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
end
|
||||
@ -540,21 +590,16 @@ minetest.register_craftitem("bonemeal:bonemeal", {
|
||||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
-- did we point at a node?
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
-- use helper function to do checks and return position and node
|
||||
local node = use_checks(user, pointed_thing)
|
||||
|
||||
-- is area protected?
|
||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
return
|
||||
end
|
||||
if node then
|
||||
|
||||
-- call global on_use function with strength of 2
|
||||
if bonemeal:on_use(pointed_thing.under, 2) then
|
||||
-- call global on_use function with strength of 2
|
||||
local used = bonemeal:on_use(pointed_thing.under, 2, node)
|
||||
|
||||
-- take item if not in creative
|
||||
if not bonemeal.is_creative(user:get_player_name()) then
|
||||
if used and not bonemeal.is_creative(user:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
end
|
||||
@ -571,21 +616,16 @@ minetest.register_craftitem("bonemeal:fertiliser", {
|
||||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
-- did we point at a node?
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
-- use helper function to do checks and return position and node
|
||||
local node = use_checks(user, pointed_thing)
|
||||
|
||||
-- is area protected?
|
||||
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||
return
|
||||
end
|
||||
if node then
|
||||
|
||||
-- call global on_use function with strength of 3
|
||||
if bonemeal:on_use(pointed_thing.under, 3) then
|
||||
-- call global on_use function with strength of 3
|
||||
local used = bonemeal:on_use(pointed_thing.under, 3, node)
|
||||
|
||||
-- take item if not in creative
|
||||
if not bonemeal.is_creative(user:get_player_name()) then
|
||||
if used and not bonemeal.is_creative(user:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
end
|
||||
@ -635,10 +675,13 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- bonemeal (from player bones)
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:bonemeal 4",
|
||||
recipe = {{"bones:bones"}}
|
||||
})
|
||||
if minetest.settings:get_bool("bonemeal.disable_deathbones_recipe") ~= true then
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:bonemeal 4",
|
||||
recipe = {{"bones:bones"}}
|
||||
})
|
||||
end
|
||||
|
||||
-- bonemeal (from coral skeleton)
|
||||
minetest.register_craft({
|
||||
@ -693,7 +736,11 @@ end
|
||||
|
||||
-- add support for other mods
|
||||
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")
|
||||
|
Reference in New Issue
Block a user