mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 05:43:43 +01:00
Brewing somewhat works with the new API
This commit is contained in:
parent
09be413e3f
commit
f60f50041d
@ -82,7 +82,7 @@ local function brewable(inv)
|
|||||||
|
|
||||||
for i=1,stand_size do
|
for i=1,stand_size do
|
||||||
|
|
||||||
bottle = inv:get_stack("stand", i):get_name()
|
bottle = inv:get_stack("stand", i)
|
||||||
alchemy = mcl_potions.get_alchemy(ingredient, bottle)
|
alchemy = mcl_potions.get_alchemy(ingredient, bottle)
|
||||||
|
|
||||||
if alchemy then
|
if alchemy then
|
||||||
|
@ -29,6 +29,7 @@ dofile(modpath .. "/splash.lua")
|
|||||||
dofile(modpath .. "/lingering.lua")
|
dofile(modpath .. "/lingering.lua")
|
||||||
dofile(modpath .. "/tipped_arrow.lua")
|
dofile(modpath .. "/tipped_arrow.lua")
|
||||||
dofile(modpath .. "/potions.lua")
|
dofile(modpath .. "/potions.lua")
|
||||||
|
local potions = mcl_potions.registered_potions
|
||||||
|
|
||||||
minetest.register_craftitem("mcl_potions:fermented_spider_eye", {
|
minetest.register_craftitem("mcl_potions:fermented_spider_eye", {
|
||||||
description = S("Fermented Spider Eye"),
|
description = S("Fermented Spider Eye"),
|
||||||
@ -370,97 +371,110 @@ local output_table = {
|
|||||||
["mcl_potions:awkward"] = awkward_table,
|
["mcl_potions:awkward"] = awkward_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local enhancement_table = {}
|
|
||||||
local extension_table = {}
|
|
||||||
local potions = {}
|
|
||||||
|
|
||||||
for i, potion in ipairs({"healing","harming","swiftness","slowness",
|
|
||||||
"leaping","poison","regeneration","invisibility","fire_resistance",
|
|
||||||
-- "weakness","strength",
|
|
||||||
"water_breathing","night_vision", "withering"}) do
|
|
||||||
|
|
||||||
table.insert(potions, potion)
|
|
||||||
|
|
||||||
if potion ~= "invisibility" and potion ~= "night_vision" and potion ~= "weakness" and potion ~= "water_breathing" and potion ~= "fire_resistance" then
|
|
||||||
enhancement_table["mcl_potions:"..potion] = "mcl_potions:"..potion.."_2"
|
|
||||||
enhancement_table["mcl_potions:"..potion.."_splash"] = "mcl_potions:"..potion.."_2_splash"
|
|
||||||
table.insert(potions, potion.."_2")
|
|
||||||
end
|
|
||||||
|
|
||||||
if potion ~= "healing" and potion ~= "harming" then
|
|
||||||
extension_table["mcl_potions:"..potion.."_splash"] = "mcl_potions:"..potion.."_plus_splash"
|
|
||||||
extension_table["mcl_potions:"..potion] = "mcl_potions:"..potion.."_plus"
|
|
||||||
table.insert(potions, potion.."_plus")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, potion in ipairs({"awkward", "mundane", "thick", "water"}) do
|
|
||||||
table.insert(potions, potion)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local inversion_table = {
|
local inversion_table = {
|
||||||
["mcl_potions:healing"] = "mcl_potions:harming",
|
["mcl_potions:healing"] = "mcl_potions:harming",
|
||||||
["mcl_potions:healing_2"] = "mcl_potions:harming_2",
|
|
||||||
["mcl_potions:swiftness"] = "mcl_potions:slowness",
|
["mcl_potions:swiftness"] = "mcl_potions:slowness",
|
||||||
["mcl_potions:swiftness_plus"] = "mcl_potions:slowness_plus",
|
|
||||||
["mcl_potions:leaping"] = "mcl_potions:slowness",
|
["mcl_potions:leaping"] = "mcl_potions:slowness",
|
||||||
["mcl_potions:leaping_plus"] = "mcl_potions:slowness_plus",
|
|
||||||
["mcl_potions:night_vision"] = "mcl_potions:invisibility",
|
["mcl_potions:night_vision"] = "mcl_potions:invisibility",
|
||||||
["mcl_potions:night_vision_plus"] = "mcl_potions:invisibility_plus",
|
|
||||||
["mcl_potions:poison"] = "mcl_potions:harming",
|
["mcl_potions:poison"] = "mcl_potions:harming",
|
||||||
["mcl_potions:poison_2"] = "mcl_potions:harming_2",
|
-- ["mcl_potions:healing_splash"] = "mcl_potions:harming_splash",
|
||||||
["mcl_potions:healing_splash"] = "mcl_potions:harming_splash",
|
-- ["mcl_potions:swiftness_splash"] = "mcl_potions:slowness_splash",
|
||||||
["mcl_potions:healing_2_splash"] = "mcl_potions:harming_2_splash",
|
-- ["mcl_potions:leaping_splash"] = "mcl_potions:slowness_splash",
|
||||||
["mcl_potions:swiftness_splash"] = "mcl_potions:slowness_splash",
|
-- ["mcl_potions:night_vision_splash"] = "mcl_potions:invisibility_splash",
|
||||||
["mcl_potions:swiftness_plus_splash"] = "mcl_potions:slowness_plus_splash",
|
-- ["mcl_potions:poison_splash"] = "mcl_potions:harming_splash",
|
||||||
["mcl_potions:leaping_splash"] = "mcl_potions:slowness_splash",
|
|
||||||
["mcl_potions:leaping_plus_splash"] = "mcl_potions:slowness_plus_splash",
|
|
||||||
["mcl_potions:night_vision_splash"] = "mcl_potions:invisibility_splash",
|
|
||||||
["mcl_potions:night_vision_plus_splash"] = "mcl_potions:invisibility_plus_splash",
|
|
||||||
["mcl_potions:poison_splash"] = "mcl_potions:harming_splash",
|
|
||||||
["mcl_potions:poison_2_splash"] = "mcl_potions:harming_2_splash",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local splash_table = {}
|
local splash_table = {}
|
||||||
local lingering_table = {}
|
local lingering_table = {}
|
||||||
|
|
||||||
for i, potion in ipairs(potions) do
|
for potion, def in pairs(potions) do
|
||||||
splash_table["mcl_potions:"..potion] = "mcl_potions:"..potion.."_splash"
|
if def.has_splash then
|
||||||
lingering_table["mcl_potions:"..potion.."_splash"] = "mcl_potions:"..potion.."_lingering"
|
splash_table[potion] = potion.."_splash"
|
||||||
|
end
|
||||||
|
if def.has_lingering then
|
||||||
|
lingering_table[potion.."_splash"] = potion.."_lingering"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local mod_table = {
|
local mod_table = {
|
||||||
["mesecons:wire_00000000_off"] = extension_table,
|
|
||||||
["mcl_potions:fermented_spider_eye"] = inversion_table,
|
["mcl_potions:fermented_spider_eye"] = inversion_table,
|
||||||
["mcl_nether:glowstone_dust"] = enhancement_table,
|
|
||||||
["mcl_mobitems:gunpowder"] = splash_table,
|
["mcl_mobitems:gunpowder"] = splash_table,
|
||||||
["mcl_potions:dragon_breath"] = lingering_table,
|
["mcl_potions:dragon_breath"] = lingering_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Compare two ingredients for compatable alchemy
|
local function extend_dur(potionstack)
|
||||||
|
local def = potions[potionstack:get_name()]
|
||||||
|
if not def then return false end -- somehow, it initially always fails
|
||||||
|
if not def.has_plus then return false end -- bail out if can't be extended
|
||||||
|
local potionstack = ItemStack(potionstack)
|
||||||
|
local meta = potionstack:get_meta()
|
||||||
|
local potent = meta:get_int("mcl_potions:potion_potent")
|
||||||
|
local plus = meta:get_int("mcl_potions:potion_plus")
|
||||||
|
if plus == 0 then
|
||||||
|
if potent ~= 0 then
|
||||||
|
meta:set_int("mcl_potions:potion_potent", 0)
|
||||||
|
end
|
||||||
|
meta:set_int("mcl_potions:potion_plus", def._default_extend_level)
|
||||||
|
tt.reload_itemstack_description(potionstack)
|
||||||
|
return potionstack
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function enhance_pow(potionstack)
|
||||||
|
local def = potions[potionstack:get_name()]
|
||||||
|
if not def then return false end -- somehow, it initially always fails
|
||||||
|
if not def.has_potent then return false end -- bail out if has no potent variant
|
||||||
|
local potionstack = ItemStack(potionstack)
|
||||||
|
local meta = potionstack:get_meta()
|
||||||
|
local potent = meta:get_int("mcl_potions:potion_potent")
|
||||||
|
local plus = meta:get_int("mcl_potions:potion_plus")
|
||||||
|
if potent == 0 then
|
||||||
|
if plus ~= 0 then
|
||||||
|
meta:set_int("mcl_potions:potion_plus", 0)
|
||||||
|
end
|
||||||
|
meta:set_int("mcl_potions:potion_potent", def._default_potent_level-1)
|
||||||
|
tt.reload_itemstack_description(potionstack)
|
||||||
|
return potionstack
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local meta_mod_table = {
|
||||||
|
["mesecons:wire_00000000_off"] = extend_dur,
|
||||||
|
["mcl_nether:glowstone_dust"] = enhance_pow,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Find an alchemical recipe for given ingredient and potion
|
||||||
|
-- returns outcome
|
||||||
function mcl_potions.get_alchemy(ingr, pot)
|
function mcl_potions.get_alchemy(ingr, pot)
|
||||||
if output_table[pot] then
|
local brew_selector = output_table[pot:get_name()]
|
||||||
|
if brew_selector and brew_selector[ingr] then
|
||||||
|
local meta = pot:get_meta():to_table()
|
||||||
|
local alchemy = ItemStack(brew_selector[ingr])
|
||||||
|
local metaref = alchemy:get_meta()
|
||||||
|
metaref:from_table(meta)
|
||||||
|
tt.reload_itemstack_description(alchemy)
|
||||||
|
return alchemy
|
||||||
|
end
|
||||||
|
|
||||||
local brew_table = output_table[pot]
|
brew_selector = mod_table[ingr]
|
||||||
|
if brew_selector then
|
||||||
if brew_table[ingr] then
|
local brew = brew_selector[pot:get_name()]
|
||||||
return brew_table[ingr]
|
if brew then
|
||||||
|
local meta = pot:get_meta():to_table()
|
||||||
|
local alchemy = ItemStack(brew)
|
||||||
|
local metaref = alchemy:get_meta()
|
||||||
|
metaref:from_table(meta)
|
||||||
|
tt.reload_itemstack_description(alchemy)
|
||||||
|
return alchemy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if mod_table[ingr] then
|
if meta_mod_table[ingr] then
|
||||||
|
local brew_func = meta_mod_table[ingr]
|
||||||
local brew_table = mod_table[ingr]
|
if brew_func then return brew_func(pot) end
|
||||||
|
|
||||||
if brew_table[pot] then
|
|
||||||
return brew_table[pot]
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -493,10 +507,6 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
mcl_wip.register_wip_item("mcl_potions:night_vision")
|
mcl_wip.register_wip_item("mcl_potions:night_vision")
|
||||||
mcl_wip.register_wip_item("mcl_potions:night_vision_plus")
|
|
||||||
mcl_wip.register_wip_item("mcl_potions:night_vision_splash")
|
mcl_wip.register_wip_item("mcl_potions:night_vision_splash")
|
||||||
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_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_arrow")
|
||||||
mcl_wip.register_wip_item("mcl_potions:night_vision_plus_arrow")
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
|
mcl_potions.registered_potions = {}
|
||||||
|
|
||||||
local function potion_image(colorstring, opacity)
|
local function potion_image(colorstring, opacity)
|
||||||
if not opacity then
|
if not opacity then
|
||||||
opacity = 127
|
opacity = 127
|
||||||
@ -268,6 +270,7 @@ function mcl_potions.register_potion(def)
|
|||||||
sdef.on_splash = def.custom_splash_effect
|
sdef.on_splash = def.custom_splash_effect
|
||||||
if not def._effect_list then sdef.instant = true end
|
if not def._effect_list then sdef.instant = true end
|
||||||
mcl_potions.register_splash(name, splash_desc, color, sdef)
|
mcl_potions.register_splash(name, splash_desc, color, sdef)
|
||||||
|
pdef.has_splash = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.has_lingering or def.has_lingering == nil then
|
if def.has_lingering or def.has_lingering == nil then
|
||||||
@ -289,6 +292,7 @@ function mcl_potions.register_potion(def)
|
|||||||
ldef.while_lingering = def.custom_linger_effect
|
ldef.while_lingering = def.custom_linger_effect
|
||||||
if not def._effect_list then ldef.instant = true end
|
if not def._effect_list then ldef.instant = true end
|
||||||
mcl_potions.register_lingering(name, ling_desc, color, ldef)
|
mcl_potions.register_lingering(name, ling_desc, color, ldef)
|
||||||
|
pdef.has_lingering = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if def.has_arrow then
|
if def.has_arrow then
|
||||||
@ -316,7 +320,10 @@ function mcl_potions.register_potion(def)
|
|||||||
adef.custom_effect = def.custom_effect
|
adef.custom_effect = def.custom_effect
|
||||||
if not def._effect_list then adef.instant = true end
|
if not def._effect_list then adef.instant = true end
|
||||||
mcl_potions.register_arrow(name, arr_desc, color, adef)
|
mcl_potions.register_arrow(name, arr_desc, color, adef)
|
||||||
|
pdef.has_arrow = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mcl_potions.registered_potions[modname..":"..name] = pdef
|
||||||
end
|
end
|
||||||
|
|
||||||
mcl_potions.register_potion({
|
mcl_potions.register_potion({
|
||||||
|
Loading…
Reference in New Issue
Block a user