Compare commits

...

38 Commits

Author SHA1 Message Date
AFCMS 1b0b5fc733 Merge branch 'master' into api-cauldrons 2021-05-27 09:10:19 +02:00
AFCMS 246ece7440 Merge branch 'master' into api-cauldrons 2021-05-19 00:20:08 +02:00
AFCMS 5c078b3d7b Merge branch 'master' into api-cauldrons 2021-05-04 10:29:34 +02:00
AFCMS 3fddffb942 Merge branch 'master' into api-cauldrons 2021-05-03 23:27:09 +02:00
AFCMS 225650904c Merge branch 'master' into api-cauldrons 2021-03-31 20:33:18 +02:00
AFCMS 1b144d507d Merge branch 'master' into api-cauldrons 2021-03-31 16:15:53 +02:00
AFCMS 738519f0a4 Merge branch 'master' into api-cauldrons 2021-03-30 22:28:33 +02:00
AFCMS d1ca012ea0 small API fix 2021-03-27 12:27:46 +01:00
AFCMS a18a2127c5 add helper function to give item in creative 2021-03-27 12:20:14 +01:00
AFCMS 7156afcd03 add helper functio nto give item 2021-03-27 12:16:08 +01:00
AFCMS e3b3e2343b fix crash 2021-03-27 12:08:00 +01:00
AFCMS 6f23351126 move every function in the right place 2021-03-27 12:06:52 +01:00
AFCMS a99619774d move more functions 2021-03-27 12:03:14 +01:00
AFCMS 989384f362 move is_cauldron to the right place 2021-03-27 11:57:07 +01:00
AFCMS 69da355f96 fix API design 2021-03-27 11:55:22 +01:00
AFCMS 297d4e707c WIP separate functions into different files 2021-03-27 11:52:54 +01:00
AFCMS b4033ddfc9 Merge branch 'master' into api-cauldrons 2021-03-27 11:35:24 +01:00
AFCMS c35c8a1713 Merge branch 'master' into api-cauldrons 2021-03-19 15:12:54 +01:00
AFCMS 64b49ba719 try to fix give function 2021-03-19 14:58:25 +01:00
AFCMS d00490c86f fix stupid crash 2021-03-19 14:27:57 +01:00
AFCMS 8c91d23eb8 fix give function 2021-03-19 14:26:43 +01:00
AFCMS 294cb3eb7d cleanup 2021-03-19 14:17:59 +01:00
AFCMS cf4d57e584 fix crash 2021-03-19 14:13:34 +01:00
AFCMS 890b95bb49 Merge branch 'master' into api-cauldrons 2021-03-19 13:39:17 +01:00
AFCMS 8611d27f1d init function 2021-03-19 10:23:22 +01:00
AFCMS 59892abf6d fix 2021-03-19 10:19:08 +01:00
AFCMS e69365f44d init give function 2021-03-19 10:18:15 +01:00
AFCMS aa0c7bd2cf Merge branch 'master' into api-cauldrons 2021-03-19 10:16:27 +01:00
AFCMS 2b73c16c69 fix doc 2 2021-03-18 20:58:06 +01:00
AFCMS 36f479b2ec cleanup 2021-03-18 20:52:24 +01:00
AFCMS 717a18ef16 fix doc 2021-03-18 20:50:37 +01:00
AFCMS 9b0c87dabc fixes 2021-03-18 19:43:25 +01:00
AFCMS 3c83898095 quick fix 2021-03-18 19:30:53 +01:00
AFCMS 6ebae965f6 fixes 2021-03-18 19:27:43 +01:00
AFCMS 5e5b3ebf75 WIP API for mcl_cauldrons 2021-03-18 19:18:35 +01:00
AFCMS e68736a040 WIP 2021-03-18 18:02:08 +01:00
AFCMS 72149a2c56 part 2 2021-03-18 09:43:31 +01:00
AFCMS 182e825303 init mcl_cauldrons API (WIP) 2021-03-17 21:47:27 +01:00
10 changed files with 314 additions and 247 deletions

View File

@ -211,47 +211,22 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
end end
end end
minetest.add_node(pointed_thing.under, {name="air"}) minetest.set_node(pointed_thing.under, {name="air"})
sound_take(nn, pointed_thing.under) sound_take(nn, pointed_thing.under)
if mod_doc and doc.entry_exists("nodes", nn) then if mod_doc and doc.entry_exists("nodes", nn) then
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
-- Take water out of full cauldron new_bucket = mcl_cauldrons.take_cauldron(pointed_thing.under, new_bucket, user)
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
if not minetest.is_creative_enabled(user:get_player_name()) then
new_bucket = ItemStack("mcl_buckets:bucket_water")
end
sound_take("mcl_core:water_source", pointed_thing.under)
elseif nn == "mcl_cauldrons:cauldron_3r" then
-- Take river 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
new_bucket = ItemStack("mcl_buckets:bucket_river_water")
end
sound_take("mclx_core:river_water_source", pointed_thing.under)
end end
-- Add liquid bucket and put it into inventory, if possible. -- Add liquid bucket and put it into inventory, if possible.
-- Drop new bucket otherwise. -- Drop new bucket otherwise.
if new_bucket then if minetest.is_creative_enabled(user:get_player_name()) then --TODO
if itemstack:get_count() == 1 then
return new_bucket
else
local inv = user:get_inventory()
if inv:room_for_item("main", new_bucket) then
inv:add_item("main", new_bucket)
else
minetest.add_item(user:get_pos(), new_bucket)
end
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:take_item() itemstack:take_item()
end end
return itemstack
end
end
end, end,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir) _on_dispense = function(stack, pos, droppos, dropnode, dropdir)
-- Fill empty bucket with liquid or drop bucket if no liquid -- Fill empty bucket with liquid or drop bucket if no liquid

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

@ -67,7 +67,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_level(pos, "water", 3)
end end
sound_place("mcl_core:water_source", pos) sound_place("mcl_core:water_source", pos)
return false return false
@ -110,7 +110,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,28 @@
# mcl_cauldrons
This mod add an API to add cauldrons to mcl.
## mcl_cauldrons.is_cauldron(name)
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)
empty cauldron at `pos`
return `bucket` field of the cauldron def if user is player, itemstack overwise.
* pos: position of the cauldron
* itemstack: will be return if `bucket` field isn't defined in cauldron def or user is nil or not player.
* user: player who takes cauldron
* sounds: sounds table. If not nil, dug sound will be played.
## mcl_cauldrons.register_cauldron_type(def)
def can have these fields:
* name: name of the liquid e.g: "water"
* bucket: string of the bucket item. can be nil. e.g: "mcl_buckets:bucket_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"
## mcl_cauldrons.registered_cauldrons
Table containing chauldrons def indexed by name.

View File

@ -0,0 +1,159 @@
local has_doc = minetest.get_modpath(minetest.get_current_modname())
local function survival_give(inv, original_item, itemstack)
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
return original_item:take_item()
else
minetest.add_item(user:get_pos(), itemstack)
return original_item
end
end
local function creative_give(inv, original_item, itemstack)
if not inv:contains_item("main", itemstack) then
inv:add_item("main", itemstack)
return original_item
end
end
local function give_item(user, original_item, itemstack)
local inv = user:get_inventory()
if inv then
if minetest.is_creative_enabled(user:get_player_name()) then
creative_give(inv, original_item, itemstack)
else
survival_give(inv, original_item, itemstack)
end
end
return itemstack
end
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 = mcl_cauldrons.cauldron_nodeboxes[water_level],
collision_box = mcl_cauldrons.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)
return minetest.get_item_group(name, "cauldron") ~= 0
end
-------------------------------------
--Functions to get/set cauldron level
-------------------------------------
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.set_cauldron_level(pos, type, level)
return minetest.set_node(pos, {name = mcl_cauldrons.get_cauldron_string(type, level)})
end
function mcl_cauldrons.add_cauldron_level(pos, type, number)
local current = mcl_cauldrons.get_cauldron_level(pos)
local number = current + number
if number > 4 then number = 4 end
if number < 1 then number = 1 end
mcl_cauldrons.set_cauldron_level(pos, type, number)
return number, not current == number
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
----------------------------
--Functions to take cauldron
----------------------------
function mcl_cauldrons.take_cauldron(pos, itemstack, user, sounds)
local nn = minetest.get_node(pos)
if mcl_cauldrons.registered_cauldrons[nn.name] and mcl_cauldrons.registered_cauldrons[nn.name].bucket then
if user and not minetest.is_creative_enabled(user:get_player_name()) then
minetest.set_node(pos, {name="mcl_cauldrons:cauldron"})
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
return give_item(user, original, ItemStack(mcl_cauldrons.registered_cauldrons[nn.name].bucket))
else
minetest.set_node(pos, {name="mcl_cauldrons:cauldron"})
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
return itemstack
end
else
minetest.set_node(pos, {name="mcl_cauldrons:cauldron"})
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
return itemstack
end
end
function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
local nn = minetest.get_node(pos)
if mcl_cauldrons.registered_cauldrons[nn.name] and mcl_cauldrons.registered_cauldrons[nn.name].bottle then
if user and not minetest.is_creative_enabled(user:get_player_name()) then
local number, changed = mcl_cauldrons.add_cauldron_level(pos, mcl_cauldrons.registered_cauldrons[nn.name].name, -1)
if changed then
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
local item_name = mcl_cauldrons.registered_cauldrons[nn.name].bottle
local inv = placer:get_inventory()
minetest.sound_play("mcl_potions_bottle_fill", {pos=pointed_thing.under, gain=0.5, max_hear_range=16}, true)
if minetest.is_creative_enabled(placer:get_player_name()) then
-- Don't replace empty bottle in creative for convenience reasons
if not inv:contains_item("main", item_name) then
inv:add_item("main", item_name)
end
elseif itemstack:get_count() == 1 then
return item_name
else
return give_item(user, ItemStack(mcl_cauldrons.registered_cauldrons[nn.name].bucket))
end
end
else
local number = mcl_cauldrons.add_cauldron_level(pos, mcl_cauldrons.registered_cauldrons[nn.name].name, -1)
if number ~= 0 then
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
end
return itemstack
end
else
local number = mcl_cauldrons.add_cauldron_level(pos, mcl_cauldrons.registered_cauldrons[nn.name].name, -1)
if number ~= 0 then
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
end
return itemstack
end
end

View File

@ -1,143 +1,9 @@
local S = minetest.get_translator("mcl_cauldron") local S = minetest.get_translator("mcl_cauldron")
local modpath = minetest.get_modpath(minetest.get_current_modname())
mcl_cauldrons = {}
-- Cauldron mod, adds cauldrons. -- Cauldron mod, adds cauldrons.
-- TODO: Extinguish fire of burning entities dofile(modpath.."/utils.lua")
dofile(modpath.."/api.lua")
-- Convenience function because the cauldron nodeboxes are very similar dofile(modpath.."/register.lua")
local create_cauldron_nodebox = function(water_level)
local floor_y
if water_level == 0 then -- empty
floor_y = -0.1875
elseif water_level == 1 then -- 1/3 filled
floor_y = 1/16
elseif water_level == 2 then -- 2/3 filled
floor_y = 4/16
elseif water_level == 3 then -- full
floor_y = 7/16
end
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
local cauldron_nodeboxes = {}
for w=0,3 do
cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end
-- Empty cauldron
minetest.register_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 bucket 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 = 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,
})
-- Template function for cauldrons with water
local register_filled_cauldron = function(water_level, description, river_water)
local id = "mcl_cauldrons:cauldron_"..water_level
local water_tex
if river_water then
id = id .. "r"
water_tex = "default_river_water_source_animated.png^[verticalframe:16:0"
else
water_tex = "default_water_source_animated.png^[verticalframe:16:0"
end
minetest.register_node(id, {
description = description,
_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 = {
"("..water_tex..")^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
-- 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)"))
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)
end
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)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.4)) do
if mcl_burning.is_burning(obj) then
mcl_burning.extinguish(obj)
local new_group = minetest.get_item_group(node.name, "cauldron_filled") - 1
minetest.swap_node(pos, {name = "mcl_cauldrons:cauldron" .. (new_group == 0 and "" or "_" .. new_group)})
break
end
end
end
})

View File

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

View File

@ -0,0 +1,48 @@
local S = minetest.get_translator(minetest.get_current_modname())
mcl_cauldrons.register_cauldron_type({
name = "water",
bucket = "mcl_buckets:bucket_water",
bottle = "mcl_potions:water",
desc = S("Cauldron (%s/3 Water)"),
texture = "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)
end
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)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.4)) do
if mcl_burning.is_burning(obj) then
mcl_burning.extinguish(obj)
local new_group = minetest.get_item_group(node.name, "cauldron_filled") - 1
minetest.swap_node(pos, {name = "mcl_cauldrons:cauldron" .. (new_group == 0 and "" or "_" .. new_group)})
break
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

@ -0,0 +1,63 @@
local S = minetest.get_translator(minetest.get_current_modname())
-- Convenience function because the cauldron nodeboxes are very similar
local create_cauldron_nodebox = function(water_level)
local floor_y
if water_level == 0 then -- empty
floor_y = -0.1875
elseif water_level == 1 then -- 1/3 filled
floor_y = 1/16
elseif water_level == 2 then -- 2/3 filled
floor_y = 4/16
elseif water_level == 3 then -- full
floor_y = 7/16
end
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
mcl_cauldrons.cauldron_nodeboxes = {}
for w=0,3 do
mcl_cauldrons.cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end
-- Empty cauldron
minetest.register_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,
})

View File

@ -71,61 +71,13 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
--from_liquid_source = true --from_liquid_source = true
river_water = node.name == "mclx_core:river_water_source" river_water = node.name == "mclx_core:river_water_source"
-- Or reduce water level of cauldron by 1 -- Or reduce water level of cauldron by 1
elseif string.sub(node.name, 1, 14) == "mcl_cauldrons:" then elseif mcl_cauldrons.is_cauldron(node.name) then
local pname = placer:get_player_name() local pname = placer:get_player_name()
if minetest.is_protected(pointed_thing.under, pname) then if minetest.is_protected(pointed_thing.under, pname) then
minetest.record_protection_violation(pointed_thing.under, pname) minetest.record_protection_violation(pointed_thing.under, pname)
return itemstack return itemstack
end end
if node.name == "mcl_cauldrons:cauldron_3" then mcl_cauldrons.take_small_cauldron(pointed_thing.under, itemstack, placer, {dug = "mcl_potions_bottle_fill"})
get_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_2"})
elseif node.name == "mcl_cauldrons:cauldron_2" then
get_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_1"})
elseif node.name == "mcl_cauldrons:cauldron_1" then
get_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
elseif node.name == "mcl_cauldrons:cauldron_3r" then
get_water = true
river_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_2r"})
elseif node.name == "mcl_cauldrons:cauldron_2r" then
get_water = true
river_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_1r"})
elseif node.name == "mcl_cauldrons:cauldron_1r" then
get_water = true
river_water = true
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
end
end
if get_water then
local water_bottle
if river_water then
water_bottle = ItemStack("mcl_potions:river_water")
else
water_bottle = ItemStack("mcl_potions:water")
end
-- Replace with water bottle, if possible, otherwise
-- place the water potion at a place where's space
local inv = placer:get_inventory()
minetest.sound_play("mcl_potions_bottle_fill", {pos=pointed_thing.under, gain=0.5, max_hear_range=16}, true)
if minetest.is_creative_enabled(placer:get_player_name()) then
-- Don't replace empty bottle in creative for convenience reasons
if not inv:contains_item("main", water_bottle) then
inv:add_item("main", water_bottle)
end
elseif itemstack:get_count() == 1 then
return water_bottle
else
if inv:room_for_item("main", water_bottle) then
inv:add_item("main", water_bottle)
else
minetest.add_item(placer:get_pos(), water_bottle)
end
itemstack:take_item()
end
end end
end end
return itemstack return itemstack
@ -150,31 +102,6 @@ local potion_image = function(colorstring, opacity)
return "mcl_potions_potion_overlay.png^[colorize:"..colorstring..":"..tostring(opacity).."^mcl_potions_potion_bottle.png" return "mcl_potions_potion_overlay.png^[colorize:"..colorstring..":"..tostring(opacity).."^mcl_potions_potion_bottle.png"
end end
-- Cauldron fill up rules:
-- Adding any water increases the water level by 1, preserving the current water type
local cauldron_levels = {
-- start = { add water, add river water }
{ "", "_1", "_1r" },
{ "_1", "_2", "_2" },
{ "_2", "_3", "_3" },
{ "_1r", "_2r", "_2r" },
{ "_2r", "_3r", "_3r" },
}
local fill_cauldron = function(cauldron, water_type)
local base = "mcl_cauldrons:cauldron"
for i=1, #cauldron_levels do
if cauldron == base .. cauldron_levels[i][1] then
if water_type == "mclx_core:river_water_source" then
return base .. cauldron_levels[i][3]
else
return base .. cauldron_levels[i][2]
end
end
end
end
-- Itemstring of potions is “mcl_potions:<NBT Potion Tag>” -- Itemstring of potions is “mcl_potions:<NBT Potion Tag>”
minetest.register_craftitem("mcl_potions:water", { minetest.register_craftitem("mcl_potions:water", {