forked from VoxeLibre/VoxeLibre
Compare commits
21 Commits
master
...
api-cauldr
Author | SHA1 | Date |
---|---|---|
|
c35c8a1713 | |
|
64b49ba719 | |
|
d00490c86f | |
|
8c91d23eb8 | |
|
294cb3eb7d | |
|
cf4d57e584 | |
|
890b95bb49 | |
|
8611d27f1d | |
|
59892abf6d | |
|
e69365f44d | |
|
aa0c7bd2cf | |
|
2b73c16c69 | |
|
36f479b2ec | |
|
717a18ef16 | |
|
9b0c87dabc | |
|
3c83898095 | |
|
6ebae965f6 | |
|
5e5b3ebf75 | |
|
e68736a040 | |
|
72149a2c56 | |
|
182e825303 |
|
@ -209,47 +209,22 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
|
|||
new_bucket = ItemStack({name = liquiddef.itemname})
|
||||
end
|
||||
|
||||
minetest.add_node(pointed_thing.under, {name="air"})
|
||||
minetest.set_node(pointed_thing.under, {name="air"})
|
||||
sound_take(nn, pointed_thing.under)
|
||||
|
||||
if mod_doc and doc.entry_exists("nodes", nn) then
|
||||
doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn)
|
||||
end
|
||||
|
||||
elseif nn == "mcl_cauldrons:cauldron_3" then
|
||||
-- Take 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_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)
|
||||
elseif minetest.get_item_group(nn, "cauldron") then
|
||||
new_bucket = mcl_cauldrons.take_cauldron(pointed_thing.under, new_bucket, user)
|
||||
end
|
||||
|
||||
-- Add liquid bucket and put it into inventory, if possible.
|
||||
-- Drop new bucket otherwise.
|
||||
if new_bucket then
|
||||
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
|
||||
if minetest.is_creative_enabled(user:get_player_name()) then --TODO
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
end,
|
||||
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
|
||||
-- Fill empty bucket with liquid or drop bucket if no liquid
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name = mcl_buckets
|
||||
author = Kahrl
|
||||
description =
|
||||
depends = mcl_worlds
|
||||
depends = mcl_worlds, mcl_cauldrons
|
||||
optional_depends = mcl_core, mclx_core, doc
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ if mod_mcl_core then
|
|||
if minetest.get_item_group(nn, "cauldron") ~= 0 then
|
||||
-- Put water into cauldron
|
||||
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
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return false
|
||||
|
@ -104,7 +104,7 @@ if mod_mclx_core then
|
|||
if minetest.get_item_group(nn, "cauldron") ~= 0 then
|
||||
-- Put water into cauldron
|
||||
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
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return false
|
||||
|
|
|
@ -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.
|
|
@ -1,8 +1,31 @@
|
|||
local S = minetest.get_translator("mcl_cauldron")
|
||||
|
||||
mcl_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
|
||||
local create_cauldron_nodebox = function(water_level)
|
||||
|
@ -41,7 +64,8 @@ for w=0,3 do
|
|||
cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
|
||||
end
|
||||
|
||||
|
||||
mcl_cauldrons.registered_cauldrons = {}
|
||||
--local cauldrons_list = {}
|
||||
-- Empty cauldron
|
||||
minetest.register_node("mcl_cauldrons:cauldron", {
|
||||
description = S("Cauldron"),
|
||||
|
@ -67,18 +91,105 @@ minetest.register_node("mcl_cauldrons:cauldron", {
|
|||
_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"
|
||||
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.get_cauldron_level(pos)
|
||||
local nn = minetest.get_node(pos)
|
||||
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
|
||||
|
||||
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
|
||||
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 = description,
|
||||
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",
|
||||
|
@ -89,7 +200,7 @@ local register_filled_cauldron = function(water_level, description, river_water)
|
|||
collision_box = cauldron_nodeboxes[0],
|
||||
selection_box = { type = "regular" },
|
||||
tiles = {
|
||||
"("..water_tex..")^mcl_cauldrons_cauldron_top.png",
|
||||
"("..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"
|
||||
},
|
||||
|
@ -104,16 +215,20 @@ local register_filled_cauldron = function(water_level, description, river_water)
|
|||
doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", id)
|
||||
end
|
||||
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)"))
|
||||
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)
|
||||
--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({
|
||||
|
@ -141,3 +256,10 @@ minetest.register_abm({
|
|||
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
|
|
@ -1,3 +1,4 @@
|
|||
name = mcl_cauldrons
|
||||
description = Add cauldrons to mcl
|
||||
depends = mcl_core, mcl_sounds
|
||||
optional_depends = mclx_core, doc
|
||||
|
|
|
@ -75,61 +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
|
||||
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
|
||||
mcl_cauldrons.take_small_cauldron(pointed_thing.under, itemstack, placer, {dug = "mcl_potions_bottle_fill"})
|
||||
end
|
||||
end
|
||||
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"
|
||||
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>”
|
||||
|
||||
minetest.register_craftitem("mcl_potions:water", {
|
||||
|
|
Loading…
Reference in New Issue