WIP API for mcl_cauldrons

This commit is contained in:
AFCMS 2021-03-18 19:18:35 +01:00
parent e68736a040
commit 5e5b3ebf75
2 changed files with 34 additions and 29 deletions

View File

@ -77,6 +77,10 @@ function mcl_cauldrons.get_cauldron_level(pos)
return minetest.get_item_group(nn.name, "cauldron")
end
function mcl_cauldrons.is_cauldron(name)
return minetest.get_item_group(nn.name, "cauldron") ~= 0
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
@ -96,6 +100,32 @@ function mcl_cauldrons.take_cauldron(pos, itemstack, user, sounds)
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 = 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
return ItemStack(mcl_cauldrons.registered_cauldrons[nn.name].bottle)
end
return itemstack
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
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
@ -112,12 +142,8 @@ function mcl_cauldrons.add_cauldron_level(pos, type, number)
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
return number
end
function mcl_cauldrons.register_cauldron_type(def)
@ -156,6 +182,7 @@ end
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"
})

View File

@ -75,35 +75,13 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
from_liquid_source = true
river_water = node.name == "mclx_core:river_water_source"
-- 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()
if minetest.is_protected(pointed_thing.under, pname) then
minetest.record_protection_violation(pointed_thing.under, pname)
return itemstack
end
if node.name == "mcl_cauldrons:cauldron_3" then
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
local itemstack = mcl_cauldrons.take_small_cauldron(pointed_thing.under, itemstack, placer, {dug = "mcl_potions_bottle_fill"})
if get_water then
local water_bottle
if river_water then