forked from VoxeLibre/VoxeLibre
281 lines
9.8 KiB
Lua
281 lines
9.8 KiB
Lua
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
|
-- Convenience function because the cauldron nodeboxes are very similar
|
|
local floors_table = {
|
|
[0]=-0.1875, -- empty
|
|
[1]=1/16, -- 1/3 filled
|
|
[2]=4/16, -- 2/3 filled
|
|
[3]=7/16, -- full
|
|
}
|
|
|
|
local create_cauldron_nodebox = function(water_level)
|
|
local floor_y = floors_table[water_level]
|
|
return {
|
|
type = "fixed",
|
|
fixed = {
|
|
{-0.5, -0.1875, -0.5, -0.375, 0.5, 0.5}, -- Left wall
|
|
{0.375, -0.1875, -0.5, 0.5, 0.5, 0.5}, -- Right wall
|
|
{-0.375, -0.1875, 0.375, 0.375, 0.5, 0.5}, -- Back wall
|
|
{-0.375, -0.1875, -0.5, 0.375, 0.5, -0.375}, -- Front wall
|
|
{-0.5, -0.3125, -0.5, 0.5, floor_y, 0.5}, -- Floor
|
|
{-0.5, -0.5, -0.5, -0.375, -0.3125, -0.25}, -- Left front foot, part 1
|
|
{-0.375, -0.5, -0.5, -0.25, -0.3125, -0.375}, -- Left front foot, part 2
|
|
{-0.5, -0.5, 0.25, -0.375, -0.3125, 0.5}, -- Left back foot, part 1
|
|
{-0.375, -0.5, 0.375, -0.25, -0.3125, 0.5}, -- Left back foot, part 2
|
|
{0.375, -0.5, 0.25, 0.5, -0.3125, 0.5}, -- Right back foot, part 1
|
|
{0.25, -0.5, 0.375, 0.375, -0.3125, 0.5}, -- Right back foot, part 2
|
|
{0.375, -0.5, -0.5, 0.5, -0.3125, -0.25}, -- Right front foot, part 1
|
|
{0.25, -0.5, -0.5, 0.375, -0.3125, -0.375}, -- Right front foot, part 2
|
|
}
|
|
}
|
|
end
|
|
|
|
-- Generate nodeboxes for cauldrons, (0=empty, 1=1/3 filled, 2=2/3 filled, 3=full)
|
|
mcl_cauldrons.cauldron_nodeboxes = {}
|
|
for w=0,3 do
|
|
mcl_cauldrons.cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
|
|
end
|
|
|
|
|
|
-- The normal Lua means of inheritance uses setmetatable.
|
|
-- For node definitions, minetest.register_node() breaks/overwrite the metatable for its own use.
|
|
-- This function copies in the "old" keys/values, to let them be overwritten by another (newer) table.
|
|
-- Nested tables are recursively merged/copied, so nested keys may be selectively overridden.
|
|
-- Modifying the returned table does not risk mangling the source/parent table.
|
|
-- This workaround happens to work as declarative objects do not change after instantiation.
|
|
local function merge_tables(a,b)
|
|
local result = {}
|
|
for k,v in pairs(a) do result[k]=v end
|
|
for k,v in pairs(b) do
|
|
if type(a[k]) == "table" then
|
|
-- recursive merge table (with copy).
|
|
result[k] = merge_tables(a[k], v)
|
|
else
|
|
result[k] = v
|
|
end
|
|
end
|
|
return result
|
|
end
|
|
|
|
|
|
function mcl_cauldrons.empty_cauldron_on_fill(node, change_levels, substance)
|
|
-- base rules for cauldrons.
|
|
if change_levels <= 0 then
|
|
-- no change.
|
|
return nil
|
|
end
|
|
local old_level = mcl_cauldrons.get_level(node)
|
|
local whole, fraction = math.modf(change_levels)
|
|
local new_level
|
|
if fraction > 0 then
|
|
if math.random() < fraction then
|
|
whole = whole + 1
|
|
end
|
|
end
|
|
if (substance and mcl_cauldrons.has_substance(node, substance)) or (substance == nil) then
|
|
-- same substance, add more.
|
|
new_level = old_level + whole
|
|
else
|
|
-- different substance, delete old content.
|
|
new_level = whole
|
|
end
|
|
-- clamp 0 through 3 inclusive.
|
|
new_level = math.max(0, math.min(new_level, 3))
|
|
local newnode = mcl_cauldrons.set_level(node, new_level, substance)
|
|
return newnode
|
|
end
|
|
|
|
function mcl_cauldrons.empty_cauldron_on_drain(node, change_levels, substance)
|
|
-- base rules for cauldrons.
|
|
if change_levels <= 0 then
|
|
-- no change.
|
|
return nil
|
|
end
|
|
if (substance and not mcl_cauldrons.has_substance(node, substance)) then
|
|
-- different substance, cannot drain.
|
|
return nil
|
|
end
|
|
local old_level = mcl_cauldrons.get_level(node)
|
|
local whole, fraction = math.modf(change_levels)
|
|
local new_level
|
|
if fraction > 0 then
|
|
if math.random() < fraction then
|
|
whole = whole + 1
|
|
end
|
|
end
|
|
if (whole > old_level) then
|
|
-- insufficient amount, no change.
|
|
return nil
|
|
end
|
|
-- same substance, drain.
|
|
new_level = old_level - whole
|
|
-- clamp 0 through 3 inclusive.
|
|
new_level = math.max(0, math.min(new_level, 3))
|
|
local newnode = mcl_cauldrons.set_level(node, new_level, substance)
|
|
return newnode
|
|
end
|
|
|
|
-- Empty cauldron
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron", {
|
|
description = S("Cauldron"),
|
|
_tt_help = S("Stores water"),
|
|
_doc_items_longdesc = S("Cauldrons are used to store water and slowly fill up under rain."),
|
|
_doc_items_usagehelp = S("Place a water pucket into the cauldron to fill it with water. Place an empty bucket on a full cauldron to retrieve the water. Place a water bottle into the cauldron to fill the cauldron to one third with water. Place a glass bottle in a cauldron with water to retrieve one third of the water."),
|
|
wield_image = "mcl_cauldrons_cauldron.png",
|
|
inventory_image = "mcl_cauldrons_cauldron.png",
|
|
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, deco_block=1, cauldron=1},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[0],
|
|
selection_box = { type = "regular" },
|
|
tiles = {
|
|
"mcl_cauldrons_cauldron_inner.png^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(),
|
|
_mcl_hardness = 2,
|
|
_mcl_blast_resistance = 2,
|
|
|
|
_mcl_on_fill = function(node, change_levels, substance)
|
|
return mcl_cauldrons.empty_cauldron_on_fill(node, change_levels, substance)
|
|
end,
|
|
_mcl_on_drain = function(node, change_levels, substance)
|
|
return mcl_cauldrons.empty_cauldron_on_drain(node, change_levels, substance)
|
|
end,
|
|
})
|
|
|
|
|
|
-- water cauldron as extension of empty cauldron.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_1",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron"], {
|
|
description = S("Cauldron (1/3 Water)"),
|
|
groups = {
|
|
pickaxey = 1,
|
|
cauldron = 1,
|
|
cauldron_filled = 1,
|
|
cauldron_maximum = 3,
|
|
cauldron_water = 1,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
|
collision_box = mcl_cauldrons.cauldron_nodeboxes[0],
|
|
tiles = {
|
|
"(default_water_source_animated.png^[verticalframe:16:0"..")^mcl_cauldrons_cauldron_top.png",
|
|
"mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png",
|
|
"mcl_cauldrons_cauldron_side.png"
|
|
},
|
|
drop = "mcl_cauldrons:cauldron",
|
|
}), "mcl_cauldrons:cauldron")
|
|
|
|
-- water cauldron 2/3 as extension of 1/3.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_2",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_water_1"], {
|
|
description = S("Cauldron (2/3 Water)"),
|
|
groups = {
|
|
cauldron_filled = 2,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
|
}), "mcl_cauldrons:cauldron")
|
|
|
|
-- water cauldron 3/3 as extension of 1/3.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_3",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_water_1"], {
|
|
description = S("Cauldron (3/3 Water)"),
|
|
groups = {
|
|
cauldron_filled = 3,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
|
}), "mcl_cauldrons:cauldron")
|
|
|
|
if minetest.get_modpath("mclx_core") then
|
|
-- river water cauldron as extension of empty cauldron.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_1",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron"], {
|
|
description = S("Cauldron (1/3 River Water)"),
|
|
groups = {
|
|
pickaxey = 1,
|
|
cauldron = 1,
|
|
cauldron_filled = 1,
|
|
cauldron_maximum = 3,
|
|
cauldron_river_water = 1,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
|
collision_box = mcl_cauldrons.cauldron_nodeboxes[0],
|
|
tiles = {
|
|
"(default_river_water_source_animated.png^[verticalframe:16:0"..")^mcl_cauldrons_cauldron_top.png",
|
|
"mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png",
|
|
"mcl_cauldrons_cauldron_side.png"
|
|
},
|
|
drop = "mcl_cauldrons:cauldron",
|
|
}), "mcl_cauldrons:cauldron")
|
|
-- water cauldron 2/3 as extension of 1/3.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_2",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_river_water_1"], {
|
|
description = S("Cauldron (2/3 River Water)"),
|
|
groups = {
|
|
cauldron_filled = 2,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
|
}), "mcl_cauldrons:cauldron")
|
|
-- water cauldron 3/3 as extension of 1/3.
|
|
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_3",
|
|
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_river_water_1"], {
|
|
description = S("Cauldron (3/3 River Water)"),
|
|
groups = {
|
|
cauldron_filled = 3,
|
|
},
|
|
node_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
|
}), "mcl_cauldrons:cauldron")
|
|
end
|
|
|
|
|
|
-- Crafting recipe: Cauldron
|
|
minetest.register_craft({
|
|
output = "mcl_cauldrons:cauldron",
|
|
recipe = {
|
|
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
|
|
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
|
|
{ "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" },
|
|
}
|
|
})
|
|
|
|
minetest.register_abm({
|
|
label = "cauldrons",
|
|
nodenames = {"group:cauldron_filled"},
|
|
interval = 0.5,
|
|
chance = 1,
|
|
action = function(pos, node)
|
|
local EXTINGUISHING_RADIUS = 0.4
|
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, EXTINGUISHING_RADIUS)) do
|
|
if mcl_burning.is_burning(obj) then
|
|
local newnode = mcl_cauldrons.drain_levels(node, 1, "cauldron_water")
|
|
if node ~= newnode then
|
|
-- extinguishing requires 1 level of water from cauldron.
|
|
minetest.swap_node(pos, newnode)
|
|
mcl_burning.extinguish(obj)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
})
|
|
|
|
|
|
-- backwards compatibility
|
|
local aliases = {
|
|
-- key=old/legacy name; value=current name
|
|
["mcl_cauldrons:cauldron_1"] = "mcl_cauldrons:cauldron_water_1",
|
|
["mcl_cauldrons:cauldron_2"] = "mcl_cauldrons:cauldron_water_2",
|
|
["mcl_cauldrons:cauldron_3"] = "mcl_cauldrons:cauldron_water_3",
|
|
["mcl_cauldrons:cauldron_1r"] = "mcl_cauldrons:cauldron_river_water_1",
|
|
["mcl_cauldrons:cauldron_2r"] = "mcl_cauldrons:cauldron_river_water_2",
|
|
["mcl_cauldrons:cauldron_3r"] = "mcl_cauldrons:cauldron_river_water_3",
|
|
}
|
|
for legacy, current in pairs(aliases) do
|
|
minetest.register_alias(legacy, current)
|
|
end
|
|
|