From 6ac7a6f6083d8c8e734a93b57df60a00dd880da0 Mon Sep 17 00:00:00 2001 From: sys4 Date: Wed, 22 Jul 2020 16:32:59 +0200 Subject: [PATCH] [nalc_riesenpilz] Ajoute support bonemeal --- nalc_riesenpilz/init.lua | 116 ++++++++++++++++++++++++++++++++++++++- nalc_riesenpilz/mod.conf | 1 + 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/nalc_riesenpilz/init.lua b/nalc_riesenpilz/init.lua index 29ad883..d1ef1e5 100644 --- a/nalc_riesenpilz/init.lua +++ b/nalc_riesenpilz/init.lua @@ -1530,7 +1530,7 @@ end for _,mushname in pairs({ "brown", "red", "fly_agaric", "lavashroom", "glowshroom", - "parasol" + "parasol", "red45" }) do minetest.register_decoration( { @@ -1545,3 +1545,117 @@ for _,mushname in pairs({ decoration = "riesenpilz:"..mushname, }) end + +-- Bonemeal support +if minetest.get_modpath("bonemeal") then + + local grow_params = { + ["riesenpilz:red"] = { + [1] = { + schem = gmr_tiny_schem, + }, + [2] = { + schem = gmr_mid_schem, + }, + [3] = { + schem = gmr_big_schem, + }}, + ["riesenpilz:fly_agaric"] = { + [1] = { + schem = gymr_schem, + }}, + ["riesenpilz:brown"] = { + [1] = { + schem = gmb_tiny_schem, + }, + [2] = { + schem = gmb_mid_schem, + }, + [3] = { + schem = gmb_big_schem, + }}, + ["riesenpilz:lavashroom"] = { + [1] = { + schem = gml_schem, + }}, + ["riesenpilz:glowshroom"] = { + [1] = { + schem = gmg_schem, + }}, + ["riesenpilz:parasol"] = { + [1] = { + schem = gmw_mid_schem, + }, + [2] = { + schem = gmw_big_schem, + }}, + ["riesenpilz:red45"] = { + [1] = { + schem = gmr45_schem, + }}, + } + + -- Override mushrooms + for _,mushname in pairs({ + "brown", "red", "fly_agaric", + "lavashroom", "glowshroom", + "parasol", "red45" + }) do + + local groups = table.copy(minetest.registered_nodes["riesenpilz:"..mushname].groups) + groups.sapling = 1 + local minp = table.copy( grow_params["riesenpilz:"..mushname][#grow_params["riesenpilz:"..mushname]].schem.size) + local maxp = table.copy(minp) + minp.x = 0 - math.floor(minp.x/2) + minp.y = 1 + minp.z = minp.x + maxp.x = math.abs(minp.x) + maxp.z = maxp.x + + minetest.override_item( + "riesenpilz:"..mushname, { + groups = groups, + on_place = function(itemstack, placer, pointed_thing) + itemstack = default.sapling_on_place( + itemstack, placer, pointed_thing, + "riesenpilz:"..mushname, + minp, + maxp, + 4) + return itemstack + end, + }) + end + + local function grow_mushroom(pos) + if not default.can_grow(pos) then + return + end + + local node = minetest.get_node(pos) + local grow_param = grow_params[node.name] + + if grow_param then + minetest.log("action", "A mushroom grows into a giant mushroom at ".. + minetest.pos_to_string(pos)) + local i = math.random(1, #grow_param) + local center = table.copy(grow_param[i].schem.size) + center.x = pos.x - (math.floor(center.x/2)) + center.y = pos.y - 1 + center.z = pos.z - (math.floor(center.z/2)) + minetest.place_schematic(center, grow_param[i].schem, nil, nil, true) + end + end + + bonemeal:add_sapling({ + {"riesenpilz:red", grow_mushroom, "soil"}, + {"riesenpilz:fly_agaric", grow_mushroom, "soil"}, + {"riesenpilz:brown", grow_mushroom, "soil"}, + {"riesenpilz:lavashroom", grow_mushroom, "soil"}, + {"riesenpilz:glowshroom", grow_mushroom, "soil"}, + {"riesenpilz:parasol", grow_mushroom, "soil"}, + {"riesenpilz:red45", grow_mushroom, "soil"} + }) +end + +minetest.log("action", "[nalc_riesenpilz] loaded.") diff --git a/nalc_riesenpilz/mod.conf b/nalc_riesenpilz/mod.conf index 6ab9350..7046e78 100644 --- a/nalc_riesenpilz/mod.conf +++ b/nalc_riesenpilz/mod.conf @@ -1,3 +1,4 @@ name = nalc_riesenpilz description = Generate mushroom biomes with schematics in Minetest. depends = default,riesenpilz,stairs +optional_depends = bonemeal