From 7b5d67cdbe890218b2f1b1c0555ee8fd37f266f3 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 11 Mar 2021 22:13:43 +0100 Subject: [PATCH] add flowerpots API --- mods/ITEMS/mcl_core/mod.conf | 2 +- mods/ITEMS/mcl_flowerpots/depends.txt | 5 - mods/ITEMS/mcl_flowerpots/init.lua | 238 ++++++++++++-------------- mods/ITEMS/mcl_flowerpots/mod.conf | 3 + mods/ITEMS/mcl_flowers/depends.txt | 5 - mods/ITEMS/mcl_flowers/init.lua | 44 ++--- mods/ITEMS/mcl_flowers/mod.conf | 3 + mods/ITEMS/mcl_flowers/register.lua | 72 ++++++-- 8 files changed, 200 insertions(+), 172 deletions(-) delete mode 100644 mods/ITEMS/mcl_flowerpots/depends.txt create mode 100644 mods/ITEMS/mcl_flowerpots/mod.conf delete mode 100644 mods/ITEMS/mcl_flowers/depends.txt create mode 100644 mods/ITEMS/mcl_flowers/mod.conf diff --git a/mods/ITEMS/mcl_core/mod.conf b/mods/ITEMS/mcl_core/mod.conf index 575c46655d..9227d607ec 100644 --- a/mods/ITEMS/mcl_core/mod.conf +++ b/mods/ITEMS/mcl_core/mod.conf @@ -1 +1 @@ -name = mcl_core +name = mcl_core \ No newline at end of file diff --git a/mods/ITEMS/mcl_flowerpots/depends.txt b/mods/ITEMS/mcl_flowerpots/depends.txt deleted file mode 100644 index bc1609be29..0000000000 --- a/mods/ITEMS/mcl_flowerpots/depends.txt +++ /dev/null @@ -1,5 +0,0 @@ -mcl_core -mcl_sounds -mcl_farming -mcl_flowers -doc? diff --git a/mods/ITEMS/mcl_flowerpots/init.lua b/mods/ITEMS/mcl_flowerpots/init.lua index 5a752c407f..fe022672fe 100644 --- a/mods/ITEMS/mcl_flowerpots/init.lua +++ b/mods/ITEMS/mcl_flowerpots/init.lua @@ -1,4 +1,8 @@ local S = minetest.get_translator("mcl_flowerpots") +local has_doc = minetest.get_modpath("doc") + +mcl_flowerpots = {} +mcl_flowerpots.registered_pots = {} local flowers = { {"dandelion", "mcl_flowers:dandelion", S("Dandelion Flower Pot")}, @@ -23,10 +27,6 @@ local flowers = { {"fern", "mcl_flowers:fern", S("Fern Flower Pot"), {"mcl_flowers_fern_inv.png"}}, } -local cubes = { - {"cactus", "mcl_core:cactus", S("Cactus Flower Pot")}, -} - minetest.register_node("mcl_flowerpots:flower_pot", { description = S("Flower Pot"), _tt_help = S("Can hold a small flower or plant"), @@ -62,24 +62,10 @@ minetest.register_node("mcl_flowerpots:flower_pot", { return end local item = clicker:get_wielded_item():get_name() - for _, row in ipairs(flowers) do - local flower = row[1] - local flower_node = row[2] - if item == flower_node then - minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower}) - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end - end - end - for _, row in ipairs(cubes) do - local flower = row[1] - local flower_node = row[2] - if item == flower_node then - minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower}) - if not minetest.is_creative_enabled(clicker:get_player_name()) then - itemstack:take_item() - end + if mcl_flowerpots.registered_pots[item] then + minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..mcl_flowerpots.registered_pots[item]}) + if not minetest.is_creative_enabled(clicker:get_player_name()) then + itemstack:take_item() end end end, @@ -94,112 +80,106 @@ minetest.register_craft({ } }) -for _, row in ipairs(flowers) do -local flower = row[1] -local flower_node = row[2] -local desc = row[3] -local texture -if row[4] then - texture = row[4] -else - texture = minetest.registered_nodes[flower_node]["tiles"] +function mcl_flowerpots.register_potted_flower(name, def) + mcl_flowerpots.registered_pots[name] = def.name + minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, { + description = def.desc.." "..S("Flower Pot"), + _doc_items_create_entry = false, + drawtype = "mesh", + mesh = "flowerpot.obj", + tiles = { + "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..def.image, + }, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + visual_scale = 0.5, + wield_scale = {x=1.0, y=1.0, z=1.0}, + paramtype = "light", + sunlight_propagates = true, + selection_box = { + type = "fixed", + fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + collision_box = { + type = "fixed", + fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + is_ground_content = false, + groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, + sounds = mcl_sounds.node_sound_stone_defaults(), + on_rightclick = function(pos, item, clicker) + local player_name = clicker:get_player_name() + if minetest.is_protected(pos, player_name) then + minetest.record_protection_violation(pos, player_name) + return + end + minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name) + minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) + end, + drop = { + items = { + { items = { "mcl_flowerpots:flower_pot", name } } + } + }, + }) + -- Add entry alias for the Help + if has_doc then + doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..name) + end end -minetest.register_node("mcl_flowerpots:flower_pot_"..flower, { - description = desc, - _doc_items_create_entry = false, - drawtype = "mesh", - mesh = "flowerpot.obj", - tiles = { - "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..texture[1], - }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - visual_scale = 0.5, - wield_scale = {x=1.0, y=1.0, z=1.0}, - paramtype = "light", - sunlight_propagates = true, - selection_box = { - type = "fixed", - fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - collision_box = { - type = "fixed", - fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - is_ground_content = false, - groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, - sounds = mcl_sounds.node_sound_stone_defaults(), - on_rightclick = function(pos, item, clicker) - local name = clicker:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return - end - minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, flower_node) - minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) - end, - drop = { - items = { - { items = { "mcl_flowerpots:flower_pot", flower_node } } - } - }, + +function mcl_flowerpots.register_potted_cube(name, def) + mcl_flowerpots.registered_pots[name] = def.name + minetest.register_node(":mcl_flowerpots:flower_pot_"..def.name, { + description = def.desc.." "..S("Flower Pot"), + _doc_items_create_entry = false, + drawtype = "mesh", + mesh = "flowerpot_with_long_cube.obj", + tiles = { + "[combine:32x32:0,0=mcl_flowerpots_flowerpot.png:0,0="..def.image, + }, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + visual_scale = 0.5, + wield_scale = {x=1.0, y=1.0, z=1.0}, + paramtype = "light", + sunlight_propagates = true, + selection_box = { + type = "fixed", + fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + collision_box = { + type = "fixed", + fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} + }, + is_ground_content = false, + groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, + sounds = mcl_sounds.node_sound_stone_defaults(), + on_rightclick = function(pos, item, clicker) + local name = "" + if clicker:is_player() then + player_name = clicker:get_player_name() + end + if minetest.is_protected(pos, player_name) then + minetest.record_protection_violation(pos, player_name) + return + end + minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, name) + minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) + end, + drop = { + items = { + { items = { "mcl_flowerpots:flower_pot", name } } + } + }, + }) + -- Add entry alias for the Help + if has_doc then + doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..def.name) + end +end + +--forced because hard dependency to mcl_core +mcl_flowerpots.register_potted_cube("mcl_core:cactus", { + name = "cactus", + desc = S("Cactus"), + image = "mcl_flowerpots_cactus.png", }) --- Add entry alias for the Help -if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..flower) -end -end - -for _, row in ipairs(cubes) do -local flower = row[1] -local flower_node = row[2] -local desc = row[3] -minetest.register_node("mcl_flowerpots:flower_pot_"..flower, { - description = desc, - _doc_items_create_entry = false, - drawtype = "mesh", - mesh = "flowerpot_with_long_cube.obj", - tiles = { - "mcl_flowerpots_"..flower..".png", - }, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - visual_scale = 0.5, - wield_scale = {x=1.0, y=1.0, z=1.0}, - paramtype = "light", - sunlight_propagates = true, - selection_box = { - type = "fixed", - fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - collision_box = { - type = "fixed", - fixed = {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2} - }, - is_ground_content = false, - groups = {dig_immediate=3, attached_node=1, dig_by_piston=1, not_in_creative_inventory=1, flower_pot=2}, - sounds = mcl_sounds.node_sound_stone_defaults(), - on_rightclick = function(pos, item, clicker) - local name = "" - if clicker:is_player() then - name = clicker:get_player_name() - end - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return - end - minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, flower_node) - minetest.set_node(pos, {name="mcl_flowerpots:flower_pot"}) - end, - drop = { - items = { - { items = { "mcl_flowerpots:flower_pot", flower_node } } - } - }, - - -}) - --- Add entry alias for the Help -if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", "mcl_flowerpots:flower_pot", "nodes", "mcl_flowerpots:flower_pot_"..flower) -end -end diff --git a/mods/ITEMS/mcl_flowerpots/mod.conf b/mods/ITEMS/mcl_flowerpots/mod.conf new file mode 100644 index 0000000000..e6a71c4daf --- /dev/null +++ b/mods/ITEMS/mcl_flowerpots/mod.conf @@ -0,0 +1,3 @@ +name=mcl_flowerpots +depends=mcl_core, mcl_sounds, mcl_farming +optional_depends=doc \ No newline at end of file diff --git a/mods/ITEMS/mcl_flowers/depends.txt b/mods/ITEMS/mcl_flowers/depends.txt deleted file mode 100644 index a7a7b9cd15..0000000000 --- a/mods/ITEMS/mcl_flowers/depends.txt +++ /dev/null @@ -1,5 +0,0 @@ -mcl_core -mcl_util -mcl_sounds -screwdriver? -doc? diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index 8b1a605d3d..aa94d54003 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -1,5 +1,6 @@ local S = minetest.get_translator("mcl_flowers") local mod_screwdriver = minetest.get_modpath("screwdriver") ~= nil +local has_mcl_flowerpots = minetest.get_modpath("mcl_flowerpots") local modpath = minetest.get_modpath("mcl_flowers") mcl_flowers = {} @@ -53,48 +54,49 @@ local on_place_flower = mcl_util.generate_on_place_plant_function(function(pos, return ok, colorize end) -function mcl_flowers.register_simple_flower(name, desc, image, simple_selection_box) +function mcl_flowers.register_simple_flower(name, def) local newname = "mcl_flowers:"..name + if not def._mcl_silk_touch_drop then def._mcl_silk_touch_drop = nil end + if not def.drop then def.drop = newname end mcl_flowers.registered_simple_flowers[newname] = { - desc=desc - image=image - simple_selection_box=simple_selection_box + name=name, + desc=def.desc, + pot_desc=def.pot_desc, + image=def.image, + selection_box=def.selection_box, } minetest.register_node(newname, { - description = desc, + description = def.desc, _doc_items_longdesc = smallflowerlongdesc, _doc_items_usagehelp = plant_usage_help, drawtype = "plantlike", waving = 1, - tiles = { image..".png" }, - inventory_image = image..".png", - wield_image = image..".png", + tiles = { def.image }, + inventory_image = def.image, + wield_image = def.image, sunlight_propagates = true, paramtype = "light", walkable = false, stack_max = 64, + drop = def.drop, groups = {dig_immediate=3,flammable=2,fire_encouragement=60,fire_flammability=100,plant=1,flower=1,place_flowerlike=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,destroy_by_lava_flow=1,dig_by_piston=1,enderman_takable=1,deco_block=1}, sounds = mcl_sounds.node_sound_leaves_defaults(), node_placement_prediction = "", on_place = on_place_flower, selection_box = { type = "fixed", - fixed = simple_selection_box, + fixed = def.selection_box, }, + _mcl_silk_touch_drop = def._mcl_silk_touch_drop, }) + if def.potted and has_mcl_flowerpots then + mcl_flowerpots.register_potted_flower(newname, { + name = name, + desc = def.desc, + image = def.image, + }) + end end -local add_simple_flower = mcl_flowers.register_simple_flower -add_simple_flower("poppy", S("Poppy"), "mcl_flowers_poppy", { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 }) -add_simple_flower("dandelion", S("Dandelion"), "flowers_dandelion_yellow", { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 }) -add_simple_flower("oxeye_daisy", S("Oxeye Daisy"), "mcl_flowers_oxeye_daisy", { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 }) -add_simple_flower("tulip_orange", S("Orange Tulip"), "flowers_tulip", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) -add_simple_flower("tulip_pink", S("Pink Tulip"), "mcl_flowers_tulip_pink", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) -add_simple_flower("tulip_red", S("Red Tulip"), "mcl_flowers_tulip_red", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) -add_simple_flower("tulip_white", S("White Tulip"), "mcl_flowers_tulip_white", { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 }) -add_simple_flower("allium", S("Allium"), "mcl_flowers_allium", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) -add_simple_flower("azure_bluet", S("Azure Bluet"), "mcl_flowers_azure_bluet", { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 }) -add_simple_flower("blue_orchid", S("Blue Orchid"), "mcl_flowers_blue_orchid", { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 }) - local wheat_seed_drop = { max_items = 1, diff --git a/mods/ITEMS/mcl_flowers/mod.conf b/mods/ITEMS/mcl_flowers/mod.conf new file mode 100644 index 0000000000..b309ac22e8 --- /dev/null +++ b/mods/ITEMS/mcl_flowers/mod.conf @@ -0,0 +1,3 @@ +name=mcl_flowers +depends=mcl_core, mcl_util, mcl_sounds +optional_depends=screwdriver, doc, mcl_flowerpots \ No newline at end of file diff --git a/mods/ITEMS/mcl_flowers/register.lua b/mods/ITEMS/mcl_flowers/register.lua index 8a83491e33..9b65caebf4 100644 --- a/mods/ITEMS/mcl_flowers/register.lua +++ b/mods/ITEMS/mcl_flowers/register.lua @@ -1,12 +1,62 @@ local S = minetest.get_translator("mcl_flowers") -local add_simple_flower = mcl_flowers.register_simple_flower -add_simple_flower("poppy", S("Poppy"), "mcl_flowers_poppy", { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 }) -add_simple_flower("dandelion", S("Dandelion"), "flowers_dandelion_yellow", { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 }) -add_simple_flower("oxeye_daisy", S("Oxeye Daisy"), "mcl_flowers_oxeye_daisy", { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 }) -add_simple_flower("tulip_orange", S("Orange Tulip"), "flowers_tulip", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) -add_simple_flower("tulip_pink", S("Pink Tulip"), "mcl_flowers_tulip_pink", { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }) -add_simple_flower("tulip_red", S("Red Tulip"), "mcl_flowers_tulip_red", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) -add_simple_flower("tulip_white", S("White Tulip"), "mcl_flowers_tulip_white", { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 }) -add_simple_flower("allium", S("Allium"), "mcl_flowers_allium", { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }) -add_simple_flower("azure_bluet", S("Azure Bluet"), "mcl_flowers_azure_bluet", { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 }) -add_simple_flower("blue_orchid", S("Blue Orchid"), "mcl_flowers_blue_orchid", { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 }) \ No newline at end of file + +mcl_flowers.register_simple_flower("poppy", { + desc = S("Poppy"), + image = "mcl_flowers_poppy.png", + selection_box = { -5/16, -0.5, -5/16, 5/16, 5/16, 5/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("dandelion", { + desc = S("Dandelion"), + image = "flowers_dandelion_yellow.png", + selection_box = { -4/16, -0.5, -4/16, 4/16, 3/16, 4/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("oxeye_daisy", { + desc = S("Oxeye Daisy"), + image = "mcl_flowers_oxeye_daisy.png", + selection_box = { -4/16, -0.5, -4/16, 4/16, 4/16, 4/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("tulip_orange", { + desc = S("Orange Tulip"), + image = "flowers_tulip.png", + selection_box = { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("tulip_pink", { + desc = S("Pink Tulip"), + image = "mcl_flowers_tulip_pink.png", + selection_box = { -3/16, -0.5, -3/16, 3/16, 5/16, 3/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("tulip_red", { + desc = S("Red Tulip"), + image = "mcl_flowers_tulip_red.png", + selection_box = { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("tulip_white", { + desc = S("White Tulip"), + image = "mcl_flowers_tulip_white.png", + selection_box = { -3/16, -0.5, -3/16, 3/16, 4/16, 3/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("allium", { + desc = S("Allium"), + image = "mcl_flowers_allium.png", + selection_box = { -3/16, -0.5, -3/16, 3/16, 6/16, 3/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("azure_bluet", { + desc = S("Azure Bluet"), + image = "mcl_flowers_azure_bluet.png", + selection_box = { -5/16, -0.5, -5/16, 5/16, 3/16, 5/16 }, + potted = true, +}) +mcl_flowers.register_simple_flower("blue_orchid", { + desc = S("Blue Orchid"), + image = "mcl_flowers_blue_orchid.png", + selection_box = { -5/16, -0.5, -5/16, 5/16, 7/16, 5/16 }, + potted = true, +}) \ No newline at end of file