Add river water support for bottles and cauldrons
This commit is contained in:
parent
99af7618ee
commit
142317c65a
5 changed files with 133 additions and 41 deletions
|
@ -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", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue