This commit is contained in:
AFCMS 2021-03-18 18:02:08 +01:00
parent 72149a2c56
commit e68736a040
3 changed files with 43 additions and 30 deletions

View File

@ -217,19 +217,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
end
elseif minetest.get_item_group(nn, "cauldron") then
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)
new_bucket = mcl_cauldrons.take_cauldron(pointed_thing.under, new_bucket, user)
end
-- Add liquid bucket and put it into inventory, if possible.

View File

@ -2,7 +2,12 @@
This mod add an API to add cauldrons to mcl.
## mcl_cauldrons.register_cauldron_type(name, desc, texture)
## 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

@ -40,7 +40,8 @@ for w=0,3 do
cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end
local cauldrons_list = {}
mcl_cauldrons.registered_cauldrons = {}
--local cauldrons_list = {}
-- Empty cauldron
minetest.register_node("mcl_cauldrons:cauldron", {
description = S("Cauldron"),
@ -66,44 +67,63 @@ minetest.register_node("mcl_cauldrons:cauldron", {
_mcl_blast_resistance = 2,
})
function mcl_cauldrons.set_cauldron(pos, type, level)
function mcl_cauldrons.set_cauldron_level(pos, type, level)
minetest.set_node(pos, {name = mcl_cauldrons.get_cauldron_string(type, level)})
return true
end
function mcl_cauldrons.take_cauldron(pos, itemstack, user)
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.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
return ItemStack("mcl_buckets:bucket_water")
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(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.get_cauldron_string(type, level)
if cauldrons_list["mcl_cauldrons:cauldron_"..type.."_"..level] then
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.add_cauldron_level(pos, number)
function mcl_cauldrons.add_cauldron_level(pos, type, number)
local nn = minetest.get_node(pos).name
if cauldrons_list[nn] and number >= 1 and number <= 3 then
local nb = minetest.get_item_group(nn, "cauldron_filled")
if nb > 3 then nb = 3 end
else
minetest.log("error", "[mcl_cauldrons] trying to add level to not cauldron node at "..minetest.serialize(pos))
end
local number = mcl_cauldrons.get_cauldron_level(pos)+number
if number > 4 then number = 4 end
if number < 1 then number = 1 end
--if
mcl_cauldrons.set_cauldron_level(pos, type, number)
--else
-- minetest.log("error", "[mcl_cauldrons] trying to add level to not cauldron node at "..minetest.serialize(pos))
--end
return
end
function mcl_cauldrons.register_cauldron_type(def)
for water_level = 1,3 do
local id = "mcl_cauldrons:cauldron_"..def.name.."_"..water_level
cauldrons_list[id] = true
mcl_cauldrons.registered_cauldrons[id] = def
minetest.register_node(id, {
description = string.format(def.desc, water_level),
_doc_items_create_entry = false,