forked from VoxeLibre/VoxeLibre
Cauldron API, callback-based; changes to mcl_buckets and mcl_potions for interaction with water cauldron.
This commit is contained in:
parent
1b0b5fc733
commit
2775f89979
|
@ -93,6 +93,14 @@ function mcl_buckets.register_liquid(def)
|
|||
-- Check if pointing to a buildable node
|
||||
--local item = itemstack:get_name()
|
||||
|
||||
local mcl_into_cauldron = def._mcl_into_cauldron
|
||||
|
||||
if mcl_into_cauldron then
|
||||
local new_bucketname = mcl_into_cauldron(place_pos, user)
|
||||
if not new_bucketname then
|
||||
mcl_into_cauldron = nil
|
||||
end
|
||||
end
|
||||
if def.extra_check and def.extra_check(place_pos, user) == true and nodedef and nodedef.buildable_to then
|
||||
-- buildable; replace the node
|
||||
local pns = user:get_player_name()
|
||||
|
@ -104,6 +112,8 @@ function mcl_buckets.register_liquid(def)
|
|||
if mod_doc and doc.entry_exists("nodes", node_place) then
|
||||
doc.mark_entry_as_revealed(user:get_player_name(), "nodes", node_place)
|
||||
end
|
||||
elseif mcl_into_cauldron then
|
||||
-- already handled; skip default case, to inventory handling.
|
||||
else
|
||||
-- not buildable to; place the liquid above
|
||||
-- check if the node above can be replaced
|
||||
|
@ -201,6 +211,14 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
|
|||
-- Check if pointing to a liquid source
|
||||
local liquiddef = mcl_buckets.liquids[nn]
|
||||
local new_bucket
|
||||
local cauldron_stuff
|
||||
if mcl_cauldrons.is_cauldron(node) then
|
||||
if mcl_cauldrons.get_level(node, "cauldron_water") > 0 then
|
||||
cauldron_stuff = "cauldron_water"
|
||||
elseif mcl_cauldrons.get_level(node, "cauldron_river_water") > 0 then
|
||||
cauldron_stuff = "cauldron_river_water"
|
||||
end
|
||||
end
|
||||
if liquiddef ~= nil and liquiddef.itemname ~= nil and (nn == liquiddef.source_take) then
|
||||
|
||||
-- Fill bucket, but not in Creative Mode
|
||||
|
@ -218,8 +236,32 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
|
|||
doc.mark_entry_as_revealed(user:get_player_name(), "nodes", nn)
|
||||
end
|
||||
|
||||
elseif cauldron_stuff then
|
||||
-- Cauldron
|
||||
--[[
|
||||
elseif minetest.get_item_group(nn, "cauldron") then
|
||||
new_bucket = mcl_cauldrons.take_cauldron(pointed_thing.under, new_bucket, user)
|
||||
--]]
|
||||
local newnode
|
||||
newnode = mcl_cauldrons.drain_levels(node, mcl_cauldrons.BUCKETFUL, "cauldron_water")
|
||||
if node ~= newnode then
|
||||
-- take water.
|
||||
minetest.set_node(pointed_thing.under, newnode)
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
new_bucket = ItemStack({name = "mcl_buckets:bucket_water"})
|
||||
end
|
||||
sound_take("mcl_core:water_source", pointed_thing.under)
|
||||
else
|
||||
newnode = mcl_cauldrons.drain_levels(node, mcl_cauldrons.BUCKETFUL, "cauldron_river_water")
|
||||
if node ~= newnode then
|
||||
-- take river water.
|
||||
minetest.set_node(pointed_thing.under, newnode)
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
new_bucket = ItemStack({name = "mcl_buckets:bucket_river_water"})
|
||||
end
|
||||
sound_take("mcl_core:river_water_source", pointed_thing.under)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add liquid bucket and put it into inventory, if possible.
|
||||
|
@ -227,6 +269,27 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
|
|||
if minetest.is_creative_enabled(user:get_player_name()) then --TODO
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
||||
-- copied and edited from empty bucket code.
|
||||
if not minetest.is_creative_enabled(user:get_player_name()) then
|
||||
-- Add water bucket and put it into inventory, if possible.
|
||||
-- Drop water bucket otherwise.
|
||||
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
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
end,
|
||||
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
|
||||
-- Fill empty bucket with liquid or drop bucket if no liquid
|
||||
|
|
|
@ -65,12 +65,14 @@ if mod_mcl_core then
|
|||
local nn = minetest.get_node(pos).name
|
||||
-- Pour water into cauldron
|
||||
if minetest.get_item_group(nn, "cauldron") ~= 0 then
|
||||
--[[
|
||||
-- Put water into cauldron
|
||||
if nn ~= "mcl_cauldrons:cauldron_3" then
|
||||
mcl_cauldrons.set_cauldron_level(pos, "water", 3)
|
||||
end
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return false
|
||||
--]]
|
||||
-- Evaporate water if used in Nether (except on cauldron)
|
||||
else
|
||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
||||
|
@ -81,6 +83,27 @@ if mod_mcl_core then
|
|||
end
|
||||
end,
|
||||
groups = { water_bucket = 1 },
|
||||
_mcl_into_cauldron = function (pos, placer)
|
||||
local node = minetest.get_node(pos)
|
||||
if not mcl_cauldrons.is_cauldron(node) then
|
||||
return nil
|
||||
end
|
||||
local placer_name = ""
|
||||
if placer ~= nil then
|
||||
placer_name = placer:get_player_name()
|
||||
end
|
||||
if placer and minetest.is_protected(pos, placer_name) then
|
||||
minetest.record_protection_violation(pos, placer_name)
|
||||
return nil
|
||||
end
|
||||
local newnode = mcl_cauldrons.fill_levels(node, mcl_cauldrons.BUCKETFUL, "cauldron_water")
|
||||
if newnode ~= node then
|
||||
minetest.set_node(pos, newnode)
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return "mcl_buckets:bucket_water"
|
||||
end
|
||||
return nil
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -108,12 +131,14 @@ if mod_mclx_core then
|
|||
local nn = minetest.get_node(pos).name
|
||||
-- Pour into cauldron
|
||||
if minetest.get_item_group(nn, "cauldron") ~= 0 then
|
||||
--[[
|
||||
-- Put water into cauldron
|
||||
if nn ~= "mcl_cauldrons:cauldron_3r" then
|
||||
mcl_cauldrons.set_cauldron(pos, "river_water", 3)
|
||||
end
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return false
|
||||
--]]
|
||||
else
|
||||
-- Evaporate water if used in Nether (except on cauldron)
|
||||
local dim = mcl_worlds.pos_to_dimension(pos)
|
||||
|
@ -124,6 +149,27 @@ if mod_mclx_core then
|
|||
end
|
||||
end,
|
||||
groups = { water_bucket = 1 },
|
||||
_mcl_into_cauldron = function (pos, placer)
|
||||
local node = minetest.get_node(pos)
|
||||
if not mcl_cauldrons.is_cauldron(node) then
|
||||
return nil
|
||||
end
|
||||
local placer_name = ""
|
||||
if placer ~= nil then
|
||||
placer_name = placer:get_player_name()
|
||||
end
|
||||
if placer and minetest.is_protected(pos, placer_name) then
|
||||
minetest.record_protection_violation(pos, placer_name)
|
||||
return nil
|
||||
end
|
||||
local newnode = mcl_cauldrons.fill_levels(node, mcl_cauldrons.BUCKETFUL, "cauldron_river_water")
|
||||
if newnode ~= node then
|
||||
minetest.set_node(pos, newnode)
|
||||
sound_place("mcl_core:water_source", pos)
|
||||
return "mcl_buckets:bucket_river_water"
|
||||
end
|
||||
return nil
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -24,5 +24,93 @@ def can have these fields:
|
|||
* 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.
|
||||
## `mcl_cauldrons.registered_cauldrons`
|
||||
Table containing cauldron definitions, indexed by name.
|
||||
|
||||
|
||||
|
||||
Node definitions
|
||||
----------------
|
||||
|
||||
Extensions to the base node definition descriptor (as passed to `minetest.register_node()`) for cauldrons:
|
||||
|
||||
* `.groups.cauldron`: 1 - is a cauldron
|
||||
* `.groups.cauldron_filled`: number 0..3 - content level (0=empty, 3=full)
|
||||
* `.groups.cauldron_maximum`: number 1.. - maximum contents level
|
||||
* `.groups.cauldron_water`: 1 - contains water
|
||||
* `.groups.cauldron_river_water`: 1 - contains river water
|
||||
|
||||
* `.mcl_on_fill(node, amount)`: returns node { name, param1, param2 }
|
||||
* `.mcl_on_drain(node, amount)`: returns node { name, param1, param2 }
|
||||
|
||||
|
||||
### `mcl_cauldrons.register_cauldron_node(nodename, cauldron_def)`
|
||||
|
||||
|
||||
|
||||
Cauldron interactions
|
||||
---------------------
|
||||
|
||||
### `mcl_cauldrons.find_cauldron(substance, fill_level)`
|
||||
Returns table, { node\_name, node\_definition }, returns nil if no match.
|
||||
Find registered cauldron best matching substance and fill level.
|
||||
* `substance`: string, one of the groups keys qualifying the content (e.g. `"cauldron_water"`); empty string for empty cauldron.
|
||||
* `fill_level`: desired fill level of cauldron; `nil` for first/any match; 0 resolves to empty cauldron.
|
||||
|
||||
### `mcl_cauldrons.is_cauldron(node)`
|
||||
Returns boolean.
|
||||
Test is nodename describes a cauldron.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
|
||||
### `mcl_cauldrons.is_empty(node)`
|
||||
Returns boolean.
|
||||
Test cauldron is empty.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
|
||||
### `mcl_cauldrons.is_full(node)`
|
||||
Returns boolean.
|
||||
Test cauldron is full.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
|
||||
### `mcl_cauldrons.has_substance(node, substance)`
|
||||
Returns boolean.
|
||||
Test the content is a certain substance.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, one of the groups key qualifying the content (e.g. `"cauldron_water"`).
|
||||
|
||||
### `mcl_cauldrons.get_maximum(node, substance)`
|
||||
Returns number.
|
||||
Get the maximum number of levels for requested substance.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, group-key qualifying the content (e.g. `"cauldron_water"`); `nil` for any/do-not-care.
|
||||
|
||||
### `mcl_cauldrons.get_level(node, substance)`
|
||||
Returns number.
|
||||
Get the fill level of the requested substance.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, group-key qualifying the content (e.g. `"cauldron_water"`); `nil` for any/do-not-care.
|
||||
|
||||
### `mcl_cauldrons.set_level(node, fill_level, substance)`
|
||||
Returns node { name, param1, param2 }.
|
||||
Set the fill level of cauldron, with optional explicit substance.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, group-key of cauldron content; `nil` to preserve substance.
|
||||
|
||||
### `mcl_cauldrons.fill_levels(node, change_levels, substance)`
|
||||
Returns node { name, param1, param2 }.
|
||||
Increase levels in cauldron, constrained by game rules.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, group-key of cauldron content; `nil` to preserve substance.
|
||||
|
||||
### `mcl_cauldrons.drain_levels(nodename, change_levels, substance)`
|
||||
Returns node { name, param1, param2 }.
|
||||
Reduce levels in cauldron, constrained by game rules.
|
||||
* `node`: Minetest node { name, param1, param2 }
|
||||
* `substance`: string, group-key of cauldron content; `nil` to preserve substance.
|
||||
|
||||
### `mcl_cauldrons.register_cauldron_node(nodename, cauldron_definition, doc_alias)`
|
||||
Register cauldron's node defintion. Affects `mcl_cauldrons.registered_cauldrons` while ultimately ending up at `minetest.register_node`.
|
||||
* `nodename`: string - name to assign to registered node.
|
||||
* `cauldron_defintion`: table - node definition (expecting mcl\_cauldrons extensions).
|
||||
* `doc_alias`: string - documentation (in-game encyclopedia) entry associated with this definition.
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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)
|
||||
|
@ -29,7 +30,9 @@ local function give_item(user, original_item, itemstack)
|
|||
return itemstack
|
||||
end
|
||||
|
||||
--]]
|
||||
mcl_cauldrons.registered_cauldrons = {}
|
||||
--[[
|
||||
|
||||
function mcl_cauldrons.register_cauldron_type(def)
|
||||
for water_level = 1,3 do
|
||||
|
@ -156,4 +159,121 @@ function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
|
|||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------
|
||||
|
||||
|
||||
mcl_cauldrons.BUCKETFUL = 3
|
||||
mcl_cauldrons.BOTTLEFUL = 1
|
||||
|
||||
|
||||
function mcl_cauldrons.find_cauldron (substance, fill_level)
|
||||
if (substance == "") then
|
||||
fill_level = 0
|
||||
end
|
||||
for nodename, nodedef in pairs(mcl_cauldrons.registered_cauldrons) do
|
||||
local substantial = (substance == nil) or (nodedef.groups[substance] and (nodedef.groups[substance] > 0))
|
||||
local filling = (fill_level == nil) or (nodedef.groups.cauldron_filled == fill_level)
|
||||
if substantial and filling then
|
||||
return nodename, nodedef
|
||||
end
|
||||
end
|
||||
-- no match, use empty.
|
||||
local nodename = "mcl_cauldrons:cauldron"
|
||||
return nodename, mcl_cauldrons.registered_cauldrons[nodename]
|
||||
end
|
||||
|
||||
function mcl_cauldrons.is_cauldron (node)
|
||||
return (minetest.get_item_group(node.name, "cauldron"))
|
||||
end
|
||||
|
||||
function mcl_cauldrons.has_substance (node, substance)
|
||||
return (minetest.get_item_group(node.name, substance) > 0)
|
||||
end
|
||||
|
||||
function mcl_cauldrons.get_maximum (node, substance)
|
||||
local nodename
|
||||
if substance == nil then
|
||||
nodename = node.name
|
||||
else
|
||||
nodename = mcl_cauldrons.find_cauldron(substance, nil)
|
||||
end
|
||||
return minetest.get_item_group(nodename, "cauldron_maximum")
|
||||
end
|
||||
|
||||
function mcl_cauldrons.get_level (node, substance)
|
||||
if substance and (minetest.get_item_group(node.name, substance) == 0) then
|
||||
return 0
|
||||
end
|
||||
return minetest.get_item_group(node.name, "cauldron_filled")
|
||||
end
|
||||
|
||||
function mcl_cauldrons.is_empty (node)
|
||||
if not mcl_cauldrons.is_cauldron(node) then
|
||||
error("not a cauldron", node.name)
|
||||
end
|
||||
if minetest.get_item_group(node.name, "cauldron_filled") == 0 then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function mcl_cauldrons.is_full (node)
|
||||
local maximum = mcl_cauldrons.get_maximum(node)
|
||||
local current = mcl_cauldrons.get_level(node)
|
||||
return (current >= maximum)
|
||||
end
|
||||
|
||||
function mcl_cauldrons.set_level (node, fill_level, substance)
|
||||
local nodename, nodedef = mcl_cauldrons.find_cauldron(substance, fill_level)
|
||||
local newnode = { name = nodename, param1 = node.param1, param2 = node.param2 }
|
||||
return newnode
|
||||
end
|
||||
|
||||
function mcl_cauldrons.fill_levels (node, change_levels, substance)
|
||||
local nodedef = mcl_cauldrons.registered_cauldrons[node.name]
|
||||
local callback = nodedef.mcl_on_fill
|
||||
local newnode
|
||||
if callback then
|
||||
-- specific rules.
|
||||
newnode = callback(node, change_levels, substance)
|
||||
end
|
||||
if newnode == nil then
|
||||
-- revert changes.
|
||||
newnode = node
|
||||
end
|
||||
return newnode
|
||||
end
|
||||
|
||||
function mcl_cauldrons.drain_levels (node, change_levels, substance)
|
||||
local nodedef = mcl_cauldrons.registered_cauldrons[node.name]
|
||||
local callback = nodedef.mcl_on_drain
|
||||
local newnode
|
||||
if callback then
|
||||
-- specific rules.
|
||||
newnode = callback(node, change_levels, substance)
|
||||
end
|
||||
if newnode == nil then
|
||||
-- revert changes.
|
||||
newnode = node
|
||||
end
|
||||
return newnode
|
||||
end
|
||||
|
||||
|
||||
function mcl_cauldrons.register_cauldron_node (nodename, nodedef, doc_alias)
|
||||
mcl_cauldrons.registered_cauldrons[nodename] = nodedef
|
||||
minetest.register_node(nodename, nodedef)
|
||||
if doc_alias and has_doc then
|
||||
doc.add_entry_alias("nodes", doc_alias, "nodes", nodename)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,134 @@
|
|||
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
|
||||
|
||||
|
||||
local function merge_tables (a,b)
|
||||
local result = {}
|
||||
for k,v in pairs(a) do result[k]=v end
|
||||
for k,v in pairs(b) do result[k]=v end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-- Empty cauldron
|
||||
mcl_cauldrons.register_cauldron_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,
|
||||
|
||||
mcl_on_fill = function (node, change_levels, substance)
|
||||
-- base rules for cauldrons.
|
||||
if change_levels <= 0 then
|
||||
-- no change.
|
||||
return nil
|
||||
end
|
||||
local old_level = mcl_cauldrons.get_level(node)
|
||||
local whole, fraction = math.modf(change_levels)
|
||||
local new_level
|
||||
if fraction > 0 then
|
||||
if math.random() < fraction then
|
||||
whole = whole + 1
|
||||
end
|
||||
end
|
||||
if (substance and mcl_cauldrons.has_substance(node, substance)) or (substance == nil) then
|
||||
-- same substance, add more.
|
||||
new_level = old_level + whole
|
||||
else
|
||||
-- different substance, delete old content.
|
||||
new_level = whole
|
||||
end
|
||||
-- clamp 0 through 3 inclusive.
|
||||
new_level = math.max(0, math.min(new_level, 3))
|
||||
local newnode = mcl_cauldrons.set_level(node, new_level, substance)
|
||||
return newnode
|
||||
end,
|
||||
mcl_on_drain = function (node, change_levels, substance)
|
||||
-- base rules for cauldrons.
|
||||
if change_levels <= 0 then
|
||||
-- no change.
|
||||
return nil
|
||||
end
|
||||
if (substance and not mcl_cauldrons.has_substance(node, substance)) then
|
||||
-- different substance, cannot drain.
|
||||
return nil
|
||||
end
|
||||
local old_level = mcl_cauldrons.get_level(node)
|
||||
local whole, fraction = math.modf(change_levels)
|
||||
local new_level
|
||||
if fraction > 0 then
|
||||
if math.random() < fraction then
|
||||
whole = whole + 1
|
||||
end
|
||||
end
|
||||
if (whole > old_level) then
|
||||
-- insufficient amount, no change.
|
||||
return nil
|
||||
end
|
||||
-- same substance, drain.
|
||||
new_level = old_level - whole
|
||||
-- clamp 0 through 3 inclusive.
|
||||
new_level = math.max(0, math.min(new_level, 3))
|
||||
local newnode = mcl_cauldrons.set_level(node, new_level, substance)
|
||||
return newnode
|
||||
end,
|
||||
})
|
||||
|
||||
--[[
|
||||
mcl_cauldrons.register_cauldron_type({
|
||||
name = "water",
|
||||
bucket = "mcl_buckets:bucket_water",
|
||||
|
@ -7,11 +136,111 @@ mcl_cauldrons.register_cauldron_type({
|
|||
desc = S("Cauldron (%s/3 Water)"),
|
||||
texture = "default_water_source_animated.png"
|
||||
})
|
||||
--]]
|
||||
|
||||
-- water cauldron as extension of empty cauldron.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_1",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron"], {
|
||||
description = S("Cauldron (1/3 Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 1,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
||||
tiles = {
|
||||
"(default_water_source_animated.png^[verticalframe:16:0"..")^mcl_cauldrons_cauldron_top.png",
|
||||
"mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png",
|
||||
"mcl_cauldrons_cauldron_side.png"
|
||||
},
|
||||
drop = "mcl_cauldrons:cauldron",
|
||||
}))
|
||||
|
||||
-- water cauldron 2/3 as extension of 1/3.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_2",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_water_1"], {
|
||||
description = S("Cauldron (2/3 Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 2,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
||||
}))
|
||||
|
||||
-- water cauldron 3/3 as extension of 1/3.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_water_3",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_water_1"], {
|
||||
description = S("Cauldron (3/3 Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 3,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
||||
}))
|
||||
|
||||
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)
|
||||
-- river water cauldron as extension of empty cauldron.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_1",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron"], {
|
||||
description = S("Cauldron (1/3 River Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 1,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_river_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[1],
|
||||
tiles = {
|
||||
"(default_river_water_source_animated.png^[verticalframe:16:0"..")^mcl_cauldrons_cauldron_top.png",
|
||||
"mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png",
|
||||
"mcl_cauldrons_cauldron_side.png"
|
||||
},
|
||||
drop = "mcl_cauldrons:cauldron",
|
||||
}))
|
||||
-- water cauldron 2/3 as extension of 1/3.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_2",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_river_water_1"], {
|
||||
description = S("Cauldron (2/3 River Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 2,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_river_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[2],
|
||||
}))
|
||||
-- water cauldron 3/3 as extension of 1/3.
|
||||
mcl_cauldrons.register_cauldron_node("mcl_cauldrons:cauldron_river_water_3",
|
||||
merge_tables(mcl_cauldrons.registered_cauldrons["mcl_cauldrons:cauldron_river_water_1"], {
|
||||
description = S("Cauldron (3/3 River Water)"),
|
||||
groups = {
|
||||
pickaxey = 1,
|
||||
cauldron = 1,
|
||||
cauldron_filled = 3,
|
||||
cauldron_maximum = 3,
|
||||
cauldron_river_water = 1,
|
||||
},
|
||||
node_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
||||
collision_box = mcl_cauldrons.cauldron_nodeboxes[3],
|
||||
}))
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -40,9 +269,26 @@ minetest.register_abm({
|
|||
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
|
||||
end
|
||||
--]]
|
||||
|
||||
-- backwards compatibility
|
||||
local aliases = {
|
||||
-- key=old/legacy name; value=current name
|
||||
["mcl_cauldrons:cauldron_1"] = "mcl_cauldrons:cauldron_water_1",
|
||||
["mcl_cauldrons:cauldron_2"] = "mcl_cauldrons:cauldron_water_2",
|
||||
["mcl_cauldrons:cauldron_3"] = "mcl_cauldrons:cauldron_water_3",
|
||||
["mcl_cauldrons:cauldron_1r"] = "mcl_cauldrons:cauldron_river_water_1",
|
||||
["mcl_cauldrons:cauldron_2r"] = "mcl_cauldrons:cauldron_river_water_2",
|
||||
["mcl_cauldrons:cauldron_3r"] = "mcl_cauldrons:cauldron_river_water_3",
|
||||
}
|
||||
for legacy, current in pairs(aliases) do
|
||||
minetest.register_alias(legacy, current)
|
||||
end
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ for w=0,3 do
|
|||
end
|
||||
|
||||
-- Empty cauldron
|
||||
--[[
|
||||
minetest.register_node("mcl_cauldrons:cauldron", {
|
||||
description = S("Cauldron"),
|
||||
_tt_help = S("Stores water"),
|
||||
|
@ -60,4 +61,5 @@ minetest.register_node("mcl_cauldrons:cauldron", {
|
|||
sounds = mcl_sounds.node_sound_metal_defaults(),
|
||||
_mcl_hardness = 2,
|
||||
_mcl_blast_resistance = 2,
|
||||
})
|
||||
})
|
||||
--]]
|
||||
|
|
|
@ -40,6 +40,87 @@ minetest.register_craft({
|
|||
recipe = { "mcl_mushrooms:mushroom_brown", "mcl_core:sugar", "mcl_mobitems:spider_eye" },
|
||||
})
|
||||
|
||||
|
||||
local function take_from_cauldron (pos, node, itemstack, placer)
|
||||
local sounds = mcl_sounds.node_sound_metal_defaults() -- TODO: should come from declarative object
|
||||
-- check cauldron limits.
|
||||
local new_bottlename
|
||||
if mcl_cauldrons.get_level(node, "cauldron_water") > 0 then
|
||||
-- has water, try to take water.
|
||||
local newnode = mcl_cauldrons.drain_levels(node, mcl_cauldrons.BOTTLEFUL, "cauldron_water")
|
||||
if newnode ~= node then
|
||||
-- changes happening (success).
|
||||
minetest.set_node(pos, newnode)
|
||||
minetest.sound_play("mcl_potions_bottle_fill", {pos=pos, gain=0.5, max_hear_range=16}, true)
|
||||
new_bottlename = "mcl_potions:water"
|
||||
end
|
||||
end
|
||||
if new_bottlename then
|
||||
-- byproduct of draining cauldron.
|
||||
local new_bottle = ItemStack({name=new_bottlename})
|
||||
local inv = placer:get_inventory()
|
||||
if minetest.is_creative_enabled(placer:get_player_name()) then
|
||||
-- creative mode: get for free
|
||||
if not inv:contains_item("main", new_bottle) then
|
||||
inv:add_item("main", new_bottle)
|
||||
end
|
||||
else
|
||||
-- survival mode
|
||||
if inv:room_for_item("main", new_bottle) then
|
||||
itemstack:take_item()
|
||||
inv:add_item("main", new_bottle)
|
||||
else
|
||||
minetest.add_item(placer:get_pos(), new_bottle)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function give_to_cauldron (pos, node, itemstack, placer, substance)
|
||||
if substance == nil then
|
||||
return false
|
||||
end
|
||||
local sounds = mcl_sounds.node_sound_metal_defaults() -- TODO: should come from declarative object
|
||||
-- check cauldron limits.
|
||||
local new_bottlename
|
||||
local maximum = mcl_cauldrons.get_maximum(node, substance)
|
||||
local level = mcl_cauldrons.get_level(node, substance)
|
||||
local fit = maximum - level
|
||||
if fit > 0 then
|
||||
-- sufficiently low level, add.
|
||||
-- overwrites old content (old contents are lost).
|
||||
local newnode = mcl_cauldrons.fill_levels(node, mcl_cauldrons.BOTTLEFUL, substance)
|
||||
if node ~= new_node then
|
||||
-- change happened
|
||||
minetest.set_node(pos, newnode)
|
||||
minetest.sound_play("mcl_potions_bottle_pour", {pos=pos, gain=0.5, max_hear_range=16}, true)
|
||||
new_bottlename = "mcl_potions:glass_bottle"
|
||||
end
|
||||
end
|
||||
if new_bottlename then
|
||||
-- byproduct of filling cauldron.
|
||||
local new_bottle = ItemStack({name=new_bottlename})
|
||||
local inv = placer:get_inventory()
|
||||
if minetest.is_creative_enabled(placer:get_player_name()) then
|
||||
-- creative mode: get for free
|
||||
if not inv:contains_item("main", new_bottle) then
|
||||
inv:add_item("main", new_bottle)
|
||||
end
|
||||
else
|
||||
-- survival mode
|
||||
if inv:room_for_item("main", new_bottle) then
|
||||
itemstack:take_item()
|
||||
inv:add_item("main", new_bottle)
|
||||
else
|
||||
minetest.add_item(placer:get_pos(), new_bottle)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_craftitem("mcl_potions:glass_bottle", {
|
||||
description = S("Glass Bottle"),
|
||||
_tt_help = S("Liquid container"),
|
||||
|
@ -65,12 +146,17 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
|
|||
local get_water = false
|
||||
--local from_liquid_source = false
|
||||
local river_water = false
|
||||
local from_cauldron = false
|
||||
if mcl_cauldrons.is_cauldron(node) then
|
||||
from_cauldron = not mcl_cauldrons.is_empty(node)
|
||||
end
|
||||
if def and def.groups and def.groups.water and def.liquidtype == "source" then
|
||||
-- Water source
|
||||
get_water = true
|
||||
--from_liquid_source = true
|
||||
river_water = node.name == "mclx_core:river_water_source"
|
||||
-- Or reduce water level of cauldron by 1
|
||||
--[[
|
||||
elseif mcl_cauldrons.is_cauldron(node.name) then
|
||||
local pname = placer:get_player_name()
|
||||
if minetest.is_protected(pointed_thing.under, pname) then
|
||||
|
@ -78,6 +164,18 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
|
|||
return itemstack
|
||||
end
|
||||
mcl_cauldrons.take_small_cauldron(pointed_thing.under, itemstack, placer, {dug = "mcl_potions_bottle_fill"})
|
||||
--]]
|
||||
elseif from_cauldron then
|
||||
if mcl_cauldrons.get_level(node, "cauldron_water") > 0 then
|
||||
-- take bottle of water.
|
||||
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
|
||||
|
||||
take_from_cauldron(pointed_thing.under, node, itemstack, placer)
|
||||
end
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
|
@ -125,6 +223,7 @@ minetest.register_craftitem("mcl_potions:water", {
|
|||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local cauldron = fill_cauldron(node.name, "mcl_core:water_source")
|
||||
if cauldron then
|
||||
local pname = placer:get_player_name()
|
||||
|
@ -141,6 +240,17 @@ minetest.register_craftitem("mcl_potions:water", {
|
|||
return "mcl_potions:glass_bottle"
|
||||
end
|
||||
end
|
||||
--]]
|
||||
if mcl_cauldrons.is_cauldron(node) then
|
||||
-- apply water bottle to empty or water cauldron
|
||||
-- anything else, replace content.
|
||||
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
|
||||
give_to_cauldron(pointed_thing.under, node, itemstack, placer, "cauldron_water")
|
||||
end
|
||||
end
|
||||
|
||||
-- Drink the water by default
|
||||
|
@ -385,4 +495,5 @@ mcl_wip.register_wip_item("mcl_potions:night_vision_plus_splash")
|
|||
mcl_wip.register_wip_item("mcl_potions:night_vision_lingering")
|
||||
mcl_wip.register_wip_item("mcl_potions:night_vision_plus_lingering")
|
||||
mcl_wip.register_wip_item("mcl_potions:night_vision_arrow")
|
||||
mcl_wip.register_wip_item("mcl_potions:night_vision_plus_arrow")
|
||||
mcl_wip.register_wip_item("mcl_potions:night_vision_plus_arrow")
|
||||
|
||||
|
|
Loading…
Reference in New Issue