init mcl_cauldrons API (WIP)

This commit is contained in:
AFCMS 2021-03-17 21:47:27 +01:00
parent 5df668f6af
commit 182e825303
7 changed files with 79 additions and 17 deletions

View File

@ -216,7 +216,8 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn) doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn)
end 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 -- Take water out of full cauldron
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"}) minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
if not minetest.is_creative_enabled(user:get_player_name()) then if not minetest.is_creative_enabled(user:get_player_name()) then

View File

@ -1,6 +1,6 @@
name = mcl_buckets name = mcl_buckets
author = Kahrl author = Kahrl
description = description =
depends = mcl_worlds depends = mcl_worlds, mcl_cauldrons
optional_depends = mcl_core, mclx_core, doc optional_depends = mcl_core, mclx_core, doc

View File

@ -61,7 +61,7 @@ if mod_mcl_core then
if minetest.get_item_group(nn, "cauldron") ~= 0 then if minetest.get_item_group(nn, "cauldron") ~= 0 then
-- Put water into cauldron -- Put water into cauldron
if nn ~= "mcl_cauldrons:cauldron_3" then if nn ~= "mcl_cauldrons:cauldron_3" then
minetest.set_node(pos, {name="mcl_cauldrons:cauldron_3"}) mcl_cauldrons.set_cauldron(pos, "water", 3)
end end
sound_place("mcl_core:water_source", pos) sound_place("mcl_core:water_source", pos)
return false return false
@ -104,7 +104,7 @@ if mod_mclx_core then
if minetest.get_item_group(nn, "cauldron") ~= 0 then if minetest.get_item_group(nn, "cauldron") ~= 0 then
-- Put water into cauldron -- Put water into cauldron
if nn ~= "mcl_cauldrons:cauldron_3r" then 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 end
sound_place("mcl_core:water_source", pos) sound_place("mcl_core:water_source", pos)
return false return false

View File

@ -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"

View File

@ -1,4 +0,0 @@
mcl_core
mclx_core?
mcl_sounds
doc?

View File

@ -1,9 +1,8 @@
local S = minetest.get_translator("mcl_cauldron") local S = minetest.get_translator("mcl_cauldron")
mcl_cauldrons = {}
-- Cauldron mod, adds cauldrons. -- Cauldron mod, adds cauldrons.
-- TODO: Extinguish fire of burning entities
-- Convenience function because the cauldron nodeboxes are very similar -- Convenience function because the cauldron nodeboxes are very similar
local create_cauldron_nodebox = function(water_level) local create_cauldron_nodebox = function(water_level)
local floor_y local floor_y
@ -41,7 +40,7 @@ for w=0,3 do
cauldron_nodeboxes[w] = create_cauldron_nodebox(w) cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end end
local cauldrons_list = {}
-- Empty cauldron -- Empty cauldron
minetest.register_node("mcl_cauldrons:cauldron", { minetest.register_node("mcl_cauldrons:cauldron", {
description = S("Cauldron"), description = S("Cauldron"),
@ -67,6 +66,53 @@ minetest.register_node("mcl_cauldrons:cauldron", {
_mcl_blast_resistance = 2, _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 -- Template function for cauldrons with water
local register_filled_cauldron = function(water_level, description, river_water) local register_filled_cauldron = function(water_level, description, river_water)
local id = "mcl_cauldrons:cauldron_"..water_level local id = "mcl_cauldrons:cauldron_"..water_level
@ -106,14 +152,15 @@ local register_filled_cauldron = function(water_level, description, river_water)
end end
-- Filled cauldrons (3 levels) -- Filled cauldrons (3 levels)
register_filled_cauldron(1, S("Cauldron (1/3 Water)")) --register_filled_cauldron(1, S("Cauldron (1/3 Water)"))
register_filled_cauldron(2, S("Cauldron (2/3 Water)")) --register_filled_cauldron(2, S("Cauldron (2/3 Water)"))
register_filled_cauldron(3, S("Cauldron (3/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 if minetest.get_modpath("mclx_core") then
register_filled_cauldron(1, S("Cauldron (1/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(2, S("Cauldron (2/3 River Water)"), true)
register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true) --register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true)
end end
minetest.register_craft({ minetest.register_craft({
@ -141,3 +188,10 @@ minetest.register_abm({
end end
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

View File

@ -1 +1,4 @@
name = mcl_cauldrons name = mcl_cauldrons
description = Add cauldrons to mcl
depends = mcl_core, mcl_sounds
optional_depends = mclx_core, doc