Revert to master branch (roll back changes to mcl_potions).

This commit is contained in:
Phaethon H 2021-11-10 12:48:51 -08:00
parent a72359af4d
commit daa9354d32
1 changed files with 115 additions and 48 deletions

View File

@ -41,50 +41,6 @@ minetest.register_craft({
recipe = { "mcl_mushrooms:mushroom_brown", "mcl_core:sugar", "mcl_mobitems:spider_eye" },
})
local function is_cauldron_protected(pos, placer)
local pname = placer:get_player_name()
if minetest.is_protected(pos, pname) then
-- no take, no changing.
minetest.record_protection_violation(pos, pname)
return true
end
return false
end
-- exchange one count of `from_itemstack` for one count of `to_item_name`.
-- creative mode does not consume any items, but also does not provide more than one of `item_name`.
local function exchange_player_inventory(placer, from_itemstack, to_item_name)
local new_itemstack = ItemStack({name=to_item_name})
local inv = placer:get_inventory()
if minetest.is_creative_enabled(placer:get_player_name()) then
-- creative mode: have at most one.
if not inv:contains_item("main", new_itemstack) then
inv:add_item("main", new_itemstack)
end
else
-- survival mode
if from_itemstack:get_count() <= 1 then
-- swap in place.
return new_itemstack
else
-- take one.
from_itemstack:take_item()
-- add to inventory, or drop in place.
if inv:room_for_item("main", new_itemstack) then
-- add to inventory.
inv:add_item("main", new_itemstack)
else
-- drop in place.
minetest.add_item(placer:get_pos(), new_itemstack)
end
return from_itemstack
end
end
-- no change in inventory.
return from_itemstack
end
minetest.register_craftitem("mcl_potions:glass_bottle", {
description = S("Glass Bottle"),
_tt_help = S("Liquid container"),
@ -115,9 +71,62 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
get_water = true
--from_liquid_source = true
river_water = node.name == "mclx_core:river_water_source"
local new_bottlename = river_water and "mcl_potions:river_water" or "mcl_potions:water"
-- Or reduce water level of cauldron by 1
elseif string.sub(node.name, 1, 14) == "mcl_cauldrons:" 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)
return exchange_player_inventory(placer, itemstack, new_bottlename)
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
return itemstack
@ -142,6 +151,31 @@ local function potion_image(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", {
@ -164,6 +198,23 @@ minetest.register_craftitem("mcl_potions:water", {
return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end
end
local cauldron = fill_cauldron(node.name, "mcl_core:water_source")
if cauldron 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
-- 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}, true)
if minetest.is_creative_enabled(placer:get_player_name()) then
return itemstack
else
return "mcl_potions:glass_bottle"
end
end
end
-- Drink the water by default
@ -194,6 +245,23 @@ minetest.register_craftitem("mcl_potions:river_water", {
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
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
-- 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}, true)
if minetest.is_creative_enabled(placer:get_player_name()) then
return itemstack
else
return "mcl_potions:glass_bottle"
end
end
end
-- Drink the water by default
@ -390,5 +458,4 @@ 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")