move more functions

This commit is contained in:
AFCMS 2021-03-27 12:03:14 +01:00
parent 989384f362
commit a99619774d
3 changed files with 58 additions and 53 deletions

View File

@ -5,6 +5,10 @@ This mod add an API to add cauldrons to mcl.
## mcl_cauldrons.is_cauldron(name) ## mcl_cauldrons.is_cauldron(name)
return true if name is cauldron, false overwise. return true if name is cauldron, false overwise.
## mcl_cauldrons.get_cauldron_string(type, level)
return itemstring of cauldron with <type> and <level>
e.g: `mcl_cauldrons.get_cauldron_string("water", 1) --return itemstring of a water cauldron with 1 level of water`
## mcl_cauldrons.take_cauldron(pos, itemstack, user, sounds) ## mcl_cauldrons.take_cauldron(pos, itemstack, user, sounds)
empty cauldron at `pos` empty cauldron at `pos`
return `bucket` field of the cauldron def if user is player, itemstack overwise. return `bucket` field of the cauldron def if user is player, itemstack overwise.

View File

@ -1,5 +1,59 @@
local has_doc = minetest.get_modpath(minetest.get_current_modname())
mcl_cauldrons.registered_cauldrons = {} mcl_cauldrons.registered_cauldrons = {}
function mcl_cauldrons.register_cauldron_type(def)
for water_level = 1,3 do
local id = "mcl_cauldrons:cauldron_"..def.name.."_"..water_level
mcl_cauldrons.registered_cauldrons[id] = def
minetest.register_node(id, {
description = string.format(def.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 = {
"("..def.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 has_doc then
doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", id)
end
end
end
function mcl_cauldrons.is_cauldron(name) function mcl_cauldrons.is_cauldron(name)
return minetest.get_item_group(name, "cauldron") ~= 0 return minetest.get_item_group(name, "cauldron") ~= 0
end end
function mcl_cauldrons.set_cauldron_level(pos, type, level)
return minetest.set_node(pos, {name = mcl_cauldrons.get_cauldron_string(type, level)})
end
function mcl_cauldrons.get_cauldron_level(pos)
local nn = minetest.get_node(pos)
return minetest.get_item_group(nn.name, "cauldron")
end
function mcl_cauldrons.get_cauldron_string(type, level)
if mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_"..type.."_"..level] then
return "mcl_cauldrons:cauldron_"..type.."_"..level
elseif level == 0 then
return "mcl_cauldrons:cauldron"
else
minetest.log("warning", "[mcl_cauldrons] trying to get string from invalid cauldron params")
return "air"
end
end

View File

@ -21,15 +21,6 @@ local function give_item(user, itemstack)
return itemstack return itemstack
end end
function mcl_cauldrons.set_cauldron_level(pos, type, level)
return minetest.set_node(pos, {name = mcl_cauldrons.get_cauldron_string(type, level)})
end
function mcl_cauldrons.get_cauldron_level(pos)
local nn = minetest.get_node(pos)
return minetest.get_item_group(nn.name, "cauldron")
end
function mcl_cauldrons.add_cauldron_level(pos, type, number) function mcl_cauldrons.add_cauldron_level(pos, type, number)
local current = mcl_cauldrons.get_cauldron_level(pos) local current = mcl_cauldrons.get_cauldron_level(pos)
local number = current + number local number = current + number
@ -94,47 +85,3 @@ function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
return itemstack return itemstack
end end
end end
function mcl_cauldrons.get_cauldron_string(type, level)
if mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_"..type.."_"..level] then
return "mcl_cauldrons:cauldron_"..type.."_"..level
elseif level == 0 then
return "mcl_cauldrons:cauldron"
else
minetest.log("warning", "[mcl_cauldrons] trying to get string from invalid cauldron params")
return "air"
end
end
function mcl_cauldrons.register_cauldron_type(def)
for water_level = 1,3 do
local id = "mcl_cauldrons:cauldron_"..def.name.."_"..water_level
mcl_cauldrons.registered_cauldrons[id] = def
minetest.register_node(id, {
description = string.format(def.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 = {
"("..def.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