mirror of
https://codeberg.org/tenplus1/bonemeal.git
synced 2025-05-06 19:20:31 +02:00
tidy and tweak code
This commit is contained in:
parent
c2d76b779d
commit
81f36673d3
139
init.lua
139
init.lua
@ -1,47 +1,42 @@
|
||||
|
||||
-- MineClonia / VoxeLibre check
|
||||
|
||||
local mcl = minetest.get_modpath("mcl_core")
|
||||
|
||||
-- global
|
||||
|
||||
bonemeal = {
|
||||
item_list = {
|
||||
bucket_water = "bucket:bucket_water",
|
||||
bucket_empty = "bucket:bucket_empty",
|
||||
dirt = "default:dirt",
|
||||
torch = "default:torch",
|
||||
coral = "default:coral_skeleton"
|
||||
bucket_water = mcl and "mcl_buckets:bucket_water" or "bucket:bucket_water",
|
||||
bucket_empty = mcl and "mcl_buckets:bucker_empty" or "bucket:bucket_empty",
|
||||
dirt = mcl and "mcl_core:dirt" or "default:dirt",
|
||||
torch = mcl and "mcl_torches:torch" or "default:torch",
|
||||
coral = mcl and "mcl_ocean:dead_horn_coral_block" or "default:coral_skeleton"
|
||||
}
|
||||
}
|
||||
|
||||
-- translation support and vars
|
||||
|
||||
local S = minetest.get_translator("bonemeal")
|
||||
local a = bonemeal.item_list
|
||||
|
||||
if minetest.get_modpath("mcl_core") then
|
||||
|
||||
a.bucket_water = "mcl_buckets:bucket_water"
|
||||
a.bucket_empty = "mcl_buckets:bucker_empty"
|
||||
a.dirt = "mcl_core:dirt"
|
||||
a.torch = "mcl_torches:torch"
|
||||
a.coral = "mcl_ocean:dead_horn_coral_block"
|
||||
end
|
||||
|
||||
|
||||
local path = minetest.get_modpath("bonemeal")
|
||||
local min, max, random = math.min, math.max, math.random
|
||||
|
||||
-- translation support
|
||||
local S = minetest.get_translator("bonemeal")
|
||||
-- creative check helper
|
||||
|
||||
-- creative check
|
||||
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||
function bonemeal.is_creative(name)
|
||||
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
|
||||
end
|
||||
|
||||
-- API tables
|
||||
|
||||
local crops = {}
|
||||
local saplings = {}
|
||||
local deco = {}
|
||||
|
||||
--
|
||||
-- local functions
|
||||
--
|
||||
-- particle effect
|
||||
|
||||
-- particles
|
||||
local function particle_effect(pos)
|
||||
|
||||
minetest.add_particlespawner({
|
||||
@ -62,38 +57,31 @@ local function particle_effect(pos)
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
-- tree type check
|
||||
|
||||
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)
|
||||
minetest.spawn_tree(pos, object) -- grow L-system tree
|
||||
|
||||
elseif type(object) == "string" and minetest.registered_nodes[object] then
|
||||
|
||||
-- place node
|
||||
minetest.set_node(pos, {name = object})
|
||||
minetest.set_node(pos, {name = object}) -- place node
|
||||
|
||||
elseif type(object) == "function" then
|
||||
|
||||
-- function
|
||||
object(pos)
|
||||
object(pos) -- execute function
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- sapling check
|
||||
|
||||
local function check_sapling(pos, sapling_node, strength, light_ok)
|
||||
|
||||
-- what is sapling placed on?
|
||||
local under = minetest.get_node({
|
||||
x = pos.x,
|
||||
y = pos.y - 1,
|
||||
z = pos.z
|
||||
})
|
||||
local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
|
||||
local can_grow, grow_on
|
||||
|
||||
@ -138,8 +126,8 @@ local function check_sapling(pos, sapling_node, strength, light_ok)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- crops check
|
||||
|
||||
local function check_crops(pos, nodename, strength, light_ok)
|
||||
|
||||
local mod, crop, stage, nod, def
|
||||
@ -189,8 +177,8 @@ local function check_crops(pos, nodename, strength, light_ok)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- check soil for specific decoration placement
|
||||
|
||||
local function check_soil(pos, nodename, strength)
|
||||
|
||||
-- set radius according to strength
|
||||
@ -265,14 +253,12 @@ local function check_soil(pos, nodename, strength)
|
||||
end
|
||||
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
|
||||
if pointed_thing.type ~= "node" then return false end
|
||||
|
||||
-- get position and node info
|
||||
local pos = pointed_thing.under
|
||||
@ -281,9 +267,7 @@ local function use_checks(user, pointed_thing)
|
||||
local dirt = def and def.groups
|
||||
|
||||
-- does node have groups set
|
||||
if not dirt then
|
||||
return false
|
||||
end
|
||||
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
|
||||
@ -298,9 +282,7 @@ local function use_checks(user, pointed_thing)
|
||||
return node
|
||||
end
|
||||
|
||||
|
||||
-- global functions
|
||||
|
||||
--= Global functions
|
||||
|
||||
-- add to sapling list
|
||||
-- {sapling node, schematic or function name, "soil"|"sand"|specific_node|"group:"}
|
||||
@ -313,10 +295,10 @@ function bonemeal:add_sapling(list)
|
||||
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
|
||||
@ -324,12 +306,12 @@ function bonemeal:add_crop(list)
|
||||
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
|
||||
@ -347,8 +329,7 @@ function bonemeal:add_deco(list)
|
||||
for _, entry in pairs(deco[n][2]) do
|
||||
|
||||
if extra == entry then
|
||||
extra = false
|
||||
break
|
||||
extra = false ; break
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -366,8 +347,7 @@ function bonemeal:add_deco(list)
|
||||
for __, entry in pairs(deco[n][3]) do
|
||||
|
||||
if extra == entry then
|
||||
extra = false
|
||||
break
|
||||
extra = false ; break
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -377,8 +357,7 @@ function bonemeal:add_deco(list)
|
||||
end
|
||||
end
|
||||
|
||||
list[l] = false
|
||||
break
|
||||
list[l] = false ; break
|
||||
end
|
||||
end
|
||||
|
||||
@ -388,9 +367,9 @@ function bonemeal:add_deco(list)
|
||||
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
|
||||
@ -415,17 +394,15 @@ function bonemeal:set_deco(list)
|
||||
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
|
||||
if node.name == "ignore" then return end
|
||||
|
||||
-- make sure strength is between 1 and 4
|
||||
strength = strength or 1
|
||||
@ -437,25 +414,19 @@ function bonemeal:on_use(pos, strength, node)
|
||||
|
||||
default.grow_papyrus(pos, node)
|
||||
|
||||
particle_effect(pos)
|
||||
|
||||
return true
|
||||
particle_effect(pos) ; return true
|
||||
|
||||
elseif node.name == "default:cactus" then
|
||||
|
||||
default.grow_cactus(pos, node)
|
||||
|
||||
particle_effect(pos)
|
||||
|
||||
return true
|
||||
particle_effect(pos) ; return true
|
||||
|
||||
elseif node.name == "default:dry_dirt" and strength == 1 then
|
||||
|
||||
minetest.set_node(pos, {name = "default:dry_dirt_with_dry_grass"})
|
||||
|
||||
particle_effect(pos)
|
||||
|
||||
return true
|
||||
particle_effect(pos) ; return true
|
||||
end
|
||||
|
||||
-- grow grass and flowers
|
||||
@ -486,13 +457,10 @@ function bonemeal:on_use(pos, strength, node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- items
|
||||
--
|
||||
|
||||
--= Items
|
||||
|
||||
-- mulch (strength 1)
|
||||
|
||||
minetest.register_craftitem("bonemeal:mulch", {
|
||||
description = S("Mulch"),
|
||||
inventory_image = "bonemeal_mulch.png",
|
||||
@ -517,8 +485,8 @@ minetest.register_craftitem("bonemeal:mulch", {
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- bonemeal (strength 2)
|
||||
|
||||
minetest.register_craftitem("bonemeal:bonemeal", {
|
||||
description = S("Bone Meal"),
|
||||
inventory_image = "bonemeal_item.png",
|
||||
@ -543,8 +511,8 @@ minetest.register_craftitem("bonemeal:bonemeal", {
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- fertiliser (strength 3)
|
||||
|
||||
minetest.register_craftitem("bonemeal:fertiliser", {
|
||||
description = S("Fertiliser"),
|
||||
inventory_image = "bonemeal_fertiliser.png",
|
||||
@ -569,8 +537,8 @@ minetest.register_craftitem("bonemeal:fertiliser", {
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- bone
|
||||
|
||||
minetest.register_craftitem("bonemeal:bone", {
|
||||
description = S("Bone"),
|
||||
inventory_image = "bonemeal_bone.png",
|
||||
@ -578,18 +546,17 @@ minetest.register_craftitem("bonemeal:bone", {
|
||||
})
|
||||
|
||||
-- gelatin powder
|
||||
|
||||
minetest.register_craftitem("bonemeal:gelatin_powder", {
|
||||
description = S("Gelatin Powder"),
|
||||
inventory_image = "bonemeal_gelatin_powder.png",
|
||||
groups = {food_gelatin = 1, flammable = 2}
|
||||
})
|
||||
|
||||
|
||||
--
|
||||
-- crafting recipes
|
||||
--
|
||||
--= Recipes
|
||||
|
||||
-- gelatin powder
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:gelatin_powder 4",
|
||||
recipe = {
|
||||
@ -603,6 +570,7 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- bonemeal (from bone)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "bonemeal:bonemeal 2",
|
||||
@ -611,6 +579,7 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- bonemeal (from player bones)
|
||||
|
||||
if minetest.settings:get_bool("bonemeal.disable_deathbones_recipe") ~= true then
|
||||
|
||||
minetest.register_craft({
|
||||
@ -620,12 +589,14 @@ if minetest.settings:get_bool("bonemeal.disable_deathbones_recipe") ~= true then
|
||||
end
|
||||
|
||||
-- bonemeal (from coral skeleton)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:bonemeal 2",
|
||||
recipe = {{a.coral}}
|
||||
})
|
||||
|
||||
-- mulch
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:mulch 4",
|
||||
recipe = {
|
||||
@ -645,12 +616,14 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- fertiliser
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bonemeal:fertiliser 2",
|
||||
recipe = {{"bonemeal:bonemeal", "bonemeal:mulch"}}
|
||||
})
|
||||
|
||||
-- add bones to dirt
|
||||
|
||||
if minetest.registered_items[a.dirt] then
|
||||
|
||||
minetest.override_item(a.dirt, {
|
||||
@ -670,9 +643,11 @@ if minetest.registered_items[a.dirt] then
|
||||
end
|
||||
|
||||
-- add support for mods
|
||||
|
||||
dofile(path .. "/mods.lua")
|
||||
|
||||
-- lucky block support
|
||||
|
||||
if minetest.get_modpath("lucky_block") then
|
||||
dofile(path .. "/lucky_block.lua")
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
-- add lucky blocks
|
||||
-- helper function
|
||||
|
||||
local function growy(pos, player)
|
||||
|
||||
@ -10,6 +10,7 @@ local function growy(pos, player)
|
||||
end
|
||||
end
|
||||
|
||||
-- add lucky blocks
|
||||
|
||||
lucky_block:add_blocks({
|
||||
{"lig"},
|
||||
|
43
mods.lua
43
mods.lua
@ -1,5 +1,6 @@
|
||||
|
||||
-- craft bones from animalmaterials into bonemeal
|
||||
|
||||
if minetest.get_modpath("animalmaterials") then
|
||||
|
||||
minetest.register_craft({
|
||||
@ -8,6 +9,7 @@ if minetest.get_modpath("animalmaterials") then
|
||||
})
|
||||
end
|
||||
|
||||
-- default additions
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
|
||||
@ -62,6 +64,7 @@ if minetest.get_modpath("default") then
|
||||
|
||||
local flowers = {}
|
||||
|
||||
-- add flowers from other mods
|
||||
minetest.after(0.1, function()
|
||||
|
||||
for node, def in pairs(minetest.registered_nodes) do
|
||||
@ -92,6 +95,7 @@ if minetest.get_modpath("default") then
|
||||
})
|
||||
end
|
||||
|
||||
-- default farming crops
|
||||
|
||||
if farming then
|
||||
|
||||
@ -101,6 +105,7 @@ if farming then
|
||||
})
|
||||
end
|
||||
|
||||
-- farming redo crops
|
||||
|
||||
if farming and farming.mod and farming.mod == "redo" then
|
||||
|
||||
@ -148,6 +153,7 @@ if farming and farming.mod and farming.mod == "redo" then
|
||||
})
|
||||
end
|
||||
|
||||
-- ethereal crops, saplings and grass
|
||||
|
||||
if minetest.get_modpath("ethereal") then
|
||||
|
||||
@ -195,6 +201,7 @@ if minetest.get_modpath("ethereal") then
|
||||
})
|
||||
end
|
||||
|
||||
-- moretrees saplings
|
||||
|
||||
if minetest.get_modpath("moretrees") then
|
||||
|
||||
@ -228,14 +235,18 @@ if minetest.get_modpath("moretrees") then
|
||||
{"moretrees:rubber_tree_sapling", moretrees.spawn_rubber_tree_object, "soil"},
|
||||
{"moretrees:fir_sapling", fir_grow, "soil"}
|
||||
})
|
||||
end
|
||||
|
||||
elseif minetest.get_modpath("technic_worldgen") then
|
||||
-- technic rubber tree
|
||||
|
||||
if minetest.get_modpath("technic_worldgen") then
|
||||
|
||||
bonemeal:add_sapling({
|
||||
{"moretrees:rubber_tree_sapling", technic.rubber_tree_model, "soil"}
|
||||
})
|
||||
end
|
||||
|
||||
-- caverealms mushroom
|
||||
|
||||
if minetest.get_modpath("caverealms") then
|
||||
|
||||
@ -253,22 +264,28 @@ if minetest.get_modpath("caverealms") then
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
local function y_func(grow_func)
|
||||
return function(pos)
|
||||
grow_func({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
end
|
||||
end
|
||||
-- ferns
|
||||
|
||||
if minetest.get_modpath("ferns") then
|
||||
|
||||
local function y_func(grow_func)
|
||||
return function(pos)
|
||||
grow_func({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
end
|
||||
end
|
||||
|
||||
bonemeal:add_sapling({
|
||||
{"ferns:sapling_giant_tree_fern", y_func(abstract_ferns.grow_giant_tree_fern), "soil"},
|
||||
{"ferns:sapling_giant_tree_fern", y_func(abstract_ferns.grow_giant_tree_fern), "sand"},
|
||||
{"ferns:sapling_tree_fern", y_func(abstract_ferns.grow_tree_fern), "soil"}
|
||||
{"ferns:sapling_giant_tree_fern",
|
||||
y_func(abstract_ferns.grow_giant_tree_fern), "soil"},
|
||||
{"ferns:sapling_giant_tree_fern",
|
||||
y_func(abstract_ferns.grow_giant_tree_fern), "sand"},
|
||||
{"ferns:sapling_tree_fern",
|
||||
y_func(abstract_ferns.grow_tree_fern), "soil"}
|
||||
})
|
||||
end
|
||||
|
||||
-- dryplants sapling
|
||||
|
||||
if minetest.get_modpath("dryplants") then
|
||||
|
||||
bonemeal:add_sapling({
|
||||
@ -276,6 +293,7 @@ if minetest.get_modpath("dryplants") then
|
||||
})
|
||||
end
|
||||
|
||||
-- add bonemeal dyes
|
||||
|
||||
if minetest.get_modpath("dye") then
|
||||
|
||||
@ -292,6 +310,7 @@ if minetest.get_modpath("dye") then
|
||||
end
|
||||
end
|
||||
|
||||
-- df_trees saplings
|
||||
|
||||
if minetest.get_modpath("df_trees") then
|
||||
|
||||
@ -335,6 +354,7 @@ if minetest.get_modpath("df_trees") then
|
||||
})
|
||||
end
|
||||
|
||||
-- df_farming crops
|
||||
|
||||
if minetest.get_modpath("df_farming") then
|
||||
|
||||
@ -348,6 +368,7 @@ if minetest.get_modpath("df_farming") then
|
||||
})
|
||||
end
|
||||
|
||||
-- df_primordial saplings and plants
|
||||
|
||||
if minetest.get_modpath("df_primordial_items") then
|
||||
|
||||
@ -417,6 +438,7 @@ if minetest.get_modpath("df_primordial_items") then
|
||||
})
|
||||
end
|
||||
|
||||
-- everness saplings
|
||||
|
||||
if minetest.get_modpath("everness") then
|
||||
|
||||
@ -436,6 +458,7 @@ if minetest.get_modpath("everness") then
|
||||
})
|
||||
end
|
||||
|
||||
-- bush classic fruit
|
||||
|
||||
if minetest.get_modpath("bushes_classic") then
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user