From 182e825303716e0bc18c374429d9034a4e84a3f1 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 17 Mar 2021 21:47:27 +0100 Subject: [PATCH] init mcl_cauldrons API (WIP) --- mods/ITEMS/mcl_buckets/init.lua | 3 +- mods/ITEMS/mcl_buckets/mod.conf | 2 +- mods/ITEMS/mcl_buckets/register.lua | 4 +- mods/ITEMS/mcl_cauldrons/API.md | 8 ++++ mods/ITEMS/mcl_cauldrons/depends.txt | 4 -- mods/ITEMS/mcl_cauldrons/init.lua | 72 ++++++++++++++++++++++++---- mods/ITEMS/mcl_cauldrons/mod.conf | 3 ++ 7 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 mods/ITEMS/mcl_cauldrons/API.md delete mode 100644 mods/ITEMS/mcl_cauldrons/depends.txt diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index 30e4075c86..ca62fe2b82 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -216,7 +216,8 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", { doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn) end - elseif nn == "mcl_cauldrons:cauldron_3" then + elseif minetest.get_item_group(nn, "cauldron") then + mcl_cauldrons.take_cauldron(pos, itemstack) -- Take water out of full cauldron minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) if not minetest.is_creative_enabled(user:get_player_name()) then diff --git a/mods/ITEMS/mcl_buckets/mod.conf b/mods/ITEMS/mcl_buckets/mod.conf index 5a78e70ada..5aed8805fc 100644 --- a/mods/ITEMS/mcl_buckets/mod.conf +++ b/mods/ITEMS/mcl_buckets/mod.conf @@ -1,6 +1,6 @@ name = mcl_buckets author = Kahrl description = -depends = mcl_worlds +depends = mcl_worlds, mcl_cauldrons optional_depends = mcl_core, mclx_core, doc diff --git a/mods/ITEMS/mcl_buckets/register.lua b/mods/ITEMS/mcl_buckets/register.lua index b5d86ac0e8..1f5e4e377b 100644 --- a/mods/ITEMS/mcl_buckets/register.lua +++ b/mods/ITEMS/mcl_buckets/register.lua @@ -61,7 +61,7 @@ if mod_mcl_core then if minetest.get_item_group(nn, "cauldron") ~= 0 then -- Put water into cauldron if nn ~= "mcl_cauldrons:cauldron_3" then - minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3"}) + mcl_cauldrons.set_cauldron(pos, "water", 3) end sound_place("mcl_core:water_source", pos) return false @@ -104,7 +104,7 @@ if mod_mclx_core then if minetest.get_item_group(nn, "cauldron") ~= 0 then -- Put water into cauldron if nn ~= "mcl_cauldrons:cauldron_3r" then - minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3r"}) + mcl_cauldrons.set_cauldron(pos, "river_water", 3) end sound_place("mcl_core:water_source", pos) return false diff --git a/mods/ITEMS/mcl_cauldrons/API.md b/mods/ITEMS/mcl_cauldrons/API.md new file mode 100644 index 0000000000..8c80fa1d55 --- /dev/null +++ b/mods/ITEMS/mcl_cauldrons/API.md @@ -0,0 +1,8 @@ +# mcl_cauldrons + +This mod add an API to add cauldrons to mcl. + +## mcl_cauldrons.register_cauldron_type(name, desc, texture) +* name: name of the liquid e.g: "water" +* desc: description of the item. %s will be replaced by the level. e.g: "Water Cauldron %s/3 full" +* texture: texture of the flowing liquid e.g: "mcl_core_water_flowing.png" \ No newline at end of file diff --git a/mods/ITEMS/mcl_cauldrons/depends.txt b/mods/ITEMS/mcl_cauldrons/depends.txt deleted file mode 100644 index 2c344c60c8..0000000000 --- a/mods/ITEMS/mcl_cauldrons/depends.txt +++ /dev/null @@ -1,4 +0,0 @@ -mcl_core -mclx_core? -mcl_sounds -doc? diff --git a/mods/ITEMS/mcl_cauldrons/init.lua b/mods/ITEMS/mcl_cauldrons/init.lua index f4356d27b1..251392f8d3 100644 --- a/mods/ITEMS/mcl_cauldrons/init.lua +++ b/mods/ITEMS/mcl_cauldrons/init.lua @@ -1,9 +1,8 @@ local S = minetest.get_translator("mcl_cauldron") +mcl_cauldrons = {} -- Cauldron mod, adds cauldrons. --- TODO: Extinguish fire of burning entities - -- Convenience function because the cauldron nodeboxes are very similar local create_cauldron_nodebox = function(water_level) local floor_y @@ -41,7 +40,7 @@ for w=0,3 do cauldron_nodeboxes[w] = create_cauldron_nodebox(w) end - +local cauldrons_list = {} -- Empty cauldron minetest.register_node("mcl_cauldrons:cauldron", { description = S("Cauldron"), @@ -67,6 +66,53 @@ minetest.register_node("mcl_cauldrons:cauldron", { _mcl_blast_resistance = 2, }) +function mcl_cauldrons.set_cauldron(pos, type, level) + if cauldrons_list["mcl_cauldrons:cauldron_"..type.."_"..level] then + minetest.set_node(pos, {name="mcl_cauldrons:cauldron_"..type.."_"..level}) + return true + else + minetest.log("error", "[mcl_cauldrons] trying to set invalid cauldron") + return false + end +end + +function mcl_cauldrons.take_cauldron(pos, itemstack, sound) + return +end + +function mcl_cauldrons.register_cauldron_type(name, desc, texture) + for water_level = 1,3 do + local id = "mcl_cauldrons:cauldron_"..name.."_"..water_level + cauldrons_list[id] = true + minetest.register_node(id, { + description = string.format(desc, water_level), + _doc_items_create_entry = false, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + drawtype = "nodebox", + paramtype = "light", + is_ground_content = false, + groups = {pickaxey=1, not_in_creative_inventory=1, cauldron=(1+water_level), cauldron_filled=water_level, comparator_signal=water_level}, + node_box = cauldron_nodeboxes[water_level], + collision_box = cauldron_nodeboxes[0], + selection_box = { type = "regular" }, + tiles = { + "("..texture.."^[verticalframe:16:0"..")^mcl_cauldrons_cauldron_top.png", + "mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png", + "mcl_cauldrons_cauldron_side.png" + }, + sounds = mcl_sounds.node_sound_metal_defaults(), + drop = "mcl_cauldrons:cauldron", + _mcl_hardness = 2, + _mcl_blast_resistance = 2, + }) + + -- Add entry aliases for the Help + if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", id) + end + end +end + -- Template function for cauldrons with water local register_filled_cauldron = function(water_level, description, river_water) local id = "mcl_cauldrons:cauldron_"..water_level @@ -106,14 +152,15 @@ local register_filled_cauldron = function(water_level, description, river_water) end -- Filled cauldrons (3 levels) -register_filled_cauldron(1, S("Cauldron (1/3 Water)")) -register_filled_cauldron(2, S("Cauldron (2/3 Water)")) -register_filled_cauldron(3, S("Cauldron (3/3 Water)")) +--register_filled_cauldron(1, S("Cauldron (1/3 Water)")) +--register_filled_cauldron(2, S("Cauldron (2/3 Water)")) +--register_filled_cauldron(3, S("Cauldron (3/3 Water)")) +mcl_cauldrons.register_cauldron_type("water", S("Cauldron (%s/3 Water)"), "default_water_source_animated.png") if minetest.get_modpath("mclx_core") then - register_filled_cauldron(1, S("Cauldron (1/3 River Water)"), true) - register_filled_cauldron(2, S("Cauldron (2/3 River Water)"), true) - register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true) + --register_filled_cauldron(1, S("Cauldron (1/3 River Water)"), true) + --register_filled_cauldron(2, S("Cauldron (2/3 River Water)"), true) + --register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true) end minetest.register_craft({ @@ -141,3 +188,10 @@ minetest.register_abm({ end end }) + +for i = 1, 3 do --Backward compatibility + minetest.register_alias("mcl_cauldrons:cauldron_"..i, "mcl_cauldrons:cauldron_water_"..i) +end +for i = 1, 3 do + minetest.register_alias("mcl_cauldrons:cauldron_"..i.."r", "mcl_cauldrons:cauldron_river_water_"..i) +end \ No newline at end of file diff --git a/mods/ITEMS/mcl_cauldrons/mod.conf b/mods/ITEMS/mcl_cauldrons/mod.conf index 1bedf9d731..40dd3e47a2 100644 --- a/mods/ITEMS/mcl_cauldrons/mod.conf +++ b/mods/ITEMS/mcl_cauldrons/mod.conf @@ -1 +1,4 @@ name = mcl_cauldrons +description = Add cauldrons to mcl +depends = mcl_core, mcl_sounds +optional_depends = mclx_core, doc \ No newline at end of file