mirror of
https://codeberg.org/tenplus1/bonemeal.git
synced 2025-01-06 16:20:27 +01:00
added mulch and fertiliser items as well as new strength variable
This commit is contained in:
parent
6a9ca6e202
commit
ae18b73c41
16
README.md
16
README.md
@ -1,11 +1,16 @@
|
|||||||
Bonemeal mod [bonemeal]
|
Bonemeal mod [bonemeal]
|
||||||
|
|
||||||
This mod adds two new items into the game, bones which can be dug from normal
|
This mod adds four new items into the game, bones which can be dug from normal
|
||||||
dirt and bonemeal which is crafted from bones and player bone blocks.
|
dirt which can be made into bonemeal, mulch which is is crafted using a tree and
|
||||||
|
8x leaves, and fertiliser which is a mixture of them both.
|
||||||
|
|
||||||
Bonemeal can be used on added saplings for a 1 in 2 chance to grow them quickly
|
Each item can be used on saplings and crops for a chance to grow them quicker as
|
||||||
as well as specified crops which are grown 1 to 4 steps at a time. Dirt can
|
well as dirt which will generate random grass, flowers or whichever decoration
|
||||||
also be clicked for random grass, flowers or registered decoration to appear.
|
is registered.
|
||||||
|
|
||||||
|
Mulch has a strength of 1, Bonemeal 2 and Fertiliser 3 which means the stronger
|
||||||
|
the item, the more chance of growing saplings in low light, making crops sprout
|
||||||
|
quicker or simply decorate a larger area with grass and flowers.
|
||||||
|
|
||||||
The api.txt document shows how to add your own saplings, crops and grasses to
|
The api.txt document shows how to add your own saplings, crops and grasses to
|
||||||
the list by using one of the 3 commands included and the mod.lua file gives you
|
the list by using one of the 3 commands included and the mod.lua file gives you
|
||||||
@ -17,3 +22,4 @@ Changelog:
|
|||||||
|
|
||||||
- 0.1 - Initial release
|
- 0.1 - Initial release
|
||||||
- 0.2 - Added global on_use function for bonemeal growth
|
- 0.2 - Added global on_use function for bonemeal growth
|
||||||
|
- 0.3 - Added strength to on_use global for new items (mulch and fertiliser).
|
||||||
|
7
api.txt
7
api.txt
@ -57,14 +57,17 @@ bonemeal:add_deco({"default:dirt_with_dry_grass", {"default:dry_grass_1", ""},
|
|||||||
Global ON_USE Function
|
Global ON_USE Function
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
bonemeal:on_use(pos)
|
bonemeal:on_use(pos, strength)
|
||||||
|
|
||||||
This function can be called from other mods to grow plants using alternative
|
This function can be called from other mods to grow plants using alternative
|
||||||
bonemeal items and have the same effect.
|
bonemeal items and have the same effect.
|
||||||
|
|
||||||
|
{pos} is the location to apply growing
|
||||||
|
{strength} is how strong to grow [low of 1 to high of 4]
|
||||||
|
|
||||||
|
|
||||||
Final Words
|
Final Words
|
||||||
===========
|
===========
|
||||||
|
|
||||||
I hope this guide helps you add your own plants so you can grow them quickly
|
I hope this guide helps you add your own plants so you can grow them quickly
|
||||||
with bonemeal. Please check the mods.lua for more examples.
|
with the items included. Please check the mods.lua for more examples.
|
||||||
|
144
init.lua
144
init.lua
@ -59,7 +59,7 @@ end
|
|||||||
-- default biomes deco
|
-- default biomes deco
|
||||||
local deco = {
|
local deco = {
|
||||||
{"default:dirt_with_dry_grass", dry_grass, flowers},
|
{"default:dirt_with_dry_grass", dry_grass, flowers},
|
||||||
{"default:sand", {}, {"default:dry_shrub", "", ""} },
|
{"default:sand", {}, {"default:dry_shrub", "", "", ""} },
|
||||||
{"default:desert_sand", {}, {"default:dry_shrub", "", "", ""} },
|
{"default:desert_sand", {}, {"default:dry_shrub", "", "", ""} },
|
||||||
{"default:silver_sand", {}, {"default:dry_shrub", "", "", ""} },
|
{"default:silver_sand", {}, {"default:dry_shrub", "", "", ""} },
|
||||||
}
|
}
|
||||||
@ -104,7 +104,6 @@ local function grow_tree(pos, object)
|
|||||||
elseif type(object) == "function" then
|
elseif type(object) == "function" then
|
||||||
-- function
|
-- function
|
||||||
object(pos)
|
object(pos)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -112,11 +111,6 @@ end
|
|||||||
-- sapling check
|
-- sapling check
|
||||||
local function check_sapling(pos, nodename)
|
local function check_sapling(pos, nodename)
|
||||||
|
|
||||||
-- 1 in 2 chance of spawning sapling
|
|
||||||
if math.random(1, 2) == 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- what is sapling placed on?
|
-- what is sapling placed on?
|
||||||
local under = minetest.get_node({
|
local under = minetest.get_node({
|
||||||
x = pos.x,
|
x = pos.x,
|
||||||
@ -167,7 +161,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- crops check
|
-- crops check
|
||||||
local function check_crops(pos, nodename)
|
local function check_crops(pos, nodename, strength)
|
||||||
|
|
||||||
local stage = ""
|
local stage = ""
|
||||||
|
|
||||||
@ -179,7 +173,7 @@ local function check_crops(pos, nodename)
|
|||||||
|
|
||||||
-- get stage number or set to 0 for seed
|
-- get stage number or set to 0 for seed
|
||||||
stage = tonumber( nodename:split("_")[2] ) or 0
|
stage = tonumber( nodename:split("_")[2] ) or 0
|
||||||
stage = math.min(stage + math.random(1, 4), crops[n][2])
|
stage = math.min(stage + strength, crops[n][2])
|
||||||
|
|
||||||
minetest.set_node(pos, {name = crops[n][1] .. stage})
|
minetest.set_node(pos, {name = crops[n][1] .. stage})
|
||||||
|
|
||||||
@ -195,11 +189,16 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- check soil for specific decoration placement
|
-- check soil for specific decoration placement
|
||||||
local function check_soil(pos, nodename)
|
local function check_soil(pos, nodename, strength)
|
||||||
|
|
||||||
|
-- set radius according to strength
|
||||||
|
local side = strength - 1
|
||||||
|
local tall = math.max(strength - 2, 0)
|
||||||
|
|
||||||
|
-- get area of land with free space above
|
||||||
local dirt = minetest.find_nodes_in_area_under_air(
|
local dirt = minetest.find_nodes_in_area_under_air(
|
||||||
{x = pos.x - 2, y = pos.y - 1, z = pos.z - 2},
|
{x = pos.x - side, y = pos.y - tall, z = pos.z - side},
|
||||||
{x = pos.x + 2, y = pos.y + 1, z = pos.z + 2},
|
{x = pos.x + side, y = pos.y + tall, z = pos.z + side},
|
||||||
{"group:soil", "group:sand"})
|
{"group:soil", "group:sand"})
|
||||||
|
|
||||||
-- set default grass and decoration
|
-- set default grass and decoration
|
||||||
@ -282,7 +281,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- global on_use function for bonemeal
|
-- global on_use function for bonemeal
|
||||||
function bonemeal:on_use(pos)
|
function bonemeal:on_use(pos, strength)
|
||||||
|
|
||||||
-- get node pointed at
|
-- get node pointed at
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
@ -292,27 +291,68 @@ function bonemeal:on_use(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- make sure strength is between 1 and 4
|
||||||
|
strength = strength or 2
|
||||||
|
strength = math.max(strength, 1)
|
||||||
|
strength = math.min(strength, 4)
|
||||||
|
|
||||||
|
-- grow grass and flowers
|
||||||
|
if minetest.get_item_group(node.name, "soil") > 0
|
||||||
|
or minetest.get_item_group(node.name, "sand") > 0 then
|
||||||
|
check_soil(pos, node.name, strength)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- light check depending on strength (strength of 4 = no light needed)
|
||||||
|
if (minetest.get_node_light(pos) or 0) < (12 - (strength * 3)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- check for tree growth if pointing at sapling
|
-- check for tree growth if pointing at sapling
|
||||||
if minetest.get_item_group(node.name, "sapling") > 0 then
|
if minetest.get_item_group(node.name, "sapling") > 0
|
||||||
|
and math.random(1, (5 - strength)) == 1 then
|
||||||
check_sapling(pos, node.name)
|
check_sapling(pos, node.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for crop growth
|
-- check for crop growth
|
||||||
check_crops(pos, node.name)
|
check_crops(pos, node.name, strength)
|
||||||
|
|
||||||
-- grow grass and flowers
|
|
||||||
if minetest.get_item_group(node.name, "soil") > 0
|
|
||||||
or minetest.get_item_group(node.name, "sand") > 0 then
|
|
||||||
check_soil(pos, node.name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
----- items
|
----- items
|
||||||
|
|
||||||
|
|
||||||
-- bonemeal item
|
-- mulch (strength 1)
|
||||||
|
minetest.register_craftitem("bonemeal:mulch", {
|
||||||
|
description = "Mulch",
|
||||||
|
inventory_image = "bonemeal_mulch.png",
|
||||||
|
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
|
-- did we point at a node?
|
||||||
|
if pointed_thing.type ~= "node" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- is area protected?
|
||||||
|
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- take item if not in creative
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- call global on_use function with strength of 1
|
||||||
|
bonemeal:on_use(pointed_thing.under, 1)
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- bonemeal (strength 2)
|
||||||
minetest.register_craftitem("bonemeal:bonemeal", {
|
minetest.register_craftitem("bonemeal:bonemeal", {
|
||||||
description = "Bone Meal",
|
description = "Bone Meal",
|
||||||
inventory_image = "bonemeal_item.png",
|
inventory_image = "bonemeal_item.png",
|
||||||
@ -334,8 +374,38 @@ minetest.register_craftitem("bonemeal:bonemeal", {
|
|||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get position and call global on_use function
|
-- call global on_use function with strength of 2
|
||||||
bonemeal:on_use(pointed_thing.under)
|
bonemeal:on_use(pointed_thing.under, 2)
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
-- fertiliser (strength 3)
|
||||||
|
minetest.register_craftitem("bonemeal:fertiliser", {
|
||||||
|
description = "Fertiliser",
|
||||||
|
inventory_image = "bonemeal_fertiliser.png",
|
||||||
|
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
|
-- did we point at a node?
|
||||||
|
if pointed_thing.type ~= "node" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- is area protected?
|
||||||
|
if minetest.is_protected(pointed_thing.under, user:get_player_name()) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- take item if not in creative
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- call global on_use function with strength of 3
|
||||||
|
bonemeal:on_use(pointed_thing.under, 3)
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
@ -348,19 +418,43 @@ minetest.register_craftitem("bonemeal:bone", {
|
|||||||
inventory_image = "bonemeal_bone.png",
|
inventory_image = "bonemeal_bone.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- bonemeal recipes
|
|
||||||
|
--- crafting recipes
|
||||||
|
|
||||||
|
|
||||||
|
-- bonemeal (from bone)
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
output = "bonemeal:bonemeal 2",
|
output = "bonemeal:bonemeal 2",
|
||||||
recipe = {"bonemeal:bone"},
|
recipe = {"bonemeal:bone"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- bonemeal (from player bones)
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
output = "bonemeal:bonemeal 4",
|
output = "bonemeal:bonemeal 4",
|
||||||
recipe = {"bones:bones"},
|
recipe = {"bones:bones"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- mulch
|
||||||
|
minetest.register_craft({
|
||||||
|
type = "shapeless",
|
||||||
|
output = "bonemeal:mulch 4",
|
||||||
|
recipe = {
|
||||||
|
"group:tree", "group:leaves", "group:leaves",
|
||||||
|
"group:leaves", "group:leaves", "group:leaves",
|
||||||
|
"group:leaves", "group:leaves", "group:leaves"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- fertiliser
|
||||||
|
minetest.register_craft({
|
||||||
|
type = "shapeless",
|
||||||
|
output = "bonemeal:fertiliser 2",
|
||||||
|
recipe = {"bonemeal:bonemeal", "bonemeal:mulch"},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
-- add bones to dirt
|
-- add bones to dirt
|
||||||
minetest.override_item("default:dirt", {
|
minetest.override_item("default:dirt", {
|
||||||
drop = {
|
drop = {
|
||||||
|
BIN
textures/bonemeal_fertiliser.png
Normal file
BIN
textures/bonemeal_fertiliser.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 B |
BIN
textures/bonemeal_mulch.png
Normal file
BIN
textures/bonemeal_mulch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 B |
Loading…
Reference in New Issue
Block a user