Move Splash potion generation into single call

This commit is contained in:
Brandon 2020-07-12 07:18:54 -04:00
parent 922a42756e
commit 8f079d11be
2 changed files with 225 additions and 190 deletions

View File

@ -33,19 +33,22 @@ local function register_potion(def)
return itemstack
end
local function get_tt(tt, effect, dur)
local _tt
if def.effect and def.is_dur then
_tt = (def.effect*100).."% | "..time_string(dur)
if effect and def.is_dur then
_tt = (effect*100).."% | "..time_string(dur)
if def.name == "poison" or def.name == "regeneration" then
_tt = "1/2 Heart/"..def.effect.."sec | "..time_string(dur)
_tt = "1/2 Heart/"..effect.."sec | "..time_string(dur)
end
else
_tt = def._tt or time_string(dur) or S("No effect")
_tt = tt or time_string(dur) or S("No effect")
end
return _tt
end
minetest.register_craftitem("mcl_potions:"..def.name, {
description = S(def.description),
_tt_help = _tt,
_tt_help = get_tt(def._tt, def.effect, dur),
_doc_items_longdesc = def._longdesc,
_doc_items_usagehelp = how_to_drink,
stack_max = 1,
@ -56,6 +59,23 @@ local function register_potion(def)
on_secondary_use = on_use,
})
local splash_dur = dur * mcl_potions.SPLASH_FACTOR
local potion_fun
if def.dur then
potion_fun = function(player, redx) def.on_use(player, def.effect, splash_dur*redx) end
else
potion_fun = function(player, redx) def.on_use(player, def.effect*redx, splash_dur) end
end
local splash_def = {
tt = get_tt(def._tt, def.effect, splash_dur),
potion_fun = potion_fun,
}
if def.color then
mcl_potions.register_splash(def.name, S("Splash "..def.description), def.color, splash_def)
end
if def.is_II then
local desc_mod = " II"
@ -78,16 +98,6 @@ local function register_potion(def)
desc_mod = " IV"
end
local _tt
if effect_II and def.is_dur then
_tt = (effect_II*100).."% | "..time_string(dur_2)
if def.name == "poison" or def.name == "regeneration" then
_tt = "1/2 Heart/"..effect_II.."sec | "..time_string(dur_2)
end
else
_tt = def._tt_2 or time_string(dur_2) or S("No effect")
end
local on_use = function (itemstack, user, pointed_thing)
def.on_use(user, effect_II, dur_2)
minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, user, pointed_thing)
@ -97,7 +107,7 @@ local function register_potion(def)
minetest.register_craftitem("mcl_potions:"..def.name.."_2", {
description = S(def.description..desc_mod),
_tt_help = _tt,
_tt_help = get_tt(def._tt_2, effect_II, dur_2),
_doc_items_longdesc = def._longdesc,
_doc_items_usagehelp = how_to_drink,
stack_max = 1,
@ -107,6 +117,24 @@ local function register_potion(def)
on_place = on_use,
on_secondary_use = on_use,
})
local splash_dur_2 = dur_2 * mcl_potions.SPLASH_FACTOR
local potion_fun
if def.dur then
potion_fun = function(player, redx) def.on_use(player, effect_II, splash_dur_2*redx) end
else
potion_fun = function(player, redx) def.on_use(player, effect_II*redx, splash_dur_2) end
end
local splash_def = {
tt = get_tt(def._tt_2, effect_II, splash_dur_2),
potion_fun = potion_fun,
}
if def.color then
mcl_potions.register_splash(def.name.."_2", S("Splash "..def.description..desc_mod), def.color, splash_def)
end
end
if def.is_plus then
@ -116,16 +144,6 @@ local function register_potion(def)
dur_pl = 90
end
local _tt
if def.effect and def.is_dur then
_tt = (def.effect*100).."% | "..time_string(dur_pl)
if def.name == "poison" or def.name == "regeneration" then
_tt = "1/2 Heart/"..def.effect.."sec | "..time_string(dur_pl)
end
else
_tt = def._tt_plus or time_string(dur_pl) or S("No effect")
end
local on_use = function (itemstack, user, pointed_thing)
def.on_use(user, def.effect, dur_pl)
minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, user, pointed_thing)
@ -135,7 +153,7 @@ local function register_potion(def)
minetest.register_craftitem("mcl_potions:"..def.name.."_plus", {
description = S(def.description.." +"),
_tt_help = _tt,
_tt_help = get_tt(def._tt_plus, def.effect, dur_pl),
_doc_items_longdesc = def._longdesc,
_doc_items_usagehelp = how_to_drink,
stack_max = 1,
@ -146,6 +164,23 @@ local function register_potion(def)
on_secondary_use = on_use,
})
local splash_dur_pl = dur_pl * mcl_potions.SPLASH_FACTOR
local potion_fun
if def.dur then
potion_fun = function(player, redx) def.on_use(player, def.effect, splash_dur_2*redx) end
else
potion_fun = function(player, redx) def.on_use(player, def.effect*redx, splash_dur_2) end
end
local splash_def = {
tt = get_tt(def._tt_2, effect_II, splash_dur_2),
potion_fun = potion_fun,
}
if def.color then
mcl_potions.register_splash(def.name.."_plus", S("Splash "..def.description.." +"), def.color, splash_def)
end
end
end

View File

@ -8,7 +8,7 @@ local splash_image = function(colorstring, opacity)
end
local function register_splash(name, descr, color, def)
function mcl_potions.register_splash(name, descr, color, def)
local id = "mcl_potions:"..name.."_splash"
minetest.register_craftitem(id, {
@ -96,136 +96,136 @@ local splash_DUR = mcl_potions.DURATION*mcl_potions.SPLASH_FACTOR
local splash_DUR_2 = mcl_potions.DURATION_2*mcl_potions.SPLASH_FACTOR
local splash_DUR_pl = mcl_potions.DURATION_PLUS*mcl_potions.SPLASH_FACTOR
register_splash("water", S("Splash Water Bottle"), "#0000FF", {
potion_fun = function(player, redx) end,
tt = S("No effect")
})
register_splash("river_water", S("Splash River Water Bottle"), "#0044FF", {
potion_fun = function(player, redx) end,
tt = S("No effect")
})
register_splash("awkward", S("Awkward Splash Potion"), "#0000FF", {
potion_fun = function(player, redx) end,
tt = S("No effect")
})
register_splash("mundane", S("Mundane Splash Potion"), "#0000FF", {
potion_fun = function(player, redx) end,
tt = S("No effect")
})
register_splash("thick", S("Thick Splash Potion"), "#0000FF", {
potion_fun = function(player, redx) end,
tt = S("No effect")
})
register_splash("healing", S("Healing Splash Potion"), "#AA0000", {
potion_fun = function(player, redx) mcl_potions.healing_func(player, 3*redx) end,
tt = S("+3 HP")
})
register_splash("healing_2", S("Healing Splash Potion II"), "#DD0000", {
potion_fun = function(player, redx) mcl_potions.healing_func(player, 6*redx) end,
tt = S("+6 HP")
})
register_splash("harming", S("Harming Splash Potion"), "#660099", {
potion_fun = function(player, redx) mcl_potions.healing_func(player, -6*redx) end,
tt = S("-4 HP")
})
register_splash("harming_2", S("Harming Splash Potion II"), "#330066", {
potion_fun = function(player, redx) mcl_potions.healing_func(player, -12*redx) end,
tt = S("-6 HP")
})
register_splash("leaping", S("Leaping Splash Potion"), "#00CC33", {
potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.2, splash_DUR*redx) end,
tt = S("120% | @1", time_string(splash_DUR))
})
register_splash("leaping_2", S("Leaping Splash Potion II"), "#00EE33", {
potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.4, splash_DUR_2*redx) end,
tt = S("140% | @1", time_string(splash_DUR_2))
})
register_splash("leaping_plus", S("Leaping Splash Potion +"), "#00DD33", {
potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.2, splash_DUR_pl*redx) end,
tt = S("120% | @1", time_string(splash_DUR_pl))
})
register_splash("swiftness", S("Swiftness Splash Potion"), "#009999", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.2, splash_DUR*redx) end,
tt = S("120% | @1", time_string(splash_DUR))
})
register_splash("swiftness_2", S("Swiftness Splash Potion II"), "#00BBBB", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.4, splash_DUR_2*redx) end,
tt = S("140% | @1", time_string(splash_DUR_2))
})
register_splash("swiftness_plus", S("Swiftness Splash Potion +"), "#00BBBB", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.2, splash_DUR_pl*redx) end,
tt = S("120% | @1", time_string(splash_DUR_2))
})
register_splash("slowness", S("Slowness Splash Potion"), "#000080", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.85, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
tt = S("85% | @1", time_string(splash_DUR*mcl_potions.INV_FACTOR))
})
register_splash("slowness_2", S("Slowness Splash Potion IV"), "#000080", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.4, 20*mcl_potions.INV_FACTOR*redx) end,
tt = S("40% | @1", time_string(20*mcl_potions.INV_FACTOR))
})
register_splash("slowness_plus", S("Slowness Splash Potion +"), "#000066", {
potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.85, splash_DUR_pl*mcl_potions.INV_FACTOR*redx) end,
tt = S("85% | @1", time_string(splash_DUR_pl*mcl_potions.INV_FACTOR))
})
register_splash("poison", S("Poison Splash Potion"), "#335544", {
potion_fun = function(player, redx) mcl_potions.poison_func(player, 2.5, splash_DUR*mcl_potions.INV_FACTOR^2*redx) end,
tt = S("-1 HP / 2.5s | @1", time_string(splash_DUR*mcl_potions.INV_FACTOR^2))
})
register_splash("poison_2", S("Poison Splash Potion II"), "#446655", {
potion_fun = function(player, redx) mcl_potions.poison_func(player, 1.2, splash_DUR_2*mcl_potions.INV_FACTOR^2*redx) end,
tt = S("-1 HP / 1.2s | @1", time_string(splash_DUR_2*mcl_potions.INV_FACTOR^2))
})
register_splash("poison_plus", S("Poison Splash Potion +"), "#557766", {
potion_fun = function(player, redx) mcl_potions.poison_func(player, 2.5, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
tt = S("-1 HP / 2.5s | @1", time_string(splash_DUR_pl*mcl_potions.INV_FACTOR^2))
})
register_splash("regeneration", S("Regeneration Splash Potion"), "#A52BB2", {
potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 2.5, splash_DUR*redx) end,
tt = S("+1 HP / 2.5s | @1", time_string(splash_DUR))
})
register_splash("regeneration_2", S("Regeneration Splash Potion II"), "#B52CC2", {
potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 1.2, (splash_DUR_2 + 1)*redx) end,
tt = S("+1 HP / 1.2s | @1", time_string(splash_DUR_2 + 1))
})
register_splash("regeneration_plus", S("Regeneration Splash Potion +"), "#C53DD3", {
potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 2.5, splash_DUR_pl*redx) end,
tt = S("+1 HP / 2.5s | @1", time_string(splash_DUR_pl))
})
register_splash("invisibility", S("Invisibility Splash Potion"), "#B0B0B0", {
potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, nil, splash_DUR*redx) end,
tt = time_string(splash_DUR)
})
register_splash("invisibility_plus", S("Invisibility Splash Potion +"), "#A0A0A0", {
potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, nil, splash_DUR_pl*redx) end,
tt = time_string(splash_DUR_pl)
})
-- register_splash("water", S("Splash Water Bottle"), "#0000FF", {
-- potion_fun = function(player, redx) end,
-- tt = S("No effect")
-- })
--
-- register_splash("river_water", S("Splash River Water Bottle"), "#0044FF", {
-- potion_fun = function(player, redx) end,
-- tt = S("No effect")
-- })
--
-- register_splash("awkward", S("Awkward Splash Potion"), "#0000FF", {
-- potion_fun = function(player, redx) end,
-- tt = S("No effect")
-- })
--
-- register_splash("mundane", S("Mundane Splash Potion"), "#0000FF", {
-- potion_fun = function(player, redx) end,
-- tt = S("No effect")
-- })
--
-- register_splash("thick", S("Thick Splash Potion"), "#0000FF", {
-- potion_fun = function(player, redx) end,
-- tt = S("No effect")
-- })
--
-- register_splash("healing", S("Healing Splash Potion"), "#AA0000", {
-- potion_fun = function(player, redx) mcl_potions.healing_func(player, 3*redx) end,
-- tt = S("+3 HP")
-- })
--
-- register_splash("healing_2", S("Healing Splash Potion II"), "#DD0000", {
-- potion_fun = function(player, redx) mcl_potions.healing_func(player, 6*redx) end,
-- tt = S("+6 HP")
-- })
--
-- register_splash("harming", S("Harming Splash Potion"), "#660099", {
-- potion_fun = function(player, redx) mcl_potions.healing_func(player, -6*redx) end,
-- tt = S("-4 HP")
-- })
--
-- register_splash("harming_2", S("Harming Splash Potion II"), "#330066", {
-- potion_fun = function(player, redx) mcl_potions.healing_func(player, -12*redx) end,
-- tt = S("-6 HP")
-- })
--
-- register_splash("leaping", S("Leaping Splash Potion"), "#00CC33", {
-- potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.2, splash_DUR*redx) end,
-- tt = S("120% | @1", time_string(splash_DUR))
--
-- })
--
-- register_splash("leaping_2", S("Leaping Splash Potion II"), "#00EE33", {
-- potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.4, splash_DUR_2*redx) end,
-- tt = S("140% | @1", time_string(splash_DUR_2))
-- })
--
-- register_splash("leaping_plus", S("Leaping Splash Potion +"), "#00DD33", {
-- potion_fun = function(player, redx) mcl_potions.leaping_func(player, 1.2, splash_DUR_pl*redx) end,
-- tt = S("120% | @1", time_string(splash_DUR_pl))
-- })
--
-- register_splash("swiftness", S("Swiftness Splash Potion"), "#009999", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.2, splash_DUR*redx) end,
-- tt = S("120% | @1", time_string(splash_DUR))
-- })
--
-- register_splash("swiftness_2", S("Swiftness Splash Potion II"), "#00BBBB", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.4, splash_DUR_2*redx) end,
-- tt = S("140% | @1", time_string(splash_DUR_2))
-- })
--
-- register_splash("swiftness_plus", S("Swiftness Splash Potion +"), "#00BBBB", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 1.2, splash_DUR_pl*redx) end,
-- tt = S("120% | @1", time_string(splash_DUR_2))
-- })
--
-- register_splash("slowness", S("Slowness Splash Potion"), "#000080", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.85, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
-- tt = S("85% | @1", time_string(splash_DUR*mcl_potions.INV_FACTOR))
-- })
--
-- register_splash("slowness_2", S("Slowness Splash Potion IV"), "#000080", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.4, 20*mcl_potions.INV_FACTOR*redx) end,
-- tt = S("40% | @1", time_string(20*mcl_potions.INV_FACTOR))
-- })
--
-- register_splash("slowness_plus", S("Slowness Splash Potion +"), "#000066", {
-- potion_fun = function(player, redx) mcl_potions.swiftness_func(player, 0.85, splash_DUR_pl*mcl_potions.INV_FACTOR*redx) end,
-- tt = S("85% | @1", time_string(splash_DUR_pl*mcl_potions.INV_FACTOR))
-- })
--
-- register_splash("poison", S("Poison Splash Potion"), "#335544", {
-- potion_fun = function(player, redx) mcl_potions.poison_func(player, 2.5, splash_DUR*mcl_potions.INV_FACTOR^2*redx) end,
-- tt = S("-1 HP / 2.5s | @1", time_string(splash_DUR*mcl_potions.INV_FACTOR^2))
-- })
--
-- register_splash("poison_2", S("Poison Splash Potion II"), "#446655", {
-- potion_fun = function(player, redx) mcl_potions.poison_func(player, 1.2, splash_DUR_2*mcl_potions.INV_FACTOR^2*redx) end,
-- tt = S("-1 HP / 1.2s | @1", time_string(splash_DUR_2*mcl_potions.INV_FACTOR^2))
-- })
--
-- register_splash("poison_plus", S("Poison Splash Potion +"), "#557766", {
-- potion_fun = function(player, redx) mcl_potions.poison_func(player, 2.5, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
-- tt = S("-1 HP / 2.5s | @1", time_string(splash_DUR_pl*mcl_potions.INV_FACTOR^2))
-- })
--
-- register_splash("regeneration", S("Regeneration Splash Potion"), "#A52BB2", {
-- potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 2.5, splash_DUR*redx) end,
-- tt = S("+1 HP / 2.5s | @1", time_string(splash_DUR))
-- })
--
-- register_splash("regeneration_2", S("Regeneration Splash Potion II"), "#B52CC2", {
-- potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 1.2, (splash_DUR_2 + 1)*redx) end,
-- tt = S("+1 HP / 1.2s | @1", time_string(splash_DUR_2 + 1))
-- })
--
-- register_splash("regeneration_plus", S("Regeneration Splash Potion +"), "#C53DD3", {
-- potion_fun = function(player, redx) mcl_potions.regeneration_func(player, 2.5, splash_DUR_pl*redx) end,
-- tt = S("+1 HP / 2.5s | @1", time_string(splash_DUR_pl))
-- })
--
-- register_splash("invisibility", S("Invisibility Splash Potion"), "#B0B0B0", {
-- potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, nil, splash_DUR*redx) end,
-- tt = time_string(splash_DUR)
-- })
--
-- register_splash("invisibility_plus", S("Invisibility Splash Potion +"), "#A0A0A0", {
-- potion_fun = function(player, redx) mcl_potions.invisiblility_func(player, nil, splash_DUR_pl*redx) end,
-- tt = time_string(splash_DUR_pl)
-- })
-- register_splash("weakness", S("Weakness Splash Potion"), "#6600AA", {
-- potion_fun = function(player, redx) mcl_potions.weakness_func(player, -4, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
@ -257,32 +257,32 @@ register_splash("invisibility_plus", S("Invisibility Splash Potion +"), "#A0A0A0
-- tt = time_string(splash_DUR_pl)
-- })
register_splash("water_breathing", S("Water Breathing Splash Potion"), "#0000AA", {
potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, nil, splash_DUR*redx) end,
tt = time_string(splash_DUR)
})
register_splash("water_breathing_plus", S("Water Breathing Splash Potion +"), "#0000CC", {
potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, nil, splash_DUR_pl*redx) end,
tt = time_string(splash_DUR_pl)
})
register_splash("fire_resistance", S("Fire Resistance Splash Potion"), "#D0A040", {
potion_fun = function(player, redx) mcl_potions.fire_resistance_func(player, nil, splash_DUR*redx) end,
tt = time_string(splash_DUR)
})
register_splash("fire_resistance_plus", S("Fire Resistance Splash Potion +"), "#E0B050", {
potion_fun = function(player, redx) mcl_potions.fire_resistance_func(player, nil, splash_DUR_pl*redx) end,
tt = time_string(splash_DUR_pl)
})
register_splash("night_vision", S("Night Vision Splash Potion"), "#1010AA", {
potion_fun = function(player, redx) mcl_potions.night_vision_func(player, nil, splash_DUR*redx) end,
tt = time_string(splash_DUR)
})
register_splash("night_vision_plus", S("Night Vision Splash Potion +"), "#2020BA", {
potion_fun = function(player, redx) mcl_potions.night_vision_func(player, nil, splash_DUR_pl*redx) end,
tt = time_string(splash_DUR_pl)
})
-- register_splash("water_breathing", S("Water Breathing Splash Potion"), "#0000AA", {
-- potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, nil, splash_DUR*redx) end,
-- tt = time_string(splash_DUR)
-- })
--
-- register_splash("water_breathing_plus", S("Water Breathing Splash Potion +"), "#0000CC", {
-- potion_fun = function(player, redx) mcl_potions.water_breathing_func(player, nil, splash_DUR_pl*redx) end,
-- tt = time_string(splash_DUR_pl)
-- })
--
-- register_splash("fire_resistance", S("Fire Resistance Splash Potion"), "#D0A040", {
-- potion_fun = function(player, redx) mcl_potions.fire_resistance_func(player, nil, splash_DUR*redx) end,
-- tt = time_string(splash_DUR)
-- })
--
-- register_splash("fire_resistance_plus", S("Fire Resistance Splash Potion +"), "#E0B050", {
-- potion_fun = function(player, redx) mcl_potions.fire_resistance_func(player, nil, splash_DUR_pl*redx) end,
-- tt = time_string(splash_DUR_pl)
-- })
--
-- register_splash("night_vision", S("Night Vision Splash Potion"), "#1010AA", {
-- potion_fun = function(player, redx) mcl_potions.night_vision_func(player, nil, splash_DUR*redx) end,
-- tt = time_string(splash_DUR)
-- })
--
-- register_splash("night_vision_plus", S("Night Vision Splash Potion +"), "#2020BA", {
-- potion_fun = function(player, redx) mcl_potions.night_vision_func(player, nil, splash_DUR_pl*redx) end,
-- tt = time_string(splash_DUR_pl)
-- })