Add river water support for bottles and cauldrons

This commit is contained in:
Wuzzy 2017-11-30 19:27:57 +01:00
parent 99af7618ee
commit 142317c65a
5 changed files with 133 additions and 41 deletions

View File

@ -50,6 +50,7 @@ Please read <http://minecraft.gamepedia.com/Breaking> to learn how digging times
* `destroys_items=1`: If an item happens to be *inside* this node, the item will be destroyed
* `no_eat_delay=1`: Only for foodstuffs. When eating this, all eating delays are ignored.
* `can_eat_when_full=1`: Only for foodstuffs. This item can be eaten when the user has a full hunger bar
* `cauldron`: Cauldron. 1: Empty. 2-4: Water height
#### Footnotes

View File

@ -206,6 +206,13 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
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.settings:get_bool("creative_mode") then
new_bucket = ItemStack("mcl_buckets:bucket_river_water")
end
sound_take("mclx_core:river_water_source", pointed_thing.under)
end
-- Add liquid bucket and put it into inventory, if possible.
@ -260,14 +267,11 @@ if mod_mcl_core then
function(pos)
local nn = minetest.get_node(pos).name
-- Pour water into cauldron
if (nn == "mcl_cauldrons:cauldron" or
nn == "mcl_cauldrons:cauldron_1" or
nn == "mcl_cauldrons:cauldron_2") 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"})
sound_place("mcl_core:water_source", pos)
return false
elseif nn == "mcl_cauldrons:cauldron_3" then
end
sound_place("mcl_core:water_source", pos)
return false
-- Evaporate water if used in Nether (except on cauldron)
@ -295,20 +299,22 @@ if mod_mclx_core then
"Right-click on any block to empty the bucket and put a river water source on this spot.",
function(pos)
local nn = minetest.get_node(pos).name
-- TODO: Implement cauldron support.
-- Ignore cauldron
if (nn == "mcl_cauldrons:cauldron" or
nn == "mcl_cauldrons:cauldron_1" or
nn == "mcl_cauldrons:cauldron_2" or
nn == "mcl_cauldrons:cauldron_3") then
return false
-- Pour into cauldron
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"})
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)
if dim == "nether" then
minetest.sound_play("fire_extinguish_flame", {pos = pos, gain = 0.25, max_hear_distance = 16})
return false
end
end
end,
{ water_bucket = 1 }
)

View File

@ -1,3 +1,4 @@
mcl_core
mclx_core?
mcl_sounds
doc?

View File

@ -51,7 +51,7 @@ minetest.register_node("mcl_cauldrons:cauldron", {
paramtype = "light",
is_ground_content = false,
sunlight_propagates = true,
groups = {pickaxey=1, deco_block=1},
groups = {pickaxey=1, deco_block=1, cauldron=1},
node_box = cauldron_nodeboxes[0],
selection_box = { type = "regular" },
tiles = {
@ -65,20 +65,28 @@ minetest.register_node("mcl_cauldrons:cauldron", {
})
-- Template function for cauldrons with water
local register_filled_cauldron = function(water_level, description)
minetest.register_node("mcl_cauldrons:cauldron_"..water_level, {
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"
end
minetest.register_node(id, {
description = description,
_doc_items_create_entry = false,
drawtype = "nodebox",
paramtype = "light",
is_ground_content = false,
sunlight_propagates = true,
groups = {pickaxey=1, not_in_creative_inventory=1},
groups = {pickaxey=1, not_in_creative_inventory=1, cauldron=(1+water_level)},
node_box = cauldron_nodeboxes[water_level],
collision_box = cauldron_nodeboxes[0],
selection_box = { type = "regular" },
tiles = {
"(default_water_source_animated.png^[verticalframe:16:0)^mcl_cauldrons_cauldron_top.png",
"("..water_tex..")^mcl_cauldrons_cauldron_top.png",
"mcl_cauldrons_cauldron_inner.png^mcl_cauldrons_cauldron_bottom.png",
"mcl_cauldrons_cauldron_side.png"
},
@ -90,14 +98,20 @@ local register_filled_cauldron = function(water_level, description)
-- Add entry aliases for the Help
if minetest.get_modpath("doc") then
doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", "mcl_cauldrons:cauldron_"..water_level)
doc.add_entry_alias("nodes", "mcl_cauldrons:cauldron", "nodes", id)
end
end
-- Filled crauldrons (3 levels)
register_filled_cauldron(1, "Cauldron (One Third Full)")
register_filled_cauldron(2, "Cauldron (Two Thirds Full)")
register_filled_cauldron(3, "Cauldron (Full)")
-- Filled cauldrons (3 levels)
register_filled_cauldron(1, "Cauldron (1/3 Water)")
register_filled_cauldron(2, "Cauldron (2/3 Water)")
register_filled_cauldron(3, "Cauldron (3/3 Water)")
if minetest.get_modpath("mclx_core") then
register_filled_cauldron(1, "Cauldron (1/3 River Water)", true)
register_filled_cauldron(2, "Cauldron (2/3 River Water)", true)
register_filled_cauldron(3, "Cauldron (3/3 River Water)", true)
end
minetest.register_craft({
output = "mcl_cauldrons:cauldron",

View File

@ -37,11 +37,13 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
-- Try to fill glass bottle with water
local get_water = false
local river_water = false
if not def then
-- Unknown node: no-op
elseif def.groups and def.groups.water and def.liquidtype == "source" then
-- Water source
get_water = true
river_water = node.name == "mclx_core:river_water_source"
-- Or reduce water level of cauldron by 1
elseif node.name == "mcl_cauldrons:cauldron_3" then
get_water = true
@ -52,11 +54,28 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
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
if get_water then
-- Replace with water bottle, if possible, otherwise
-- place the water potion at a place where's space
local water_bottle = ItemStack("mcl_potions:potion_water")
local water_bottle
if river_water then
water_bottle = ItemStack("mcl_potions:potion_river_water")
else
water_bottle = ItemStack("mcl_potions:potion_water")
end
minetest.sound_play("mcl_potions_bottle_fill", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
if itemstack:get_count() == 1 then
return water_bottle
@ -93,6 +112,27 @@ local potion_image = function(colorstring, opacity)
return "mcl_potions_potion_bottle_drinkable.png^(mcl_potions_potion_overlay.png^[colorize:"..colorstring..":"..tostring(opacity)..")"
end
local cauldron_levels = {
-- start = { add water, add river water, take }
{ "", "_1", "_1r", nil },
{ "_1", "_2", "_2", "" },
{ "_2", "_3", "_3", "_1" },
{ "_1r", "_2", "_2r", "" },
{ "_2r", "_3r", "_3r", "_1r" },
}
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:potion_<NBT Potion Tag>”
minetest.register_craftitem("mcl_potions:potion_water", {
@ -102,7 +142,7 @@ minetest.register_craftitem("mcl_potions:potion_water", {
stack_max = 1,
inventory_image = potion_image("#0000FF"),
wield_image = potion_image("#0000FF"),
groups = {brewitem=1, food=3, can_eat_when_full=1},
groups = {brewitem=1, food=3, can_eat_when_full=1, water_bottle=1},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
@ -115,17 +155,10 @@ minetest.register_craftitem("mcl_potions:potion_water", {
end
end
local cauldron = fill_cauldron(node.name, "mcl_core:water_source")
if cauldron then
-- Increase water level of cauldron by 1
if node.name == "mcl_cauldrons:cauldron" then
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_1"})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
return "mcl_potions:glass_bottle"
elseif node.name == "mcl_cauldrons:cauldron_1" then
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_2"})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
return "mcl_potions:glass_bottle"
elseif node.name == "mcl_cauldrons:cauldron_2" then
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_3"})
minetest.set_node(pointed_thing.under, {name=cauldron})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
return "mcl_potions:glass_bottle"
end
@ -137,6 +170,43 @@ minetest.register_craftitem("mcl_potions:potion_water", {
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
})
minetest.register_craftitem("mcl_potions:potion_river_water", {
description = "River Water Bottle",
_doc_items_longdesc = "River water bottles can be used to brew potions and to fill cauldrons. Drinking it has no effect.",
_doc_items_usagehelp = "Wield it and rightclick to drink it. Rightclick a cauldron to put the river water into the cauldron.",
stack_max = 1,
inventory_image = potion_image("#0044FF"),
wield_image = potion_image("#0044FF"),
groups = {brewitem=1, food=3, can_eat_when_full=1, water_bottle=1},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
local def = minetest.registered_nodes[node.name]
-- Call on_rightclick if the pointed node defines it
if placer and not placer:get_player_control().sneak then
if def and def.on_rightclick then
return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end
end
local cauldron = fill_cauldron(node.name, "mclx_core:river_water_source")
if cauldron then
-- Increase water level of cauldron by 1
minetest.set_node(pointed_thing.under, {name=cauldron})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
return "mcl_potions:glass_bottle"
end
end
-- Drink the water by default
return minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, placer, pointed_thing)
end,
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
})
local how_to_drink = "To drink it, wield it, then rightclick."
minetest.register_craftitem("mcl_potions:potion_awkward", {