add bonemeal mod

master
elite 2017-07-22 21:14:16 -04:00
parent 239aa9b42b
commit 7fb2ceea9d
17 changed files with 788 additions and 0 deletions

View File

@ -0,0 +1,26 @@
Bonemeal mod [bonemeal]
This mod adds four new items into the game, bones which can be dug from normal
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.
Each item can be used on saplings and crops for a chance to grow them quicker as
well as dirt which will generate random grass, flowers or whichever decoration
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 list by using one of the 3 commands included and the mod.lua file gives you
many examples by using some of the popular mods available.
https://forum.minetest.net/viewtopic.php?f=9&t=16446
Changelog:
- 0.1 - Initial release
- 0.2 - Added global on_use function for bonemeal growth
- 0.3 - Added strength to on_use global for new items (mulch and fertiliser).
- 0.4 - Added Intllib support and fr.txt file

View File

@ -0,0 +1,76 @@
Bonemeal API
============
This guide will show you how to add saplings, crops and dirt types for the
bonemeal mod to use from withhin your own mods. Please make sure that bonemeal
appears in the depends.txt file of your mod so everything work properly.
Function Usage
==============
Adding Crops
------------
bonemeal:add_crop({ nodename_start, growing_steps, seed_name })
This command is used to add new crops for bonemeal to work on.
e.g.
bonemeal:add_crop({
{"farming:cotton_", 8, "farming:seed_cotton"},
{"farming:wheat_", 8, "farming:seed_wheat"},
})
Adding Saplings
---------------
bonemeal:add_sapling({ sapling_node, function, soil_type[sand, dirt, nodename] })
This command will add new saplings for bonemeal to grow on sand, soil or a
specified node type.
bonemeal:add_sapling({
{"ethereal:palm_sapling", ethereal.grow_palm_tree, "soil"},
{"ethereal:palm_sapling", ethereal.grow_palm_tree, "sand"},
})
Adding Dirt Decoration
----------------------
bonemeal:add_deco({ dirt_node, {grass_node_list}, {decor_node_list} })
This command will add grass and decoration to specific dirt types, use "" to
add an empty node.
e.g.
bonemeal:add_deco({"default:dirt_with_dry_grass", {"default:dry_grass_1", ""},
{"flowers:rose", "flowers:viola"} })
Global ON_USE Function
----------------------
bonemeal:on_use(pos, strength)
This function can be called from other mods to grow plants using alternative
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]
Note: Higher strength items require lower light levels, and a strength of 4
needs no light at all.
Final Words
===========
I hope this guide helps you add your own plants so you can grow them quickly
with the items included. Please check the mods.lua for more examples.

View File

@ -0,0 +1,6 @@
default
intllib?
farming?
ethereal?
moretrees?
technic_worldgen?

View File

@ -0,0 +1 @@
Adds bone and bonemeal giving the ability to quickly grow plants and saplings.

482
worldmods/bonemeal/init.lua Normal file
View File

@ -0,0 +1,482 @@
bonemeal = {}
-- Load support for intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP .. "/intllib.lua")
-- default crops
local crops = {
{"farming:cotton_", 8, "farming:seed_cotton"},
{"farming:wheat_", 8, "farming:seed_wheat"},
}
-- 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
-- default saplings
local saplings = {
{"default:sapling", default.grow_new_apple_tree, "soil"},
{"default:junglesapling", default.grow_new_jungle_tree, "soil"},
{"default:acacia_sapling", default.grow_new_acacia_tree, "soil"},
{"default:aspen_sapling", default.grow_new_aspen_tree, "soil"},
{"default:pine_sapling", pine_grow, "soil"},
}
-- 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", "", ""
}
local flowers = {
"flowers:dandelion_white", "flowers:dandelion_yellow", "flowers:geranium",
"flowers:rose", "flowers:tulip", "flowers:viola", ""
}
-- add additional bakedclay flowers if enabled
if minetest.get_modpath("bakedclay") then
flowers[7] = "bakedclay:delphinium"
flowers[8] = "bakedclay:thistle"
flowers[9] = "bakedclay:lazarus"
flowers[10] = "bakedclay:mannagrass"
flowers[11] = ""
end
-- default biomes deco
local deco = {
{"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", "", "", ""} },
}
----- local functions
-- 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,
texture = "bonemeal_particle.png",
})
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)
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
end
-- sapling check
local function check_sapling(pos, nodename)
-- 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
if saplings[n][1] == nodename then
grow_on = saplings[n][3]
-- sapling grows on top of specific node
if grow_on
and grow_on ~= "soil"
and grow_on ~= "sand"
and grow_on == under.name then
can_grow = true
end
-- sapling grows on top of soil (default)
if can_grow == nil
and (grow_on == nil or grow_on == "soil")
and minetest.get_item_group(under.name, "soil") > 0 then
can_grow = true
end
-- sapling grows on top of sand
if can_grow == nil
and grow_on == "sand"
and minetest.get_item_group(under.name, "sand") > 0 then
can_grow = true
end
-- check if we can grow sapling
if can_grow then
particle_effect(pos)
grow_tree(pos, saplings[n][2])
return
end
end
end
end
-- crops check
local function check_crops(pos, nodename, strength)
local stage = ""
-- grow registered crops
for n = 1, #crops do
if string.find(nodename, crops[n][1])
or nodename == crops[n][3] then
-- get stage number or set to 0 for seed
stage = tonumber( nodename:split("_")[2] ) or 0
stage = math.min(stage + strength, crops[n][2])
minetest.set_node(pos, {name = crops[n][1] .. stage})
particle_effect(pos)
return
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
local tall = math.max(strength - 2, 0)
-- 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},
{x = pos.x + side, y = pos.y + tall, z = pos.z + side},
{"group:soil", "group:sand"})
-- set default grass and decoration
local grass = green_grass
local decor = flowers
-- 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
grass = deco[n][2] or {}
decor = deco[n][3] or {}
end
end
local pos2, nod
-- loop through soil
for _,n in pairs(dirt) do
pos2 = n
pos2.y = pos2.y + 1
-- place random decoration (rare)
if math.random(1, 5) == 5 then
nod = decor[math.random(1, #decor)] or ""
if nod ~= "" then
minetest.set_node(pos2, {name = nod})
end
else
-- place random grass (common)
nod = grass[math.random(1, #grass)] or ""
if nod ~= "" then
minetest.set_node(pos2, {name = nod})
end
end
particle_effect(pos2)
end
end
-- global functions
-- add to sapling list
-- {sapling node, schematic or function name, "soil"|"sand"|specific_node}
--e.g. {"default:sapling", default.grow_new_apple_tree, "soil"}
function bonemeal:add_sapling(list)
for n = 1, #list do
table.insert(saplings, list[n])
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
table.insert(crops, list[n])
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}
function bonemeal:add_deco(list)
for n = 1, #list do
table.insert(deco, list[n])
end
end
-- global on_use function for bonemeal
function bonemeal:on_use(pos, strength)
-- get node pointed at
local node = 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 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
if minetest.get_item_group(node.name, "sapling") > 0
and math.random(1, (5 - strength)) == 1 then
check_sapling(pos, node.name)
return
end
-- check for crop growth
check_crops(pos, node.name, strength)
end
----- items
-- mulch (strength 1)
minetest.register_craftitem("bonemeal:mulch", {
description = S("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", {
description = S("Bone Meal"),
inventory_image = "bonemeal_item.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 2
bonemeal:on_use(pointed_thing.under, 2)
return itemstack
end,
})
-- fertiliser (strength 3)
minetest.register_craftitem("bonemeal:fertiliser", {
description = S("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
end,
})
-- bone
minetest.register_craftitem("bonemeal:bone", {
description = S("Bone"),
inventory_image = "bonemeal_bone.png",
})
--- crafting recipes
-- bonemeal (from bone)
minetest.register_craft({
type = "shapeless",
output = "bonemeal:bonemeal 2",
recipe = {"bonemeal:bone"},
})
-- bonemeal (from player bones)
minetest.register_craft({
type = "shapeless",
output = "bonemeal:bonemeal 4",
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
minetest.override_item("default:dirt", {
drop = {
max_items = 1,
items = {
{
items = {"bonemeal:bone", "default:dirt"},
rarity = 30,
},
{
items = {"default:dirt"},
}
}
},
})
-- add support for other mods
dofile(minetest.get_modpath("bonemeal") .. "/mods.lua")
print (S("[bonemeal] loaded"))

View File

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 TenPlus1
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,7 @@
# init.lua
Mulch = Paillis
Bone Meal = Poudre d'os
Fertiliser = Engrais
Bone = Os
[bonemeal] loaded = [bonemeal] chargé

View File

@ -0,0 +1,7 @@
# init.lua
Mulch =
Bone Meal =
Fertiliser =
Bone =
[bonemeal] loaded =

View File

@ -0,0 +1 @@
name = bonemeal

116
worldmods/bonemeal/mods.lua Normal file
View File

@ -0,0 +1,116 @@
-- craft bones from animalmaterials into bonemeal
if minetest.get_modpath("animalmaterials") then
minetest.register_craft({
type = "shapeless",
output = "bonemeal:bonemeal 2",
recipe = {"animalmaterials:bone"},
})
end
if farming and farming.mod and farming.mod == "redo" then
bonemeal:add_crop({
{"farming:tomato_", 8},
{"farming:corn_", 8},
{"farming:melon_", 8},
{"farming:pumpkin_", 8},
{"farming:beanpole_", 5},
{"farming:blueberry_", 4},
{"farming:raspberry_", 4},
{"farming:carrot_", 8},
{"farming:cocoa_", 3},
{"farming:coffee_", 5},
{"farming:cucumber_", 4},
{"farming:potato_", 4},
{"farming:grapes_", 8},
{"farming:rhubarb_", 3},
{"farming:barley_", 7},
{"farming:hemp_", 8},
})
end
if minetest.get_modpath("ethereal") then
bonemeal:add_crop({
{"ethereal:strawberry_", 8},
{"ethereal:onion_", 5},
})
bonemeal:add_sapling({
{"ethereal:palm_sapling", ethereal.grow_palm_tree, "soil"},
{"ethereal:palm_sapling", ethereal.grow_palm_tree, "sand"},
{"ethereal:yellow_tree_sapling", ethereal.grow_yellow_tree, "soil"},
{"ethereal:big_tree_sapling", ethereal.grow_big_tree, "soil"},
{"ethereal:banana_tree_sapling", ethereal.grow_banana_tree, "soil"},
{"ethereal:frost_tree_sapling", ethereal.grow_frost_tree, "soil"},
{"ethereal:mushroom_sapling", ethereal.grow_mushroom_tree, "soil"},
{"ethereal:willow_sapling", ethereal.grow_willow_tree, "soil"},
{"ethereal:redwood_sapling", ethereal.grow_redwood_tree, "soil"},
{"ethereal:orange_tree_sapling", ethereal.grow_orange_tree, "soil"},
{"ethereal:bamboo_sprout", ethereal.grow_bamboo_tree, "soil"},
{"ethereal:birch_sapling", ethereal.grow_birch_tree, "soil"},
})
local grass = {"default:grass_3", "default:grass_4", "default:grass_5", ""}
bonemeal:add_deco({
{"ethereal:crystal_dirt", {"ethereal:crystalgrass", "", "", "", ""}, {}},
{"ethereal:fiery_dirt", {"ethereal:dry_shrub", "", "", "", ""}, {}},
{"ethereal:prairie_dirt", grass, {"flowers:dandelion_white",
"flowers:dandelion_yellow", "flowers:geranium", "flowers:rose",
"flowers:tulip", "flowers:viola", "ethereal:strawberry_7"}},
{"ethereal:gray_dirt", {}, {"ethereal:snowygrass", "", ""}},
{"ethereal:cold_dirt", {}, {"ethereal:snowygrass", "", ""}},
{"ethereal:mushroom_dirt", {}, {"flowers:mushroom_red", "flowers:mushroom_brown", "", "", ""}},
{"ethereal:jungle_dirt", grass, {"default:junglegrass", "", "", ""}},
{"ethereal:grove_dirt", grass, {"ethereal:fern", "", "", ""}},
{"ethereal:bamboo_dirt", grass, {}},
})
end
if minetest.get_modpath("moretrees") then
-- special fir check for snow
local function fir_grow(pos)
if minetest.find_node_near(pos, 1,
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) then
moretrees.grow_fir_snow(pos)
else
moretrees.grow_fir(pos)
end
end
bonemeal:add_sapling({
{"moretrees:beech_sapling", moretrees.spawn_beech_object, "soil"},
{"moretrees:apple_tree_sapling", moretrees.spawn_apple_tree_object, "soil"},
{"moretrees:oak_sapling", moretrees.spawn_oak_object, "soil"},
{"moretrees:sequoia_sapling", moretrees.spawn_sequoia_object, "soil"},
--{"moretrees:birch_sapling", moretrees.spawn_birch_object, "soil"},
{"moretrees:birch_sapling", moretrees.grow_birch, "soil"},
{"moretrees:palm_sapling", moretrees.spawn_palm_object, "soil"},
{"moretrees:palm_sapling", moretrees.spawn_palm_object, "sand"},
{"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "soil"},
{"moretrees:date_palm_sapling", moretrees.spawn_date_palm_object, "sand"},
--{"moretrees:spruce_sapling", moretrees.spawn_spruce_object, "soil"},
{"moretrees:spruce_sapling", moretrees.grow_spruce, "soil"},
{"moretrees:cedar_sapling", moretrees.spawn_cedar_object, "soil"},
{"moretrees:poplar_sapling", moretrees.spawn_poplar_object, "soil"},
{"moretrees:willow_sapling", moretrees.spawn_willow_object, "soil"},
{"moretrees:rubber_tree_sapling", moretrees.spawn_rubber_tree_object, "soil"},
{"moretrees:fir_sapling", fir_grow, "soil"},
})
elseif minetest.get_modpath("technic_worldgen") then
bonemeal:add_sapling({
{"moretrees:rubber_tree_sapling", technic.rubber_tree_model, "soil"},
})
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B