From 66c9e5b502101ee826cfb981ae275b95061249d3 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 18 Feb 2017 21:07:57 +0100 Subject: [PATCH] Make cocoas drop when the jungle tree has been removed --- API.md | 1 + mods/ITEMS/mcl_cocoas/init.lua | 11 ++++++++++- mods/ITEMS/mcl_core/nodes.lua | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index d483127215..b5e479edeb 100644 --- a/API.md +++ b/API.md @@ -85,6 +85,7 @@ These groups are used mostly for informational purposes * `food=3`: Drink (including soups) * `food=1`: Other/unsure * `eatable`: Item can be *directly* eaten by wielding + left click (`on_use=item_eat`). Rating is the satiation gain +* `cocoa`: Node is a cocoa pod (rating is growth stage, ranging from 1 to 3) * `ammo=1`: Item is used as ammo for a weapon * `ammo_bow=1`: Item is used as ammo for bows * `container`: Node is a container which physically stores items within and has at least 1 inventory diff --git a/mods/ITEMS/mcl_cocoas/init.lua b/mods/ITEMS/mcl_cocoas/init.lua index 2bf4264570..1c6efc78c2 100644 --- a/mods/ITEMS/mcl_cocoas/init.lua +++ b/mods/ITEMS/mcl_cocoas/init.lua @@ -67,6 +67,13 @@ end -- Cocoa definition -- 1st stage + +--[[ TODO (code quality): Turn the cocoa nodes into attached nodes and make use of wallmounted. This is much better +than the current ugly hacky check after digging a jungle tree (in mcl_core). +Problem: If we want to use wallmounted, we MUST use a mesh, since wallmounted does not support +nodeboxes with multiple boxes. :-( +Using meshes will also clean up the texture mess. +]] local crop_def = { description = "Young Cocoa", drawtype = "nodebox", @@ -101,7 +108,7 @@ local crop_def = { }, }, groups = { - choppy=3, not_in_creative_inventory=1, dig_by_water = 1, + cocoa = 1, choppy=3, not_in_creative_inventory=1, dig_by_water = 1, }, sounds = mcl_sounds.node_sound_wood_defaults() } @@ -110,6 +117,7 @@ local crop_def = { minetest.register_node("mcl_cocoas:cocoa_1", table.copy(crop_def)) crop_def.description = "Medium Cocoa" +crop_def.groups.cocoa = 2 crop_def.tiles = { "[combine:32x32:10,2=mcl_cocoas_cocoa_stage_1.png", "[combine:32x32:10,18=mcl_cocoas_cocoa_stage_1.png", "mcl_cocoas_cocoa_stage_1.png", "mcl_cocoas_cocoa_stage_1.png^[transformFX", @@ -139,6 +147,7 @@ minetest.register_node("mcl_cocoas:cocoa_2", table.copy(crop_def)) -- Final stage crop_def.description = "Mature Cocoa" +crop_def.groups.cocoa = 3 crop_def.tiles = { -- The following 2 textures were derived from the original because the size of the top/bottom is slightly different :-( -- TODO: Find a way to *only* use the base texture diff --git a/mods/ITEMS/mcl_core/nodes.lua b/mods/ITEMS/mcl_core/nodes.lua index 9b6b59574a..bba5d59186 100644 --- a/mods/ITEMS/mcl_core/nodes.lua +++ b/mods/ITEMS/mcl_core/nodes.lua @@ -590,6 +590,28 @@ minetest.register_node("mcl_core:jungletree", { stack_max = 64, paramtype2 = "facedir", on_place = mcl_util.rotate_axis, + -- This is a bad bad workaround which is only done because cocoas are not wallmounted (but should) + -- As long cocoas only EVER stick to jungle trees, and nothing else, this is probably a lesser sin. + after_dig_node = function(pos, oldnode, oldmetadata, digger) + -- Drop attached cocoas + local posses = { + { x = pos.x + 1, y = pos.y, z = pos.z }, + { x = pos.x - 1, y = pos.y, z = pos.z }, + { x = pos.x, y = pos.y, z = pos.z + 1 }, + { x = pos.x, y = pos.y, z = pos.z - 1 }, + } + for p=1, #posses do + local node = minetest.get_node(posses[p]) + local g = minetest.get_item_group(node.name, "cocoa") + if g and g >= 1 then + minetest.remove_node(posses[p]) + local drops = minetest.get_node_drops(node.name, "") + for d=1, #drops do + minetest.add_item(posses[p], drops[d]) + end + end + end + end, groups = {tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2,building_block=1}, sounds = mcl_sounds.node_sound_wood_defaults(), })