Translatable effect names and cleanup
-added translatable effect names to the API -made /effect utilize those descriptions -cleaned up variables/constants to go with further API changespotions_api_redo
parent
6a09e5cf48
commit
d0b3a7b49b
|
@ -24,9 +24,8 @@ minetest.register_chatcommand("effect",{
|
||||||
if not P[1] then
|
if not P[1] then
|
||||||
return false, S("Missing effect parameter!")
|
return false, S("Missing effect parameter!")
|
||||||
elseif P[1] == "list" then
|
elseif P[1] == "list" then
|
||||||
local regs = mcl_potions.get_registered_effects()
|
|
||||||
local effects = "heal"
|
local effects = "heal"
|
||||||
for name, _ in pairs(regs) do
|
for name, _ in pairs(mcl_potions.registered_effects) do
|
||||||
effects = effects .. ", " .. name
|
effects = effects .. ", " .. name
|
||||||
end
|
end
|
||||||
return true, effects
|
return true, effects
|
||||||
|
@ -57,20 +56,21 @@ minetest.register_chatcommand("effect",{
|
||||||
P[3] = 1
|
P[3] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if mcl_potions.is_effect_registered(P[1]) then
|
local def = mcl_potions.registered_effects[P[1]]
|
||||||
|
if def then
|
||||||
if P[3] == "F" then
|
if P[3] == "F" then
|
||||||
local given = mcl_potions.give_effect(P[1], minetest.get_player_by_name(name), tonumber(P[4]), tonumber(P[2]))
|
local given = mcl_potions.give_effect(P[1], minetest.get_player_by_name(name), tonumber(P[4]), tonumber(P[2]))
|
||||||
if given then
|
if given then
|
||||||
return true, S("@1 effect given to player @2 for @3 seconds with factor of @4.", P[1], name, P[2], P[4])
|
return true, S("@1 effect given to player @2 for @3 seconds with factor of @4.", def.description, name, P[2], P[4])
|
||||||
else
|
else
|
||||||
return false, S("Giving effect @1 to player @2 failed.", P[1], name)
|
return false, S("Giving effect @1 to player @2 failed.", def.description, name)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local given = mcl_potions.give_effect_by_level(P[1], minetest.get_player_by_name(name), tonumber(P[3]), tonumber(P[2]))
|
local given = mcl_potions.give_effect_by_level(P[1], minetest.get_player_by_name(name), tonumber(P[3]), tonumber(P[2]))
|
||||||
if given then
|
if given then
|
||||||
return true, S("@1 effect on level @2 given to player @3 for @4 seconds.", P[1], P[3], name, P[2])
|
return true, S("@1 effect on level @2 given to player @3 for @4 seconds.", def.description, P[3], name, P[2])
|
||||||
else
|
else
|
||||||
return false, S("Giving effect @1 to player @2 failed.", P[1], name)
|
return false, S("Giving effect @1 to player @2 failed.", def.description, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
local EF = {}
|
local EF = {}
|
||||||
local registered_effects = {}
|
mcl_potions.registered_effects = {}
|
||||||
|
local registered_effects = mcl_potions.registered_effects -- shorthand ref
|
||||||
|
|
||||||
local EFFECT_TYPES = 0
|
local EFFECT_TYPES = 0
|
||||||
minetest.register_on_mods_loaded(function()
|
minetest.register_on_mods_loaded(function()
|
||||||
|
@ -8,7 +11,6 @@ minetest.register_on_mods_loaded(function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- ██████╗░███████╗░██████╗░██╗░██████╗████████╗███████╗██████╗
|
-- ██████╗░███████╗░██████╗░██╗░██████╗████████╗███████╗██████╗
|
||||||
-- ██╔══██╗██╔════╝██╔════╝░██║██╔════╝╚══██╔══╝██╔════╝██╔══██╗
|
-- ██╔══██╗██╔════╝██╔════╝░██║██╔════╝╚══██╔══╝██╔════╝██╔══██╗
|
||||||
-- ██████╔╝█████╗░░██║░░██╗░██║╚█████╗░░░░██║░░░█████╗░░██████╔╝
|
-- ██████╔╝█████╗░░██║░░██╗░██║╚█████╗░░░░██║░░░█████╗░░██████╔╝
|
||||||
|
@ -51,7 +53,9 @@ end
|
||||||
-- API - registers an effect
|
-- API - registers an effect
|
||||||
-- required parameters in def:
|
-- required parameters in def:
|
||||||
-- name - string - effect name in code
|
-- name - string - effect name in code
|
||||||
|
-- description - translated string - actual effect name in game
|
||||||
-- optional parameters in def:
|
-- optional parameters in def:
|
||||||
|
-- get_tt - function(factor) - returns tooltip description text for use with potions
|
||||||
-- icon - string - file name of the effect icon in HUD - defaults to one based on name
|
-- icon - string - file name of the effect icon in HUD - defaults to one based on name
|
||||||
-- res_condition - function(object) - returning true if target is to be resistant to the effect
|
-- res_condition - function(object) - returning true if target is to be resistant to the effect
|
||||||
-- on_start - function(object, factor) - called when dealing the effect
|
-- on_start - function(object, factor) - called when dealing the effect
|
||||||
|
@ -70,25 +74,33 @@ end
|
||||||
-- modifier_priority - integer - priority passed when registering damage_modifier - defaults to -50
|
-- modifier_priority - integer - priority passed when registering damage_modifier - defaults to -50
|
||||||
function mcl_potions.register_effect(def)
|
function mcl_potions.register_effect(def)
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
if def.name == nil then
|
local name = def.name
|
||||||
|
if name == nil then
|
||||||
error("Unable to register effect: name is nil")
|
error("Unable to register effect: name is nil")
|
||||||
end
|
end
|
||||||
if def.name == "list" then
|
if type(name) ~= "string" then
|
||||||
|
error("Unable to register effect: name is not a string")
|
||||||
|
end
|
||||||
|
if name == "list" then
|
||||||
error("Unable to register effect: list is a reserved word")
|
error("Unable to register effect: list is a reserved word")
|
||||||
end
|
end
|
||||||
if def.name == "heal" then
|
if name == "heal" then
|
||||||
error("Unable to register effect: heal is a reserved word")
|
error("Unable to register effect: heal is a reserved word")
|
||||||
end
|
end
|
||||||
if registered_effects[name] then
|
if registered_effects[name] then
|
||||||
error("Effect named "..name.." already registered!")
|
error("Effect named "..name.." already registered!")
|
||||||
end
|
end
|
||||||
local name = def.name
|
if not def.description or type(def.description) ~= "string" then
|
||||||
|
error("Unable to register effect: description is not a string")
|
||||||
|
end
|
||||||
local pdef = {}
|
local pdef = {}
|
||||||
|
pdef.description = def.description
|
||||||
if not def.icon then
|
if not def.icon then
|
||||||
pdef.icon = modname.."_effect_"..name..".png"
|
pdef.icon = modname.."_effect_"..name..".png"
|
||||||
else
|
else
|
||||||
pdef.icon = def.icon
|
pdef.icon = def.icon
|
||||||
end
|
end
|
||||||
|
pdef.get_tt = def.get_tt
|
||||||
pdef.res_condition = def.res_condition
|
pdef.res_condition = def.res_condition
|
||||||
pdef.on_start = def.on_start
|
pdef.on_start = def.on_start
|
||||||
pdef.on_load = def.on_load
|
pdef.on_load = def.on_load
|
||||||
|
@ -134,20 +146,9 @@ function mcl_potions.register_effect(def)
|
||||||
EF[name] = {}
|
EF[name] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_potions.get_registered_effects()
|
|
||||||
return table.copy(registered_effects)
|
|
||||||
end
|
|
||||||
|
|
||||||
function mcl_potions.is_effect_registered(name)
|
|
||||||
if registered_effects[name] then
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "invisibility",
|
name = "invisibility",
|
||||||
|
description = S("Invisiblity"),
|
||||||
on_start = function(object, factor)
|
on_start = function(object, factor)
|
||||||
mcl_potions.make_invisible(object, true)
|
mcl_potions.make_invisible(object, true)
|
||||||
end,
|
end,
|
||||||
|
@ -163,6 +164,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "poison",
|
name = "poison",
|
||||||
|
description = S("Poison"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
local entity = object:get_luaentity()
|
local entity = object:get_luaentity()
|
||||||
return (entity and (entity.harmed_by_heal or string.find(entity.name, "spider")))
|
return (entity and (entity.harmed_by_heal or string.find(entity.name, "spider")))
|
||||||
|
@ -181,6 +183,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "regeneration",
|
name = "regeneration",
|
||||||
|
description = S("Regeneration"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
local entity = object:get_luaentity()
|
local entity = object:get_luaentity()
|
||||||
return (entity and entity.harmed_by_heal)
|
return (entity and entity.harmed_by_heal)
|
||||||
|
@ -202,6 +205,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "strength",
|
name = "strength",
|
||||||
|
description = S("Strength"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -210,6 +214,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "weakness",
|
name = "weakness",
|
||||||
|
description = S("Weakness"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -218,6 +223,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "water_breathing",
|
name = "water_breathing",
|
||||||
|
description = S("Water Breathing"),
|
||||||
on_step = function(dtime, object, factor, duration)
|
on_step = function(dtime, object, factor, duration)
|
||||||
if not object:is_player() then return end
|
if not object:is_player() then return end
|
||||||
if object:get_breath() then
|
if object:get_breath() then
|
||||||
|
@ -231,6 +237,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "leaping",
|
name = "leaping",
|
||||||
|
description = S("Leaping"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -248,6 +255,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "swiftness",
|
name = "swiftness",
|
||||||
|
description = S("Swiftness"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -265,6 +273,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "slowness",
|
name = "slowness",
|
||||||
|
description = S("Slowness"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -282,6 +291,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "night_vision",
|
name = "night_vision",
|
||||||
|
description = S("Night Vision"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -303,6 +313,7 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "fire_resistance",
|
name = "fire_resistance",
|
||||||
|
description = S("Fire Resistance"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
|
@ -313,11 +324,13 @@ mcl_potions.register_effect({
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "bad_omen",
|
name = "bad_omen",
|
||||||
|
description = S("Bad Omen"),
|
||||||
particle_color = "#0b6138",
|
particle_color = "#0b6138",
|
||||||
})
|
})
|
||||||
|
|
||||||
mcl_potions.register_effect({
|
mcl_potions.register_effect({
|
||||||
name = "withering",
|
name = "withering",
|
||||||
|
description = S("Withering"),
|
||||||
res_condition = function(object)
|
res_condition = function(object)
|
||||||
local entity = object:get_luaentity()
|
local entity = object:get_luaentity()
|
||||||
return (entity and string.find(entity.name, "wither"))
|
return (entity and string.find(entity.name, "wither"))
|
||||||
|
@ -696,7 +709,7 @@ function mcl_potions.make_invisible(obj_ref, hide)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mcl_potions._use_potion(item, obj, color)
|
function mcl_potions._use_potion(obj, color)
|
||||||
local d = 0.1
|
local d = 0.1
|
||||||
local pos = obj:get_pos()
|
local pos = obj:get_pos()
|
||||||
minetest.sound_play("mcl_potions_drinking", {pos = pos, max_hear_distance = 6, gain = 1})
|
minetest.sound_play("mcl_potions_drinking", {pos = pos, max_hear_distance = 6, gain = 1})
|
||||||
|
|
|
@ -8,14 +8,17 @@ mcl_potions = {}
|
||||||
-- duration effects of glowstone are a time factor of 1/2
|
-- duration effects of glowstone are a time factor of 1/2
|
||||||
-- splash potion duration effects are reduced by a factor of 3/4
|
-- splash potion duration effects are reduced by a factor of 3/4
|
||||||
|
|
||||||
mcl_potions.II_FACTOR = 2
|
mcl_potions.POTENT_FACTOR = 2
|
||||||
mcl_potions.PLUS_FACTOR = 8/3
|
mcl_potions.PLUS_FACTOR = 8/3
|
||||||
|
mcl_potions.INV_FACTOR = 0.50
|
||||||
|
|
||||||
mcl_potions.DURATION = 180
|
mcl_potions.DURATION = 180
|
||||||
mcl_potions.DURATION_PLUS = mcl_potions.DURATION * mcl_potions.PLUS_FACTOR
|
mcl_potions.DURATION_INV = mcl_potions.DURATION * mcl_potions.INV_FACTOR
|
||||||
mcl_potions.DURATION_2 = mcl_potions.DURATION / mcl_potions.II_FACTOR
|
|
||||||
|
mcl_potions.II_FACTOR = mcl_potions.POTENT_FACTOR -- TODO remove at some point
|
||||||
|
mcl_potions.DURATION_PLUS = mcl_potions.DURATION * mcl_potions.PLUS_FACTOR -- TODO remove at some point
|
||||||
|
mcl_potions.DURATION_2 = mcl_potions.DURATION / mcl_potions.II_FACTOR -- TODO remove at some point
|
||||||
|
|
||||||
mcl_potions.INV_FACTOR = 0.50
|
|
||||||
mcl_potions.SPLASH_FACTOR = 0.75
|
mcl_potions.SPLASH_FACTOR = 0.75
|
||||||
mcl_potions.LINGERING_FACTOR = 0.25
|
mcl_potions.LINGERING_FACTOR = 0.25
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue