Compare commits

...

21 Commits

Author SHA1 Message Date
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
7 changed files with 200 additions and 151 deletions

View File

@ -209,46 +209,21 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
new_bucket = ItemStack({name = liquiddef.itemname}) new_bucket = ItemStack({name = liquiddef.itemname})
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 itemstack:take_item()
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()
end
return itemstack
end
end end
end, end,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir) _on_dispense = function(stack, pos, droppos, dropnode, dropdir)

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

@ -61,7 +61,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
@ -104,7 +104,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,24 @@
# 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.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

@ -1,8 +1,31 @@
local S = minetest.get_translator("mcl_cauldron") local S = minetest.get_translator("mcl_cauldron")
mcl_cauldrons = {}
-- Cauldron mod, adds cauldrons. -- Cauldron mod, adds cauldrons.
-- TODO: Extinguish fire of burning entities local function give_item(user, itemstack)
local inv = user:get_inventory()
if inv then
--[[if false then --minetest.is_creative_enabled(user:get_player_name()) then
if inv:contains_item("main", itemstack) then
return false
else
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
end
else]]
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
--end
end
return itemstack
end
-- Convenience function because the cauldron nodeboxes are very similar -- Convenience function because the cauldron nodeboxes are very similar
local create_cauldron_nodebox = function(water_level) local create_cauldron_nodebox = function(water_level)
@ -41,7 +64,8 @@ for w=0,3 do
cauldron_nodeboxes[w] = create_cauldron_nodebox(w) cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end end
mcl_cauldrons.registered_cauldrons = {}
--local cauldrons_list = {}
-- Empty cauldron -- Empty cauldron
minetest.register_node("mcl_cauldrons:cauldron", { minetest.register_node("mcl_cauldrons:cauldron", {
description = S("Cauldron"), description = S("Cauldron"),
@ -67,53 +91,144 @@ minetest.register_node("mcl_cauldrons:cauldron", {
_mcl_blast_resistance = 2, _mcl_blast_resistance = 2,
}) })
-- Template function for cauldrons with water function mcl_cauldrons.set_cauldron_level(pos, type, level)
local register_filled_cauldron = function(water_level, description, river_water) return minetest.set_node(pos, {name = mcl_cauldrons.get_cauldron_string(type, level)})
local id = "mcl_cauldrons:cauldron_"..water_level end
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 function mcl_cauldrons.get_cauldron_level(pos)
if minetest.get_modpath("doc") then local nn = minetest.get_node(pos)
doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", id) return minetest.get_item_group(nn.name, "cauldron")
end
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
mcl_cauldrons.set_cauldron_level(pos, type, number)
return number
end
function mcl_cauldrons.is_cauldron(name)
return minetest.get_item_group(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
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, 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
end end
-- Filled cauldrons (3 levels) function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
register_filled_cauldron(1, S("Cauldron (1/3 Water)")) local nn = minetest.get_node(pos)
register_filled_cauldron(2, S("Cauldron (2/3 Water)")) if mcl_cauldrons.registered_cauldrons[nn.name] and mcl_cauldrons.registered_cauldrons[nn.name].bottle then
register_filled_cauldron(3, S("Cauldron (3/3 Water)")) 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
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
if inv:room_for_item("main", item_name) then
inv:add_item("main", item_name)
else
minetest.add_item(placer:get_pos(), item_name)
end
itemstack:take_item()
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
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
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 if minetest.get_modpath("mclx_core") then
register_filled_cauldron(1, S("Cauldron (1/3 River Water)"), true) --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(2, S("Cauldron (2/3 River Water)"), true)
register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true) --register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true)
end end
minetest.register_craft({ minetest.register_craft({
@ -141,3 +256,10 @@ minetest.register_abm({
end 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

@ -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

@ -75,61 +75,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
@ -154,31 +106,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", {