1
0
Fork 0

Compare commits

...

45 Commits

Author SHA1 Message Date
the-real-herowl 2e6a66860f Added conduit power 2024-03-20 02:11:00 +01:00
the-real-herowl d9a4a16bb5 Haste and fatigue expanded and improved
* abstracted and refactored some parts of haste and fatigue
* added and exposed new mcl_potions API functions
* fixed haste and fatigue not altering the hand
* mcl_meshhand now calls into mcl_potions when resetting the hand
2024-03-20 01:47:00 +01:00
the-real-herowl ee4db5745a Capped fatigue effect on punching
This fixes a crash, too
Also updates toolcaps on gamemode change
2024-03-19 01:25:38 +01:00
the-real-herowl f993797805 Improved haste and fatigue effects
* fixed a few crashes related to unusual effect levels
* added haste and fatigue combat functionality
* added some cleanup to avoid hangover unstackable items
* capped the slowdown from fatigue at 5 minutes digging time
* (despite the above, if a tool has a longer time set in definition,
	that still works)
* removed an unused "global" variable
2024-02-03 05:37:55 +01:00
the-real-herowl 7bfe65e4e8 Added haste and fatigue 2024-02-02 04:33:19 +00:00
the-real-herowl c19ec0b617 Added dolphin's grace 2024-02-02 04:33:19 +00:00
the-real-herowl 48b7b77b9d Added strength and weakness effects
* also highest effect level displayed in HUD set to 3000
* also improved indicating effects with strange factors in HUD
2024-02-02 04:33:19 +00:00
the-real-herowl c08750262c Renamed some functions and variables
* changed names referring to player where it does support mobs
* also added an is_player() check in one function
2024-02-02 04:33:19 +00:00
the-real-herowl 6368075e78 Improved descriptions 2024-02-02 04:33:19 +00:00
the-real-herowl 2db7383618 Improved nausea 2024-02-02 04:33:19 +00:00
the-real-herowl 27de088290 Added time_override to FOV API
time_override can be used when applying or removing modifiers
2024-02-02 04:33:19 +00:00
the-real-herowl 69e275d513 Improved the darkness effect 2024-02-02 04:33:19 +00:00
the-real-herowl ae58851ede Added darkness 2024-02-02 04:33:19 +00:00
the-real-herowl 8181db7952 Added nausea 2024-02-02 04:33:19 +00:00
the-real-herowl 6aa07a0258 Fixed graphical features of some effects
* loading fixed (by adding on_load)
* absorption bar never reaching end fixed
2024-02-02 04:33:19 +00:00
the-real-herowl 6d9bd67cf8 Added blindness effect
(also improved TT descriptions of some effects)
2024-02-02 04:33:19 +00:00
the-real-herowl 700a030a13 Added frost effect 2024-02-02 04:33:19 +00:00
the-real-herowl cd136f0a25 Added HP hudbar look modifier API
(for now in mcl_potions)
2024-02-02 04:33:19 +00:00
the-real-herowl aa9978a548 Add hero of the village effect 2024-02-02 04:33:19 +00:00
the-real-herowl 3a01dcee90 Added food poisoning and saturation effects 2024-02-02 04:33:19 +00:00
the-real-herowl 4e70ae1397 Added some missing effects and improved API
* added a way to have a damage modifier relying on type instead of flag
* added Slow Falling
* added Levitation
* added Health Boost
* added Absorption
2024-02-02 04:33:19 +00:00
the-real-herowl c8fd4ec3c2 Improved damage mods in effects, resistance effect 2024-02-02 04:33:19 +00:00
the-real-herowl 8d7cfe0925 New effect icons 2024-02-02 04:33:19 +00:00
the-real-herowl b00fe1e258 Improved effects HUD and fixes
* Fixed some effects not being replaced correctly with higher levels
* Implemented an old FIXME (MTE 5.3.0 fixed underlying bug)
* Added a way to obtain an approximate level of effect from factor
* Added effect level to HUD under the icon
* Added effect timer to HUD under the icon
2024-02-02 04:33:19 +00:00
the-real-herowl 647dd6fe13 Improved /effect command return messages
Also improved the name of a variable
2024-02-02 04:33:19 +00:00
the-real-herowl 1680b607b7 Registered dragon breath and pruned code
* removed old registration code
* added to the API the `nocreative` field
* registered the bottled dragon's breath as an item
2024-02-02 04:33:19 +00:00
the-real-herowl 3d72f56f19 Re-registered potions under new API 2024-02-02 04:33:19 +00:00
the-real-herowl 51d0d02af5 Added a constant to the API 2024-02-02 04:33:19 +00:00
the-real-herowl 3791e19ae8 Fixed tipped arrow descriptions 2024-02-02 04:33:19 +00:00
the-real-herowl b6429217f2 Added missing effect descriptions 2024-02-02 04:33:19 +00:00
the-real-herowl 4e5b802113 Fixed splash and lingering potions
* descriptions
* scaling
2024-02-02 04:33:19 +00:00
the-real-herowl 069969c10b Added support for varied descriptions 2024-02-02 04:33:19 +00:00
the-real-herowl d479f749f0 Implemented missing potion registering functionality
* improved support for custom (non-status) effects
* added support for splash potions
* added support for lingering potions
* added support for tipped arrows
* removed the old registration
2024-02-02 04:33:19 +00:00
the-real-herowl 3a81ce7733 Improved potion descriptions
* added support for effect descriptions
* added descriptions for some effects
* fixed a crash
2024-02-02 04:33:19 +00:00
the-real-herowl 9251cc1583 Potions registering API fully works with creative 2024-02-02 04:33:19 +00:00
the-real-herowl 2c63903e8e Fixed variable definitions ("undeclared global") 2024-02-02 04:33:19 +00:00
the-real-herowl c9b7b237cf Creative inventory using new potions API
-creative inventory utilizes the new potions API
-the new fancy tooltips are used there
2024-02-02 04:33:19 +00:00
the-real-herowl 53ea12ad10 Added new potion tooltip handling
-potion tooltips are now utilizing the power of the new API
-potion names change based on metadata
-nothing triggers loading the new tooltips beyond the names for now
2024-02-02 04:33:19 +00:00
the-real-herowl 62c1102f53 Added new potions registering API
-added comprehensive potions registering API
-new API registers only drinkable potions for now
-new API is compatible with very complex tooltips
-new API can have multiple effects per potion
-no hardcoding for specific potions in the new API
2024-02-02 04:33:19 +00:00
the-real-herowl b2611314cf 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 changes
2024-02-02 04:33:19 +00:00
the-real-herowl ed566b3cfe Arabic-to-Roman converter redo
-rewrote the Arabic-to-Roman number converter
-moved it to mcl_util
2024-02-02 04:33:19 +00:00
the-real-herowl 0684901e2a Reimplemented /effect heal and fixed bugs
-heal subcommand to the /effect reimplemented
-healing_func() from old API standardized, included in new API
-(the last point is due to it being substantially different from others)
-fixed a few bugs, potential crashes
-fixed incorrect withering effect progression
-standardized variable naming
2024-02-02 04:33:19 +00:00
the-real-herowl 6d055eba82 Resolved merge conflict 2024-02-02 04:33:19 +00:00
the-real-herowl 4501516bed Improved /effect command and fixes
-improved the /effect command, allowing to use effect levels
-fixed a bug in level-to-factor conversions
-renamed effect icons to follow the new convention
2024-02-02 04:33:19 +00:00
the-real-herowl 1961a45813 General effects API overhaul
- added a `register_effect()` function
- added the withering effect
- registered all the old effects under the new API
- unified effect names
- updated the main effect checker to use the new API
- changed some hardcoded values to support the unified effect naming
- added new namespaced metadata effects strings
- added support for legacy effect player metadata
- potions are still using the old effects API
- added glue between old API calls and the new API
- renamed the effect icons to support the unified effect naming
2024-02-02 04:33:19 +00:00
74 changed files with 2220 additions and 1401 deletions

View File

@ -1,5 +1,7 @@
mcl_util = {}
dofile(minetest.get_modpath(minetest.get_current_modname()).."/roman_numerals.lua")
-- Updates all values in t using values from to*.
function table.update(t, ...)
for _, to in ipairs {...} do

View File

@ -0,0 +1,30 @@
local converter = {
{1000, "M"},
{900, "CM"},
{500, "D"},
{400, "CD"},
{100, "C"},
{90, "XC"},
{50, "L"},
{40, "XL"},
{10, "X"},
{9, "IX"},
{5, "V"},
{4, "IV"},
{1, "I"}
}
mcl_util.to_roman = function(number)
local r = ""
local a = number
local i = 1
while a > 0 do
if a >= converter[i][1] then
a = a - converter[i][1]
r = r.. converter[i][2]
else
i = i + 1
end
end
return r
end

View File

@ -534,6 +534,8 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then
return
end
mcl_potions.update_haste_and_fatigue(hitter)
end
local time_now = minetest.get_us_time()
@ -605,6 +607,13 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
* tmp * ((armor[group] or 0) / 100.0)
end
-- strength and weakness effects
local strength = mcl_potions.get_effect(hitter, "strength")
local weakness = mcl_potions.get_effect(hitter, "weakness")
local str_fac = strength and strength.factor or 1
local weak_fac = weakness and weakness.factor or 1
damage = damage * str_fac * weak_fac
if weapon then
local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect")
if fire_aspect_level > 0 then

View File

@ -104,7 +104,7 @@ function mcl_raids.promote_to_raidcaptain(c) -- object
mcl_raids.drop_obanner(pos)
if cmi_cause and cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then
awards.unlock(cmi_cause.puncher:get_player_name(), "mcl:voluntary_exile")
local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen")
local lv = mcl_potions.get_effect(cmi_cause.puncher, "bad_omen")
if not lv then lv = 0
else lv = lv.factor end
lv = math.max(5,lv + 1)
@ -296,7 +296,7 @@ mcl_events.register_event("raid",{
--minetest.log("Cond start raid")
local r = {}
for _,p in pairs(minetest.get_connected_players()) do
if mcl_potions.player_has_effect(p,"bad_omen") then
if mcl_potions.has_effect(p,"bad_omen") then
local raid_pos = mcl_raids.find_village(p:get_pos())
if raid_pos then
--minetest.log("We have a raid position. Start raid")
@ -310,7 +310,7 @@ mcl_events.register_event("raid",{
self.mobs = {}
self.health_max = 1
self.health = 0
local lv = mcl_potions.player_get_effect(minetest.get_player_by_name(self.player), "bad_omen")
local lv = mcl_potions.get_effect(minetest.get_player_by_name(self.player), "bad_omen")
if lv and lv.factor and lv.factor > 1 then self.max_stage = 6 end
end,
cond_progress = function(self)
@ -331,7 +331,7 @@ mcl_events.register_event("raid",{
end,
on_complete = function(self)
awards.unlock(self.player,"mcl:hero_of_the_village")
mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen")
mcl_potions.clear_effect(minetest.get_player_by_name(self.player),"bad_omen")
make_firework(self.pos,os.time())
end,
})

View File

@ -120,20 +120,26 @@ mcl_weather.skycolor = {
override_day_night_ratio = function(player, ratio)
local meta = player:get_meta()
local has_night_vision = meta:get_int("night_vision") == 1
local has_darkness = meta:get_int("darkness") == 1
local is_visited_shepherd = meta:get_int("mcl_shepherd:special") == 1
local arg
-- Apply night vision only for dark sky
local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none"
local pos = player:get_pos()
local dim = mcl_worlds.pos_to_dimension(pos)
if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then
if ratio == nil then
arg = NIGHT_VISION_RATIO
else
arg = math.max(ratio, NIGHT_VISION_RATIO)
end
if has_darkness and not is_visited_shepherd then
if has_night_vision then arg = 0.1
else arg = 0 end
else
arg = ratio
-- Apply night vision only for dark sky
local is_dark = minetest.get_timeofday() > 0.8 or minetest.get_timeofday() < 0.2 or mcl_weather.state ~= "none"
local pos = player:get_pos()
local dim = mcl_worlds.pos_to_dimension(pos)
if (has_night_vision or is_visited_shepherd) and is_dark and dim ~= "nether" and dim ~= "end" then
if ratio == nil then
arg = NIGHT_VISION_RATIO
else
arg = math.max(ratio, NIGHT_VISION_RATIO)
end
else
arg = ratio
end
end
player:override_day_night_ratio(arg)
end,

View File

@ -1,4 +1,4 @@
name = mcl_tt
author = Wuzzy
description = Add MCL2 tooltips
depends = tt, mcl_enchanting, mcl_colors
depends = tt, mcl_enchanting, mcl_colors, mcl_util

View File

@ -112,3 +112,57 @@ tt.register_snippet(function(itemstring, _, itemstack)
return S("Durability: @1", S("@1 uses", mcl_util.calculate_durability(itemstack or ItemStack(itemstring))))
end
end)
-- Potions info
tt.register_snippet(function(itemstring, _, itemstack)
if not itemstack then return end
local def = itemstack:get_definition()
if def.groups._mcl_potion ~= 1 then return end
local s = ""
local meta = itemstack:get_meta()
local potency = meta:get_int("mcl_potions:potion_potent")
local plus = meta:get_int("mcl_potions:potion_plus")
local sl_factor = 1
if def.groups.splash_potion == 1 then
sl_factor = mcl_potions.SPLASH_FACTOR
elseif def.groups.ling_potion == 1 then
sl_factor = mcl_potions.LINGERING_FACTOR
end
if def._dynamic_tt then s = s.. def._dynamic_tt((potency+1)*sl_factor).. "\n" end
local effects = def._effect_list
if effects then
local effect
local dur
local timestamp
local ef_level
local roman_lvl
local factor
local ef_tt
for name, details in pairs(effects) do
effect = mcl_potions.registered_effects[name]
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus) * sl_factor
if potency > 0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end
timestamp = math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if ef_level > 1 then roman_lvl = " ".. mcl_util.to_roman(ef_level)
else roman_lvl = "" end
s = s.. effect.description.. roman_lvl.. " (".. timestamp.. ")\n"
if effect.uses_factor then factor = effect.level_to_factor(ef_level) end
if effect.get_tt then ef_tt = minetest.colorize("grey", effect.get_tt(factor)) else ef_tt = "" end
if ef_tt ~= "" then s = s.. ef_tt.. "\n" end
end
end
return s:trim()
end)

View File

@ -74,6 +74,22 @@ function tt.reload_itemstack_description(itemstack)
local orig_desc = def._tt_original_description or def.description
if meta:get_string("name") ~= "" then
orig_desc = minetest.colorize(tt.NAME_COLOR, meta:get_string("name"))
elseif def.groups._mcl_potion == 1 then
local potency = meta:get_int("mcl_potions:potion_potent")
local plus = meta:get_int("mcl_potions:potion_plus")
if potency > 0 then
local sym_potency = mcl_util.to_roman(potency+1)
orig_desc = orig_desc.. " ".. sym_potency
end
if plus > 0 then
local sym_plus = " "
local i = plus
while i>0 do
i = i - 1
sym_plus = sym_plus.. "+"
end
orig_desc = orig_desc.. sym_plus
end
end
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)
meta:set_string("description", desc)

View File

@ -1,4 +1,4 @@
name = tt
author = Wuzzy
description = Support for custom tooltip extensions for items
depends = mcl_colors
depends = mcl_colors, mcl_util

View File

@ -521,7 +521,9 @@ end
local function update_health(player)
local hp_max = player:get_properties().hp_max
hb.change_hudbar(player, "health", player:get_hp(), hp_max)
local hp = player:get_hp()
if hp > hp_max then hp = hp_max end
hb.change_hudbar(player, "health", hp, hp_max)
end
-- update built-in HUD bars

View File

@ -105,7 +105,13 @@ minetest.register_on_mods_loaded(function()
nonmisc = true
end
if def.groups.brewitem then
table.insert(inventory_lists["brew"], name)
local str = name
if def.groups._mcl_potion == 1 then
local stack = ItemStack(name)
tt.reload_itemstack_description(stack)
str = stack:to_string()
end
table.insert(inventory_lists["brew"], str)
nonmisc = true
end
if def.groups.craftitem then
@ -117,6 +123,23 @@ minetest.register_on_mods_loaded(function()
table.insert(inventory_lists["misc"], name)
end
if def.groups._mcl_potion == 1 then
if def.has_potent then
local stack = ItemStack(name)
local potency = def._default_potent_level - 1
stack:get_meta():set_int("mcl_potions:potion_potent", potency)
tt.reload_itemstack_description(stack)
table.insert(inventory_lists["brew"], stack:to_string())
end
if def.has_plus then
local stack = ItemStack(name)
local extend = def._default_extend_level
stack:get_meta():set_int("mcl_potions:potion_plus", extend)
tt.reload_itemstack_description(stack)
table.insert(inventory_lists["brew"], stack:to_string())
end
end
table.insert(inventory_lists["all"], name)
end
end

View File

@ -2,4 +2,4 @@ name = mcl_inventory
author = BlockMen
description = Adds the player inventory and creative inventory.
depends = mcl_init, mcl_formspec, mcl_enchanting, mcl_gamemode
optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player
optional_depends = mcl_armor, mcl_brewing, mcl_potions, mcl_enchanting, mcl_craftguide, mcl_player, tt

View File

@ -379,7 +379,7 @@ minetest.register_globalstep(function(dtime)
etime = 0
for _,pl in pairs(minetest.get_connected_players()) do
local armor_feet = pl:get_inventory():get_stack("armor", 5)
if pl and pl:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.player_has_effect(pl, "fire_proof")) then
if pl and pl:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.has_effect(pl, "fire_proof")) then
return
end
burn_in_campfire(pl)

View File

@ -56,7 +56,7 @@ end
function mcl_enchanting.get_enchantment_description(enchantment, level)
local enchantment_def = mcl_enchanting.enchantments[enchantment]
return enchantment_def.name ..
(enchantment_def.max_level == 1 and "" or " " .. mcl_enchanting.roman_numerals.toRoman(level))
(enchantment_def.max_level == 1 and "" or " " .. mcl_util.to_roman(level))
end
function mcl_enchanting.get_colorized_enchantment_description(enchantment, level)

View File

@ -11,7 +11,6 @@ mcl_enchanting = {
book_animation_steps = {0, 640, 680, 700, 740},
book_animation_loop = {["open"] = true, ["close"] = true},
book_animation_speed = 40,
roman_numerals = dofile(modpath .. "/roman_numerals.lua"), -- https://exercism.io/tracks/lua/exercises/roman-numerals/solutions/73c2fb7521e347209312d115f872fa49
enchantments = {},
overlay = "^[colorize:purple:50",
--overlay = "^[invert:rgb^[multiply:#4df44d:50^[invert:rgb",

View File

@ -1,5 +1,5 @@
name = mcl_enchanting
description = Enchanting for MineClone2
depends = tt, walkover, mcl_sounds, mcl_colors, mcl_experience
depends = tt, walkover, mcl_sounds, mcl_colors, mcl_experience, mcl_util
optional_depends = screwdriver
author = Fleckenstein

View File

@ -1,34 +0,0 @@
--------------------------------------------------------------------
--! @file
--! @brief Convert from normal numbers to Roman Numerals
---------------------------------------------------------------------
local conversionTable = {
{ number = 1000, symbol = "M" },
{ number = 900, symbol = "CM" },
{ number = 500, symbol = "D" },
{ number = 400, symbol = "CD" },
{ number = 100, symbol = "C" },
{ number = 90, symbol = "XC" },
{ number = 50, symbol = "L" },
{ number = 40, symbol = "XL" },
{ number = 10, symbol = "X" },
{ number = 9, symbol = "IX" },
{ number = 5, symbol = "V" },
{ number = 4, symbol = "IV" },
{ number = 1, symbol = "I" }
}
return{
toRoman = function(number)
local romanNumeral = ""
for _,table in pairs (conversionTable) do
while(number >= table.number) do
romanNumeral = romanNumeral .. table.symbol
number = number - table.number
end
end
return romanNumeral
end
}

View File

@ -135,7 +135,7 @@ minetest.register_node("mcl_nether:magma", {
-- From walkover mod
on_walk_over = function(loc, nodeiamon, player)
local armor_feet = player:get_inventory():get_stack("armor", 5)
if player and player:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.player_has_effect(player, "fire_proof")) then
if player and player:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.has_effect(player, "fire_proof")) then
return
end
-- Hurt players standing on top of this block

View File

@ -8,23 +8,9 @@ local S = minetest.get_translator(minetest.get_current_modname())
-- ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░  ░╚════╝░░╚════╝░╚═╝░░░░░╚═╝╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═════╝░╚═════╝░
local get_chat_function = {}
get_chat_function["poison"] = mcl_potions.poison_func
get_chat_function["regeneration"] = mcl_potions.regeneration_func
get_chat_function["invisibility"] = mcl_potions.invisiblility_func
get_chat_function["fire_resistance"] = mcl_potions.fire_resistance_func
get_chat_function["night_vision"] = mcl_potions.night_vision_func
get_chat_function["water_breathing"] = mcl_potions.water_breathing_func
get_chat_function["leaping"] = mcl_potions.leaping_func
get_chat_function["swiftness"] = mcl_potions.swiftness_func
get_chat_function["heal"] = mcl_potions.healing_func
get_chat_function["bad_omen"] = mcl_potions.bad_omen_func
get_chat_function["withering"] = mcl_potions.withering_func
minetest.register_chatcommand("effect",{
params = S("<effect> <duration> [<factor>]"),
description = S("Add a status effect to yourself. Arguments: <effect>: name of status effect, e.g. poison. <duration>: duration in seconds. <factor>: effect strength multiplier (1 = 100%)"),
params = S("<effect>|heal|list <duration|heal-amount> [<level>] [<factor>]"),
description = S("Add a status effect to yourself. Arguments: <effect>: name of status effect. Passing \"list\" as effect name lists available effects. Passing \"heal\" as effect name heals (or harms) by amount designed by the next parameter. <duration>: duration in seconds. (<heal-amount>: amount of healing when the effect is \"heal\", passing a negative value subtracts health.) <level>: effect power determinant, bigger level results in more powerful effect for effects that depend on the level (no changes for other effects), defaults to 1, pass F to use low-level factor instead. <factor>: effect strength modifier, can mean different things depending on the effect, no changes for effects that do not depend on level/factor."),
privs = {server = true},
func = function(name, params)
@ -37,22 +23,68 @@ minetest.register_chatcommand("effect",{
if not P[1] then
return false, S("Missing effect parameter!")
elseif P[1] == "list" then
local effects = "heal"
for effect, _ in pairs(mcl_potions.registered_effects) do
effects = effects .. ", " .. effect
end
return true, effects
elseif P[1] == "heal" then
local hp = tonumber(P[2])
if not hp or hp == 0 then
return false, S("Missing or invalid heal amount parameter!")
else
mcl_potions.healing_func(minetest.get_player_by_name(name), hp)
if hp > 0 then
if hp < 1 then hp = 1 end
return true, S("Player @1 healed by @2 HP.", name, hp)
else
if hp > -1 then hp = -1 end
return true, S("Player @1 harmed by @2 HP.", name, hp)
end
end
elseif not tonumber(P[2]) then
return false, S("Missing or invalid duration parameter!")
elseif P[3] and not tonumber(P[3]) then
return false, S("Invalid factor parameter!")
end
-- Default factor = 1
if not P[3] then
P[3] = 1.0
elseif P[3] and not tonumber(P[3]) and P[3] ~= "F" then
return false, S("Invalid level parameter!")
elseif P[3] and P[3] == "F" and not P[4] then
return false, S("Missing or invalid factor parameter when level is F!")
end
if get_chat_function[P[1]] then
get_chat_function[P[1]](minetest.get_player_by_name(name), tonumber(P[3]), tonumber(P[2]))
return true
-- Default level = 1
if not P[3] then
P[3] = 1
end
local def = mcl_potions.registered_effects[P[1]]
if def 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]))
if given then
if def.uses_factor then
return true, S("@1 effect given to player @2 for @3 seconds with factor of @4.", def.description, name, P[2], P[4])
else
return true, S("@1 effect given to player @2 for @3 seconds.", def.description, name, P[2])
end
else
return false, S("Giving effect @1 to player @2 failed.", def.description, name)
end
else
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 def.uses_factor then
return true, S("@1 effect on level @2 given to player @3 for @4 seconds.", def.description, P[3], name, P[2])
else
return true, S("@1 effect given to player @2 for @3 seconds.", def.description, name, P[2])
end
else
return false, S("Giving effect @1 to player @2 failed.", def.description, name)
end
end
else
return false, S("@1 is not an available status effect.", P[1])
end
end,
})

File diff suppressed because it is too large Load Diff

View File

@ -8,14 +8,18 @@ mcl_potions = {}
-- duration effects of glowstone are a time factor of 1/2
-- 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.INV_FACTOR = 0.50
mcl_potions.DURATION = 180
mcl_potions.DURATION_PLUS = mcl_potions.DURATION * mcl_potions.PLUS_FACTOR
mcl_potions.DURATION_2 = mcl_potions.DURATION / mcl_potions.II_FACTOR
mcl_potions.DURATION_INV = mcl_potions.DURATION * mcl_potions.INV_FACTOR
mcl_potions.DURATION_POISON = 45
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.LINGERING_FACTOR = 0.25
@ -462,17 +466,18 @@ function mcl_potions.get_alchemy(ingr, pot)
return false
end
mcl_mobs.effect_functions["poison"] = mcl_potions.poison_func
mcl_mobs.effect_functions["regeneration"] = mcl_potions.regeneration_func
mcl_mobs.effect_functions["invisibility"] = mcl_potions.invisiblility_func
mcl_mobs.effect_functions["fire_resistance"] = mcl_potions.fire_resistance_func
mcl_mobs.effect_functions["night_vision"] = mcl_potions.night_vision_func
mcl_mobs.effect_functions["water_breathing"] = mcl_potions.water_breathing_func
mcl_mobs.effect_functions["leaping"] = mcl_potions.leaping_func
mcl_mobs.effect_functions["swiftness"] = mcl_potions.swiftness_func
mcl_mobs.effect_functions["heal"] = mcl_potions.healing_func
mcl_mobs.effect_functions["bad_omen"] = mcl_potions.bad_omen_func
mcl_mobs.effect_functions["withering"] = mcl_potions.withering_func
-- TODO replace all calls to the old API with new API calls in other mods
-- mcl_mobs.effect_functions["poison"] = mcl_potions.poison_func
-- mcl_mobs.effect_functions["regeneration"] = mcl_potions.regeneration_func
-- mcl_mobs.effect_functions["invisibility"] = mcl_potions.invisiblility_func
-- mcl_mobs.effect_functions["fire_resistance"] = mcl_potions.fire_resistance_func
-- mcl_mobs.effect_functions["night_vision"] = mcl_potions.night_vision_func
-- mcl_mobs.effect_functions["water_breathing"] = mcl_potions.water_breathing_func
-- mcl_mobs.effect_functions["leaping"] = mcl_potions.leaping_func
-- mcl_mobs.effect_functions["swiftness"] = mcl_potions.swiftness_func
-- mcl_mobs.effect_functions["heal"] = mcl_potions.healing_func
-- mcl_mobs.effect_functions["bad_omen"] = mcl_potions.bad_omen_func
-- mcl_mobs.effect_functions["withering"] = mcl_potions.withering_func
-- give withering to players in a wither rose
local etime = 0

View File

@ -11,8 +11,8 @@ end
local lingering_effect_at = {}
local function add_lingering_effect(pos, color, def, is_water, instant)
lingering_effect_at[pos] = {color = color, timer = 30, def = def, is_water = is_water}
local function add_lingering_effect(pos, color, def, is_water, potency, plus)
lingering_effect_at[pos] = {color = color, timer = 30, def = def, is_water = is_water, potency = potency, plus = plus}
end
local function linger_particles(pos, d, texture, color)
@ -55,23 +55,53 @@ minetest.register_globalstep(function(dtime)
end
linger_particles(pos, d, texture, vals.color)
-- Extinguish fire if water bottle
if vals.is_water then
if mcl_potions._extinguish_nearby_fire(pos, d) then
vals.timer = vals.timer - 3.25
end
-- -- Extinguish fire if water bottle
-- if vals.is_water then
-- if mcl_potions._extinguish_nearby_fire(pos, d) then
-- vals.timer = vals.timer - 3.25
-- end
-- end
if vals.def.while_lingering and vals.def.while_lingering(pos, d, vals.potency+1) then
vals.timer = vals.timer - 3.25
end
-- Affect players and mobs
for _, obj in pairs(minetest.get_objects_inside_radius(pos, d)) do
local entity = obj:get_luaentity()
if obj:is_player() or entity.is_mob then
if obj:is_player() or entity and entity.is_mob then
local applied = false
if vals.def._effect_list then
local ef_level
local dur
for name, details in pairs(vals.def._effect_list) do
if details.uses_level then
ef_level = details.level + details.level_scaling * (vals.potency)
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, vals.plus)
if vals.potency>0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, vals.potency)
end
dur = dur * mcl_potions.LINGERING_FACTOR
else
dur = details.dur
end
if mcl_potions.give_effect_by_level(name, obj, ef_level, dur) then
applied = true
end
end
end
vals.def.potion_fun(obj)
-- TODO: Apply timer penalty only if the potion effect was acutally applied
vals.timer = vals.timer - 3.25
if vals.def.custom_effect
and vals.def.custom_effect(obj, (vals.potency+1) * mcl_potions.LINGERING_FACTOR) then
applied = true
end
if applied then vals.timer = vals.timer - 3.25 end
end
end
@ -87,31 +117,44 @@ end)
function mcl_potions.register_lingering(name, descr, color, def)
local id = "mcl_potions:"..name.."_lingering"
local longdesc = def.longdesc
local longdesc = def._longdesc
if not def.no_effect then
longdesc = S("A throwable potion that will shatter on impact, where it creates a magic cloud that lingers around for a while. Any player or mob inside the cloud will receive the potion's effect, possibly repeatedly.")
longdesc = S("A throwable potion that will shatter on impact, where it creates a magic cloud that lingers around for a while. Any player or mob inside the cloud will receive the potion's effect or set of effects, possibly repeatedly.")
if def.longdesc then
longdesc = longdesc .. "\n" .. def.longdesc
longdesc = longdesc .. "\n" .. def._longdesc
end
end
local groups = {brewitem=1, bottle=1, ling_potion=1, _mcl_potion=1}
if def.nocreative then groups.not_in_creative_inventory = 1 end
minetest.register_craftitem(id, {
description = descr,
_tt_help = def.tt,
_tt_help = def._tt,
_dynamic_tt = def._dynamic_tt,
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = S("Use the “Punch” key to throw it."),
stack_max = def.stack_max,
_effect_list = def._effect_list,
uses_level = def.uses_level,
has_potent = def.has_potent,
has_plus = def.has_plus,
_default_potent_level = def._default_potent_level,
_default_extend_level = def._default_extend_level,
inventory_image = lingering_image(color),
groups = {brewitem=1, not_in_creative_inventory=0, bottle=1},
groups = groups,
on_use = function(item, placer, pointed_thing)
local velocity = 10
local dir = placer:get_look_dir();
local pos = placer:getpos();
minetest.sound_play("mcl_throwing_throw", {pos = pos, gain = 0.4, max_hear_distance = 16}, true)
local obj = minetest.add_entity({x=pos.x+dir.x,y=pos.y+2+dir.y,z=pos.z+dir.z}, id.."_flying")
obj:setvelocity({x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity})
obj:setacceleration({x=dir.x*-3, y=-9.8, z=dir.z*-3})
obj:get_luaentity()._thrower = placer:get_player_name()
obj:set_velocity({x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity})
obj:set_acceleration({x=dir.x*-3, y=-9.8, z=dir.z*-3})
local ent = obj:get_luaentity()
ent._thrower = placer:get_player_name()
ent._potency = item:get_meta():get_int("mcl_potions:potion_potent")
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
if not minetest.is_creative_enabled(placer:get_player_name()) then
item:take_item()
end
@ -126,6 +169,10 @@ function mcl_potions.register_lingering(name, descr, color, def)
local velocity = 22
obj:set_velocity({x=dropdir.x*velocity,y=dropdir.y*velocity,z=dropdir.z*velocity})
obj:set_acceleration({x=dropdir.x*-3, y=-9.8, z=dropdir.z*-3})
local ent = obj:get_luaentity()
ent._potency = item:get_meta():get_int("mcl_potions:potion_potent")
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
end
})
@ -148,7 +195,9 @@ function mcl_potions.register_lingering(name, descr, color, def)
end
if n ~= "air" and n ~= "mcl_portals:portal" and n ~= "mcl_portals:portal_end" and g == 0 or mcl_potions.is_obj_hit(self, pos) then
minetest.sound_play("mcl_potions_breaking_glass", {pos = pos, max_hear_distance = 16, gain = 1})
add_lingering_effect(pos, color, def, name == "water")
local potency = self._potency or 0
local plus = self._plus or 0
add_lingering_effect(pos, color, def, name == "water", potency, plus)
local texture
if name == "water" then
texture = "mcl_particles_droplet_bottle.png"
@ -160,9 +209,7 @@ function mcl_potions.register_lingering(name, descr, color, def)
end
end
linger_particles(pos, d, texture, color)
if name == "water" then
mcl_potions._extinguish_nearby_fire(pos, d)
end
if def.on_splash then def.on_splash(pos, potency+1) end
self.object:remove()
end
end,

View File

@ -1,5 +1,4 @@
local S = minetest.get_translator(minetest.get_current_modname())
--local brewhelp = S("Try different combinations to create potions.")
local function potion_image(colorstring, opacity)
if not opacity then
@ -9,7 +8,7 @@ local function potion_image(colorstring, opacity)
end
local how_to_drink = S("Use the “Place” key to drink it.")
local potion_intro = S("Drinking a potion gives you a particular effect.")
local potion_intro = S("Drinking a potion gives you a particular effect or set of effects.")
local function time_string(dur)
if not dur then
@ -90,320 +89,266 @@ function return_on_use(def, effect, dur)
end
end
local function register_potion(def)
local dur = mcl_potions.DURATION
if def.is_inv then
dur = dur * mcl_potions.INV_FACTOR
end
if def.name == "poison" or def.name == "regeneration" or def.name == "withering" then
dur = 45
end
local on_use = nil
if def.on_use then
on_use = return_on_use(def, def.effect, dur)
end
local function get_tt(tt, effect, dur)
local _tt
if effect and def.is_dur then
_tt = perc_string(effect).." | "..time_string(dur)
if def.name == "poison" or def.name == "regeneration" or def.name == "withering" then
_tt = S("1 HP/@1s | @2", effect, time_string(dur))
local function generate_on_use(effects, color, on_use, custom_effect)
return function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
if user and not user:get_player_control().sneak then
local node = minetest.get_node(pointed_thing.under)
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
end
end
elseif def.name == "healing" or def.name == "harming" then
_tt = S("@1 HP", effect)
else
_tt = tt or time_string(dur) or S("No effect")
elseif pointed_thing.type == "object" then
return itemstack
end
return _tt
end
local function get_splash_fun(effect, sp_dur)
if def.is_dur then
return function(player, redx) def.on_use(player, effect, sp_dur*redx) end
elseif def.effect then
return function(player, redx) def.on_use(player, effect*redx, sp_dur) end
local potency = itemstack:get_meta():get_int("mcl_potions:potion_potent")
local plus = itemstack:get_meta():get_int("mcl_potions:potion_plus")
local ef_level
local dur
for name, details in pairs(effects) do
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency>0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end
mcl_potions.give_effect_by_level(name, user, ef_level, dur)
end
-- covers case of no effect (water, awkward, mundane)
return function() end
end
local function get_lingering_fun(effect, ling_dur)
if def.is_dur then
return function(player) def.on_use(player, effect, ling_dur) end
elseif def.effect then
return function(player) def.on_use(player, effect*0.5, ling_dur) end
end
-- covers case of no effect (water, awkward, mundane)
return function() end
end
if on_use then on_use(user, potency+1) end
if custom_effect then custom_effect(user, potency+1) end
local function get_arrow_fun(effect, dur)
if def.is_dur then
return function(player) def.on_use(player, effect, dur) end
elseif def.effect then
return function(player) def.on_use(player, effect, dur) end
end
-- covers case of no effect (water, awkward, mundane)
return function() end
end
itemstack = minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, user, pointed_thing)
if itemstack then mcl_potions._use_potion(user, color) end
local desc
if not def.no_potion then
if def.description_potion then
desc = def.description_potion
else
desc = S("@1 Potion", def.description)
end
return itemstack
end
end
-- API - registers a potion
-- required parameters in def:
-- name - string - potion name in code
-- optional parameters in def:
-- desc_prefix - translated string - part of visible potion name, comes before the word "Potion"
-- desc_suffix - translated string - part of visible potion name, comes after the word "Potion"
-- _tt - translated string - custom tooltip text
-- _dynamic_tt - function(level) - returns custom tooltip text dependent on potion level
-- _longdesc - translated string - text for in-game documentation
-- stack_max - int - max stack size - defaults to 1
-- image - string - name of a custom texture of the potion icon
-- color - string - colorstring for potion icon when image is not defined - defaults to #0000FF
-- groups - table - item groups definition for the regular potion, not splash or lingering -
-- - must contain _mcl_potion=1 for tooltip to include dynamic_tt and effects
-- - defaults to {brewitem=1, food=3, can_eat_when_full=1, _mcl_potion=1}
-- nocreative - bool - adds a not_in_creative_inventory=1 group - defaults to false
-- _effect_list - table - all the effects dealt by the potion in the format of tables
-- -- the name of each sub-table should be a name of a registered effect, and fields can be the following:
-- -- -- uses_level - bool - whether the level of the potion affects the level of the effect -
-- -- -- - defaults to the uses_factor field of the effect definition
-- -- -- level - int - used as the effect level if uses_level is false and for lvl1 potions - defaults to 1
-- -- -- level_scaling - int - used as the number of effect levels added per potion level - defaults to 1 -
-- -- -- - this has no effect if uses_level is false
-- -- -- dur - float - duration of the effect in seconds - defaults to mcl_potions.DURATION
-- -- -- dur_variable - bool - whether variants of the potion should have the length of this effect changed -
-- -- -- - defaults to true
-- -- -- - if at least one effect has this set to true, the potion has a "plus" variant
-- uses_level - bool - whether the potion should come at different levels -
-- - defaults to true if uses_level is true for at least one effect, else false
-- drinkable - bool - defaults to true
-- has_splash - bool - defaults to true
-- has_lingering - bool - defaults to true
-- has_arrow - bool - defaults to false
-- has_potent - bool - whether there is a potent (e.g. II) variant - defaults to the value of uses_level
-- default_potent_level - int - potion level used for the default potent variant - defaults to 2
-- default_extend_level - int - extention level (amount of +) used for the default extended variant - defaults to 1
-- custom_on_use - function(user, level) - called when the potion is drunk, returns true on success
-- custom_effect - function(object, level) - called when the potion effects are applied, returns true on success
-- custom_splash_effect - function(pos, level) - called when the splash potion explodes, returns true on success
-- custom_linger_effect - function(pos, radius, level) - called on the lingering potion step, returns true on success
function mcl_potions.register_potion(def)
local modname = minetest.get_current_modname()
local name = def.name
if name == nil then
error("Unable to register potion: name is nil")
end
if type(name) ~= "string" then
error("Unable to register potion: name is not a string")
end
local pdef = {}
if def.desc_prefix and def.desc_suffix then
pdef.description = S("@1 Potion @2", def.desc_prefix, def.desc_suffix)
elseif def.desc_prefix then
pdef.description = S("@1 Potion", def.desc_prefix)
elseif def.desc_suffix then
pdef.description = S("Potion @1", def.desc_suffix)
else
desc = def.description
pdef.description = S("Strange Potion")
end
pdef._tt_help = def._tt
pdef._dynamic_tt = def._dynamic_tt
local potion_longdesc = def._longdesc
if not def.no_effect then
if def._effect_list then
potion_longdesc = potion_intro .. "\n" .. def._longdesc
end
local potion_usagehelp
local basic_potion_tt
if def.name ~= "dragon_breath" then
potion_usagehelp = how_to_drink
basic_potion_tt = get_tt(def._tt, def.effect, dur)
end
pdef._doc_items_longdesc = potion_longdesc
if def.drinkable ~= false then pdef._doc_items_usagehelp = how_to_drink end
pdef.stack_max = def.stack_max or 1
local color = def.color or "#0000FF"
pdef.inventory_image = def.image or potion_image(color)
pdef.wield_image = pdef.inventory_image
pdef.groups = def.groups or {brewitem=1, food=3, can_eat_when_full=1, _mcl_potion=1}
if def.nocreative then pdef.groups.not_in_creative_inventory = 1 end
minetest.register_craftitem("mcl_potions:"..def.name, {
description = desc,
_tt_help = basic_potion_tt,
_doc_items_longdesc = potion_longdesc,
_doc_items_usagehelp = potion_usagehelp,
stack_max = def.stack_max or 1,
inventory_image = def.image or potion_image(def.color),
wield_image = def.image or potion_image(def.color),
groups = def.groups or {brewitem=1, food=3, can_eat_when_full=1, bottle=1},
on_place = on_use,
on_secondary_use = on_use,
})
-- Register Splash and Lingering
local splash_dur = dur * mcl_potions.SPLASH_FACTOR
local ling_dur = dur * mcl_potions.LINGERING_FACTOR
local splash_def = {
tt = get_tt(def._tt, def.effect, splash_dur),
longdesc = def._longdesc,
potion_fun = get_splash_fun(def.effect, splash_dur),
no_effect = def.no_effect,
instant = def.instant,
}
local ling_def
if def.name == "healing" or def.name == "harming" then
ling_def = {
tt = get_tt(def._tt, def.effect*mcl_potions.LINGERING_FACTOR, ling_dur),
longdesc = def._longdesc,
potion_fun = get_lingering_fun(def.effect*mcl_potions.LINGERING_FACTOR, ling_dur),
no_effect = def.no_effect,
instant = def.instant,
}
else
ling_def = {
tt = get_tt(def._tt, def.effect, ling_dur),
longdesc = def._longdesc,
potion_fun = get_lingering_fun(def.effect, ling_dur),
no_effect = def.no_effect,
instant = def.instant,
}
end
local arrow_def = {
tt = get_tt(def._tt, def.effect, dur/8.),
longdesc = def._longdesc,
potion_fun = get_arrow_fun(def.effect, dur/8.),
no_effect = def.no_effect,
instant = def.instant,
}
if def.color and not def.no_throwable then
local desc
if def.description_splash then
desc = def.description_splash
else
desc = S("Splash @1 Potion", def.description)
end
mcl_potions.register_splash(def.name, desc, def.color, splash_def)
if def.description_lingering then
desc = def.description_lingering
else
desc = S("Lingering @1 Potion", def.description)
end
mcl_potions.register_lingering(def.name, desc, def.color, ling_def)
if not def.no_arrow then
mcl_potions.register_arrow(def.name, S("Arrow of @1", def.description), def.color, arrow_def)
end
end
if def.is_II then
local desc_mod = S(" II")
local effect_II
if def.name == "healing" or def.name == "harming" then
effect_II = def.effect*mcl_potions.II_FACTOR
elseif def.name == "poison" or def.name == "regeneration" then
effect_II = 1.2
elseif def.name == "withering" then
effect_II = 2
else
effect_II = def.effect^mcl_potions.II_FACTOR
end
local dur_2 = dur / mcl_potions.II_FACTOR
if def.name == "poison" then dur_2 = dur_2 - 1 end
if def.name == "slowness" then
dur_2 = 20
effect_II = 0.40
desc_mod = S(" IV")
end
on_use = return_on_use(def, effect_II, dur_2)
minetest.register_craftitem("mcl_potions:"..def.name.."_2", {
description = S("@1 Potion@2", def.description, desc_mod),
_tt_help = get_tt(def._tt_2, effect_II, dur_2),
_doc_items_longdesc = potion_longdesc,
_doc_items_usagehelp = potion_usagehelp,
stack_max = def.stack_max or 1,
inventory_image = def.image or potion_image(def.color),
wield_image = def.image or potion_image(def.color),
groups = def.groups or {brewitem=1, food=3, can_eat_when_full=1, bottle=1},
on_place = on_use,
on_secondary_use = on_use,
})
-- Register Splash and Lingering
local splash_dur_2 = dur_2 * mcl_potions.SPLASH_FACTOR
local ling_dur_2 = dur_2 * mcl_potions.LINGERING_FACTOR
local splash_def_2
if def.name == "healing" then
splash_def_2 = {
tt = get_tt(def._tt_2, 7, splash_dur_2),
longdesc = def._longdesc,
potion_fun = get_splash_fun(7, splash_dur_2),
no_effect = def.no_effect,
instant = def.instant,
}
else
splash_def_2 = {
tt = get_tt(def._tt_2, effect_II, splash_dur_2),
longdesc = def._longdesc,
potion_fun = get_splash_fun(effect_II, splash_dur_2),
no_effect = def.no_effect,
instant = def.instant,
}
end
local ling_def_2
if def.name == "healing" or def.name == "harming" then
ling_def_2 = {
tt = get_tt(def._tt_2, effect_II*mcl_potions.LINGERING_FACTOR, ling_dur_2),
longdesc = def._longdesc,
potion_fun = get_lingering_fun(effect_II*mcl_potions.LINGERING_FACTOR, ling_dur_2),
no_effect = def.no_effect,
instant = def.instant,
}
else
ling_def_2 = {
tt = get_tt(def._tt_2, effect_II, ling_dur_2),
longdesc = def._longdesc,
potion_fun = get_lingering_fun(effect_II, ling_dur_2),
no_effect = def.no_effect,
instant = def.instant,
}
end
local arrow_def_2 = {
tt = get_tt(def._tt_2, effect_II, dur_2/8.),
longdesc = def._longdesc,
potion_fun = get_arrow_fun(effect_II, dur_2/8.),
no_effect = def.no_effect,
instant = def.instant,
}
if def.color and not def.no_throwable then
mcl_potions.register_splash(def.name.."_2", S("Splash @1@2 Potion", def.description, desc_mod), def.color, splash_def_2)
mcl_potions.register_lingering(def.name.."_2", S("Lingering @1@2 Potion", def.description, desc_mod), def.color, ling_def_2)
if not def.no_arrow then
mcl_potions.register_arrow(def.name.."_2", S("Arrow of @1@2", def.description, desc_mod), def.color, arrow_def_2)
pdef._effect_list = {}
local effect
local uses_level = false
local has_plus = false
if def._effect_list then
for name, details in pairs(def._effect_list) do
effect = mcl_potions.registered_effects[name]
if effect then
local ulvl
if details.uses_level ~= nil then ulvl = details.uses_level
else ulvl = effect.uses_factor end
if ulvl then uses_level = true end
local durvar = true
if details.dur_variable ~= nil then durvar = details.dur_variable end
if durvar then has_plus = true end
pdef._effect_list[name] = {
uses_level = ulvl,
level = details.level or 1,
level_scaling = details.level_scaling or 1,
dur = details.dur or mcl_potions.DURATION,
dur_variable = durvar,
}
else
error("Unable to register potion: effect not registered")
end
end
end
if def.uses_level ~= nil then uses_level = def.uses_level end
pdef.uses_level = uses_level
if def.has_potent ~= nil then pdef.has_potent = def.has_potent
else pdef.has_potent = uses_level end
pdef._default_potent_level = def.default_potent_level or 2
pdef._default_extend_level = def.default_extend_level or 1
pdef.has_plus = has_plus
local on_use
if def.drinkable ~= false then
on_use = generate_on_use(pdef._effect_list, color, def.custom_on_use, def.custom_effect)
end
pdef.on_place = on_use
pdef.on_secondary_use = on_use
minetest.register_craftitem(modname..":"..name, pdef)
if def.has_splash or def.has_splash == nil then
local splash_desc = S("Splash @1", pdef.description)
local sdef = {}
sdef._tt = def._tt
sdef._dynamic_tt = def._dynamic_tt
sdef._longdesc = def._longdesc
sdef.nocreative = def.nocreative
sdef.stack_max = pdef.stack_max
sdef._effect_list = pdef._effect_list
sdef.uses_level = uses_level
sdef.has_potent = pdef.has_potent
sdef.has_plus = has_plus
sdef._default_potent_level = pdef._default_potent_level
sdef._default_extend_level = pdef._default_extend_level
sdef.custom_effect = def.custom_effect
sdef.on_splash = def.custom_splash_effect
if not def._effect_list then sdef.instant = true end
mcl_potions.register_splash(name, splash_desc, color, sdef)
end
if def.is_plus then
local dur_pl = dur * mcl_potions.PLUS_FACTOR
if def.name == "poison" or def.name == "regeneration" or def.name == "withering" then
dur_pl = 90
end
on_use = return_on_use(def, def.effect, dur_pl)
minetest.register_craftitem("mcl_potions:"..def.name.."_plus", {
description = S("@1 + Potion", def.description),
_tt_help = get_tt(def._tt_plus, def.effect, dur_pl),
_doc_items_longdesc = potion_longdesc,
_doc_items_usagehelp = potion_usagehelp,
stack_max = 1,
inventory_image = def.image or potion_image(def.color),
wield_image = def.image or potion_image(def.color),
groups = def.groups or {brewitem=1, food=3, can_eat_when_full=1, bottle=1},
on_place = on_use,
on_secondary_use = on_use,
})
-- Register Splash
local splash_dur_pl = dur_pl * mcl_potions.SPLASH_FACTOR
local ling_dur_pl = dur_pl * mcl_potions.LINGERING_FACTOR
local splash_def_pl = {
tt = get_tt(def._tt_plus, def.effect, splash_dur_pl),
longdesc = def._longdesc,
potion_fun = get_splash_fun(def.effect, splash_dur_pl),
no_effect = def.no_effect,
instant = def.instant,
}
local ling_def_pl = {
tt = get_tt(def._tt_plus, def.effect, ling_dur_pl),
longdesc = def._longdesc,
potion_fun = get_lingering_fun(def.effect, ling_dur_pl),
no_effect = def.no_effect,
instant = def.instant,
}
local arrow_def_pl = {
tt = get_tt(def._tt_pl, def.effect, dur_pl/8.),
longdesc = def._longdesc,
potion_fun = get_arrow_fun(def.effect, dur_pl/8.),
no_effect = def.no_effect,
instant = def.instant,
}
if def.color and not def.no_throwable then
mcl_potions.register_splash(def.name.."_plus", S("Splash @1 + Potion", def.description), def.color, splash_def_pl)
mcl_potions.register_lingering(def.name.."_plus", S("Lingering @1 + Potion", def.description), def.color, ling_def_pl)
if not def.no_arrow then
mcl_potions.register_arrow(def.name.."_plus", S("Arrow of @1 +", def.description), def.color, arrow_def_pl)
end
end
if def.has_lingering or def.has_lingering == nil then
local ling_desc = S("Lingering @1", pdef.description)
local ldef = {}
ldef._tt = def._tt
ldef._dynamic_tt = def._dynamic_tt
ldef._longdesc = def._longdesc
ldef.nocreative = def.nocreative
ldef.stack_max = pdef.stack_max
ldef._effect_list = pdef._effect_list
ldef.uses_level = uses_level
ldef.has_potent = pdef.has_potent
ldef.has_plus = has_plus
ldef._default_potent_level = pdef._default_potent_level
ldef._default_extend_level = pdef._default_extend_level
ldef.custom_effect = def.custom_effect
ldef.on_splash = def.custom_splash_effect
ldef.while_lingering = def.custom_linger_effect
if not def._effect_list then ldef.instant = true end
mcl_potions.register_lingering(name, ling_desc, color, ldef)
end
if def.has_arrow then
local arr_desc
if def.desc_prefix and def.desc_suffix then
arr_desc = S("@1 Arrow @2", def.desc_prefix, def.desc_suffix)
elseif def.desc_prefix then
arr_desc = S("@1 Arrow", def.desc_prefix)
elseif def.desc_suffix then
arr_desc = S("Arrow @1", def.desc_suffix)
else
arr_desc = S("Strange Tipped Arrow")
end
local adef = {}
adef._tt = def._tt
adef._dynamic_tt = def._dynamic_tt
adef._longdesc = def._longdesc
adef.nocreative = def.nocreative
adef._effect_list = pdef._effect_list
adef.uses_level = uses_level
adef.has_potent = pdef.has_potent
adef.has_plus = has_plus
adef._default_potent_level = pdef._default_potent_level
adef._default_extend_level = pdef._default_extend_level
adef.custom_effect = def.custom_effect
if not def._effect_list then adef.instant = true end
mcl_potions.register_arrow(name, arr_desc, color, adef)
end
end
mcl_potions.register_potion({
name = "trolling",
desc_prefix = S("Mighty"),
desc_suffix = S("of Trolling"),
_tt = "trololo",
_dynamic_tt = function(level)
return "trolololoooololo"
end,
_longdesc = "Trolololololo",
stack_max = 2,
color = "#00AA00",
nocreative = true,
_effect_list = {
night_vision = {},
strength = {},
swiftness = {
uses_level = false,
level = 2,
},
poison = {
dur = 10,
},
},
default_potent_level = 5,
default_extend_level = 3,
custom_splash_effect = mcl_potions._extinguish_nearby_fire,
has_arrow = true,
})
-- ██████╗░░█████╗░████████╗██╗░█████╗░███╗░░██╗
-- ██╔══██╗██╔══██╗╚══██╔══╝██║██╔══██╗████╗░██║
@ -420,225 +365,187 @@ end
-- ╚═════╝░╚══════╝╚═╝░░░░░╚═╝╚═╝░░╚══╝╚═╝░░░╚═╝░░░╚═╝░╚════╝░╚═╝░░╚══╝╚═════╝░
local awkward_def = {
name = "awkward",
description_potion = S("Awkward Potion"),
description_splash = S("Awkward Splash Potion"),
description_lingering = S("Awkward Lingering Potion"),
no_arrow = true,
no_effect = true,
_tt = S("No effect"),
_longdesc = S("Has an awkward taste and is used for brewing potions."),
color = "#0000FF",
groups = {brewitem=1, food=3, can_eat_when_full=1, bottle=1},
on_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
}
local mundane_def = {
name = "mundane",
description_potion = S("Mundane Potion"),
description_splash = S("Mundane Splash Potion"),
description_lingering = S("Mundane Lingering Potion"),
no_arrow = true,
no_effect = true,
_tt = S("No effect"),
_longdesc = S("Has a terrible taste and is not useful for brewing potions."),
color = "#0000FF",
on_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
}
local thick_def = {
name = "thick",
description_potion = S("Thick Potion"),
description_splash = S("Thick Splash Potion"),
description_lingering = S("Thick Lingering Potion"),
no_arrow = true,
no_effect = true,
_tt = S("No effect"),
_longdesc = S("Has a bitter taste and is not useful for brewing potions."),
color = "#0000FF",
on_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
}
local dragon_breath_def = {
name = "dragon_breath",
minetest.register_craftitem("mcl_potions:dragon_breath", {
description = S("Dragon's Breath"),
no_arrow = true,
no_potion = true,
no_throwable = true,
no_effect = true,
_longdesc = S("This item is used in brewing and can be combined with splash potions to create lingering potions."),
image = "mcl_potions_dragon_breath.png",
groups = { brewitem = 1, bottle = 1 },
on_use = nil,
stack_max = 64,
}
})
local healing_def = {
mcl_potions.register_potion({
name = "awkward",
desc_prefix = S("Awkward"),
_tt = S("No effect"),
_longdesc = S("Has an awkward taste and is used for brewing potions."),
color = "#0000FF",
})
mcl_potions.register_potion({
name = "mundane",
desc_prefix = S("Mundane"),
_tt = S("No effect"),
_longdesc = S("Has a terrible taste and is not really useful for brewing potions."),
color = "#0000FF",
})
mcl_potions.register_potion({
name = "thick",
desc_prefix = S("Thick"),
_tt = S("No effect"),
_longdesc = S("Has a bitter taste and is not really useful for brewing potions."),
color = "#0000FF",
})
mcl_potions.register_potion({
name = "healing",
description = S("Healing"),
_tt = S("+4 HP"),
_tt_2 = S("+8 HP"),
desc_suffix = S("of Healing"),
_dynamic_tt = function(level)
return S("+@1 HP", 4 * level)
end,
_longdesc = S("Instantly heals."),
color = "#F82423",
effect = 4,
instant = true,
on_use = mcl_potions.healing_func,
is_II = true,
}
uses_level = true,
has_arrow = true,
custom_effect = function(object, level)
return mcl_potions.healing_func(object, 4 * level)
end,
})
local harming_def = {
mcl_potions.register_potion({
name = "harming",
description = S("Harming"),
_tt = S("-6 HP"),
_tt_II = S("-12 HP"),
desc_suffix = S("of Harming"),
_dynamic_tt = function(level)
return S("-@1 HP", 6 * level)
end,
_longdesc = S("Instantly deals damage."),
color = "#430A09",
effect = -6,
instant = true,
on_use = mcl_potions.healing_func,
is_II = true,
is_inv = true,
}
uses_level = true,
has_arrow = true,
custom_effect = function(object, level)
return mcl_potions.healing_func(object, -6 * level)
end,
})
local night_vision_def = {
mcl_potions.register_potion({
name = "night_vision",
description = S("Night Vision"),
desc_suffix = S("of Night Vision"),
_tt = nil,
_longdesc = S("Increases the perceived brightness of light under a dark sky."),
color = "#1F1FA1",
effect = nil,
is_dur = true,
on_use = mcl_potions.night_vision_func,
is_plus = true,
}
_effect_list = {
night_vision = {},
},
has_arrow = true,
})
local swiftness_def = {
mcl_potions.register_potion({
name = "swiftness",
description = S("Swiftness"),
desc_suffix = S("of Swiftness"),
_tt = nil,
_longdesc = S("Increases walking speed."),
color = "#7CAFC6",
effect = 1.2,
is_dur = true,
on_use = mcl_potions.swiftness_func,
is_II = true,
is_plus = true,
}
_effect_list = {
swiftness = {},
},
has_arrow = true,
})
local slowness_def = {
mcl_potions.register_potion({
name = "slowness",
description = S("Slowness"),
desc_suffix = S("of Slowness"),
_tt = nil,
_longdesc = S("Decreases walking speed."),
color = "#5A6C81",
effect = 0.85,
is_dur = true,
on_use = mcl_potions.swiftness_func,
is_II = true,
is_plus = true,
is_inv = true,
}
_effect_list = {
slowness = {dur=mcl_potions.DURATION_INV},
},
has_arrow = true,
})
local leaping_def = {
mcl_potions.register_potion({
name = "leaping",
description = S("Leaping"),
desc_suffix = S("of Leaping"),
_tt = nil,
_longdesc = S("Increases jump strength."),
color = "#22FF4C",
effect = 1.15,
is_dur = true,
on_use = mcl_potions.leaping_func,
is_II = true,
is_plus = true,
}
_effect_list = {
leaping = {},
},
has_arrow = true,
})
local withering_def = {
mcl_potions.register_potion({
name = "withering",
description = S("Withering"),
desc_suffix = S("of Withering"),
_tt = nil,
_longdesc = S("Applies the withering effect which deals damage at a regular interval and can kill."),
color = "#000000",
effect = 4,
is_dur = true,
on_use = mcl_potions.withering_func,
is_II = true,
is_plus = true,
is_inv = true,
}
_effect_list = {
withering = {dur=mcl_potions.DURATION_POISON},
},
has_arrow = true,
})
local poison_def = {
mcl_potions.register_potion({
name = "poison",
description = S("Poison"),
desc_suffix = S("of Poison"),
_tt = nil,
_longdesc = S("Applies the poison effect which deals damage at a regular interval."),
color = "#4E9331",
effect = 2.5,
is_dur = true,
on_use = mcl_potions.poison_func,
is_II = true,
is_plus = true,
is_inv = true,
}
_effect_list = {
poison = {dur=mcl_potions.DURATION_POISON},
},
has_arrow = true,
})
local regeneration_def = {
mcl_potions.register_potion({
name = "regeneration",
description = S("Regeneration"),
desc_suffix = S("of Regeneration"),
_tt = nil,
_longdesc = S("Regenerates health over time."),
color = "#CD5CAB",
effect = 2.5,
is_dur = true,
on_use = mcl_potions.regeneration_func,
is_II = true,
is_plus = true,
}
_effect_list = {
regeneration = {dur=mcl_potions.DURATION_POISON},
},
has_arrow = true,
})
local invisibility_def = {
mcl_potions.register_potion({
name = "invisibility",
description = S("Invisibility"),
desc_suffix = S("of Invisibility"),
_tt = nil,
_longdesc = S("Grants invisibility."),
color = "#7F8392",
is_dur = true,
on_use = mcl_potions.invisiblility_func,
is_plus = true,
}
_effect_list = {
invisibility = {},
},
has_arrow = true,
})
local water_breathing_def = {
mcl_potions.register_potion({
name = "water_breathing",
description = S("Water Breathing"),
desc_suffix = S("of Water Breathing"),
_tt = nil,
_longdesc = S("Grants limitless breath underwater."),
color = "#2E5299",
is_dur = true,
on_use = mcl_potions.water_breathing_func,
is_plus = true,
}
_effect_list = {
water_breathing = {},
},
has_arrow = true,
})
local fire_resistance_def = {
mcl_potions.register_potion({
name = "fire_resistance",
description = S("Fire Resistance"),
desc_suffix = S("of Fire Resistance"),
_tt = nil,
_longdesc = S("Grants immunity to damage from heat sources like fire."),
color = "#E49A3A",
is_dur = true,
on_use = mcl_potions.fire_resistance_func,
is_plus = true,
}
local defs = { awkward_def, mundane_def, thick_def, dragon_breath_def,
healing_def, harming_def, night_vision_def, swiftness_def,
slowness_def, leaping_def, withering_def, poison_def, regeneration_def,
invisibility_def, water_breathing_def, fire_resistance_def}
for _, def in ipairs(defs) do
register_potion(def)
end
_effect_list = {
fire_resistance = {},
},
has_arrow = true,
})

View File

@ -13,20 +13,30 @@ end
function mcl_potions.register_splash(name, descr, color, def)
local id = "mcl_potions:"..name.."_splash"
local longdesc = def.longdesc
local longdesc = def._longdesc
if not def.no_effect then
longdesc = S("A throwable potion that will shatter on impact, where it gives all nearby players and mobs a status effect.")
if def.longdesc then
longdesc = longdesc .. "\n" .. def.longdesc
longdesc = S("A throwable potion that will shatter on impact, where it gives all nearby players and mobs a status effect or a set of status effects.")
if def._longdesc then
longdesc = longdesc .. "\n" .. def._longdesc
end
end
local groups = {brewitem=1, bottle=1, splash_potion=1, _mcl_potion=1}
if def.nocreative then groups.not_in_creative_inventory = 1 end
minetest.register_craftitem(id, {
description = descr,
_tt_help = def.tt,
_tt_help = def._tt,
_dynamic_tt = def._dynamic_tt,
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = S("Use the “Punch” key to throw it."),
stack_max = def.stack_max,
_effect_list = def._effect_list,
uses_level = def.uses_level,
has_potent = def.has_potent,
has_plus = def.has_plus,
_default_potent_level = def._default_potent_level,
_default_extend_level = def._default_extend_level,
inventory_image = splash_image(color),
groups = {brewitem=1, not_in_creative_inventory=0, bottle=1},
groups = groups,
on_use = function(item, placer, pointed_thing)
local velocity = 10
local dir = placer:get_look_dir();
@ -35,7 +45,11 @@ function mcl_potions.register_splash(name, descr, color, def)
local obj = minetest.add_entity({x=pos.x+dir.x,y=pos.y+2+dir.y,z=pos.z+dir.z}, id.."_flying")
obj:set_velocity({x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity})
obj:set_acceleration({x=dir.x*-3, y=-9.8, z=dir.z*-3})
obj:get_luaentity()._thrower = placer:get_player_name()
local ent = obj:get_luaentity()
ent._thrower = placer:get_player_name()
ent._potency = item:get_meta():get_int("mcl_potions:potion_potent")
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
if not minetest.is_creative_enabled(placer:get_player_name()) then
item:take_item()
end
@ -50,6 +64,10 @@ function mcl_potions.register_splash(name, descr, color, def)
local velocity = 22
obj:set_velocity({x=dropdir.x*velocity,y=dropdir.y*velocity,z=dropdir.z*velocity})
obj:set_acceleration({x=dropdir.x*-3, y=-9.8, z=dropdir.z*-3})
local ent = obj:get_luaentity()
ent._potency = item:get_meta():get_int("mcl_potions:potion_potent")
ent._plus = item:get_meta():get_int("mcl_potions:potion_plus")
ent._effect_list = def._effect_list
end
})
@ -103,10 +121,10 @@ function mcl_potions.register_splash(name, descr, color, def)
texture = texture.."^[colorize:"..color..":127"
})
if name == "water" then
mcl_potions._extinguish_nearby_fire(pos)
end
self.object:remove()
local potency = self._potency or 0
local plus = self._plus or 0
if def.on_splash then def.on_splash(pos, potency+1) end
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 4)) do
local entity = obj:get_luaentity()
@ -114,13 +132,44 @@ function mcl_potions.register_splash(name, descr, color, def)
local pos2 = obj:get_pos()
local rad = math.floor(math.sqrt((pos2.x-pos.x)^2 + (pos2.y-pos.y)^2 + (pos2.z-pos.z)^2))
if rad > 0 then
def.potion_fun(obj, redux_map[rad])
else
def.potion_fun(obj, 1)
if def._effect_list then
local ef_level
local dur
for name, details in pairs(def._effect_list) do
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency>0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
dur = dur * mcl_potions.SPLASH_FACTOR
else
dur = details.dur
end
if rad > 0 then
mcl_potions.give_effect_by_level(name, obj, ef_level, redux_map[rad]*dur)
else
mcl_potions.give_effect_by_level(name, obj, ef_level, dur)
end
end
end
if def.custom_effect then
local power = (potency+1) * mcl_potions.SPLASH_FACTOR
if rad > 0 then
def.custom_effect(obj, redux_map[rad] * power)
else
def.custom_effect(obj, power)
end
end
end
end
self.object:remove()
end
end,

View File

@ -37,16 +37,26 @@ local arrow_tt = minetest.registered_items["mcl_bows:arrow"]._tt_help or ""
function mcl_potions.register_arrow(name, desc, color, def)
local longdesc = def.longdesc or ""
local longdesc = def._longdesc or ""
local tt = def._tt or ""
local groups = {ammo=1, ammo_bow=1, brewitem=1, _mcl_potion=1}
if def.nocreative then groups.not_in_creative_inventory = 1 end
minetest.register_craftitem("mcl_potions:"..name.."_arrow", {
description = desc,
_tt_help = arrow_tt .. "\n" .. def.tt,
_tt_help = arrow_tt .. "\n" .. tt,
_dynamic_tt = def._dynamic_tt,
_doc_items_longdesc = arrow_longdesc .. "\n" ..
S("This particular arrow is tipped and will give an effect when it hits a player or mob.") .. "\n" ..
longdesc,
_doc_items_usagehelp = how_to_shoot,
_effect_list = def._effect_list,
uses_level = def.uses_level,
has_potent = def.has_potent,
has_plus = def.has_plus,
_default_potent_level = def._default_potent_level,
_default_extend_level = def._default_extend_level,
inventory_image = "mcl_bows_arrow_inv.png^(mcl_potions_arrow_inv.png^[colorize:"..color..":100)",
groups = { ammo=1, ammo_bow=1, brewitem=1},
groups = groups,
_on_dispense = function(itemstack, dispenserpos, droppos, dropnode, dropdir)
-- Shoot arrow
local shootpos = vector.add(dispenserpos, vector.multiply(dropdir, 0.51))
@ -264,6 +274,9 @@ function mcl_potions.register_arrow(name, desc, color, def)
end
end
local potency = self._potency or 0
local plus = self._plus or 0
-- Punch target object but avoid hurting enderman.
if lua then
if lua.name ~= "mobs_mc:enderman" then
@ -271,14 +284,59 @@ function mcl_potions.register_arrow(name, desc, color, def)
full_punch_interval=1.0,
damage_groups={fleshy=self._damage},
}, nil)
def.potion_fun(obj)
if def._effect_list then
local ef_level
local dur
for name, details in pairs(def._effect_list) do
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency>0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end
mcl_potions.give_effect_by_level(name, obj, ef_level, dur)
end
end
if def.custom_effect then def.custom_effect(obj, potency+1) end
end
else
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=self._damage},
}, nil)
def.potion_fun(obj)
if def._effect_list then
local ef_level
local dur
for name, details in pairs(def._effect_list) do
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency>0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end
dur = dur * mcl_potions.SPLASH_FACTOR
if rad > 0 then
mcl_potions.give_effect_by_level(name, obj, ef_level, redux_map[rad]*dur)
else
mcl_potions.give_effect_by_level(name, obj, ef_level, dur)
end
end
end
if def.custom_effect then def.custom_effect(obj, potency+1) end
end
if is_player then

View File

@ -75,7 +75,7 @@ minetest.register_on_respawnplayer(function(player)
mcl_fovapi.remove_all_modifiers(player)
end)
function mcl_fovapi.apply_modifier(player, modifier_name)
function mcl_fovapi.apply_modifier(player, modifier_name, time_override)
if not player or not modifier_name then
return
end
@ -106,13 +106,14 @@ function mcl_fovapi.apply_modifier(player, modifier_name)
minetest.log("FOV::Modifier applied to player:" .. player_name .. " modifier: " .. modifier_name)
end
local time = time_override or modifier.time
-- modifier apply code.
if modifier.exclusive == true then
-- if exclusive, reset the player's fov, and apply the new fov.
if modifier.is_multiplier then
player:set_fov(0, false, 0)
end
player:set_fov(modifier.fov_factor, modifier.is_multiplier, modifier.time)
player:set_fov(modifier.fov_factor, modifier.is_multiplier, time)
else
-- not exclusive? let's apply it in the mix.
local fov_factor, is_mult = player:get_fov()
@ -126,15 +127,15 @@ function mcl_fovapi.apply_modifier(player, modifier_name)
fov_factor = (fov_factor + modifier.fov_factor) / 2
end
if modifier.is_multiplier and is_mult then
player:set_fov(fov_factor, true, modifier.time)
player:set_fov(fov_factor, true, time)
else
player:set_fov(fov_factor, false, modifier.time)
player:set_fov(fov_factor, false, time)
end
end
end
function mcl_fovapi.remove_modifier(player, modifier_name)
function mcl_fovapi.remove_modifier(player, modifier_name, time_override)
if not player or not modifier_name then
return
end
@ -159,9 +160,10 @@ function mcl_fovapi.remove_modifier(player, modifier_name)
applied[k] = mcl_fovapi.registered_modifiers[k]
end
local time = time_override or modifier.reset_time
local elem = next
if elem(applied) == nil then
player:set_fov(0, false, modifier.reset_time)
player:set_fov(0, false, time)
return
end
local exc = false
@ -191,7 +193,7 @@ function mcl_fovapi.remove_modifier(player, modifier_name)
fov_factor = fov_factor * x.fov_factor
end
end
player:set_fov(fov_factor, not non_multiplier_added, modifier.reset_time)
player:set_fov(fov_factor, not non_multiplier_added, time)
end
if mcl_fovapi.registered_modifiers[modifier_name].on_end then

View File

@ -99,7 +99,7 @@ function mcl_hunger.reset_bars_poison_hunger(player)
end
end
-- Poison player
-- Poison player TODO remove this function
local function poisonp(tick, time, time_left, damage, exhaustion, name)
if not mcl_hunger.active then
return
@ -186,15 +186,8 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
do_poison = true
end
if do_poison then
-- Set food poison bars
if exhaust and exhaust > 0 then
hb.change_hudbar(user, "hunger", nil, nil, "mcl_hunger_icon_foodpoison.png", nil, "mcl_hunger_bar_foodpoison.png")
if mcl_hunger.debug then
hb.change_hudbar(user, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_foodpoison.png")
end
mcl_hunger.poison_hunger[name] = mcl_hunger.poison_hunger[name] + 1
end
poisonp(1, poisontime, 0, poison, exhaust, user:get_player_name())
local level = mcl_potions.get_effect_level(user, "food_poisoning")
mcl_potions.give_effect_by_level("food_poisoning", user, level+exhaust, poisontime)
end
end

View File

@ -232,13 +232,13 @@ minetest.register_globalstep(function(dtime)
food_tick_timer = 0
-- let hunger work always
if player_health > 0 and player_health <= 20 then
if player_health > 0 then
--mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_HUNGER) -- later for hunger status effect
mcl_hunger.update_exhaustion_hud(player)
end
if food_level >= 18 then -- slow regeneration
if player_health > 0 and player_health < 20 then
if player_health > 0 and player_health < player:get_properties().hp_max then
player:set_hp(player_health+1)
mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN)
mcl_hunger.update_exhaustion_hud(player)
@ -255,7 +255,7 @@ minetest.register_globalstep(function(dtime)
end
elseif food_tick_timer > max_tick_timer and food_level == 20 and food_saturation_level > 0 then -- fast regeneration
if player_health > 0 and player_health < 20 then
if player_health > 0 and player_health < player:get_properties().hp_max then
food_tick_timer = 0
player:set_hp(player_health+1)
mcl_hunger.exhaust(player_name, mcl_hunger.EXHAUST_REGEN)

View File

@ -1,7 +1,7 @@
-- Apply food poisoning effect as long there are no real status effect.
-- TODO: Remove this when food poisoning a status effect in mcl_potions.
-- TODO: Sanitize this now that Food Poisoning is now an effect in mcl_potions
-- Normal poison damage is set to 0 because it's handled elsewhere.
mcl_hunger.register_food("mcl_mobitems:rotten_flesh", 4, "", 30, 0, 100, 80)
mcl_hunger.register_food("mcl_mobitems:chicken", 2, "", 30, 0, 100, 30)
mcl_hunger.register_food("mcl_fishing:pufferfish_raw", 1, "", 15, 0, 300)
mcl_hunger.register_food("mcl_mobitems:rotten_flesh", 4, "", 30, 0, 1, 80)
mcl_hunger.register_food("mcl_mobitems:chicken", 2, "", 30, 0, 1, 30)
mcl_hunger.register_food("mcl_fishing:pufferfish_raw", 1, "", 15, 0, 3)

View File

@ -76,13 +76,16 @@ else
end
function mcl_meshhand.update_player(player)
local hand
if mcl_skins_enabled then
local node_id = mcl_skins.get_node_id_by_player(player)
player:get_inventory():set_stack("hand", 1, "mcl_meshhand:" .. node_id)
hand = ItemStack("mcl_meshhand:" .. node_id)
else
local creative = minetest.is_creative_enabled(player:get_player_name())
player:get_inventory():set_stack("hand", 1, "mcl_meshhand:hand" .. (creative and "_crea" or "_surv"))
hand = ItemStack("mcl_meshhand:hand" .. (creative and "_crea" or "_surv"))
end
if not mcl_potions then player:get_inventory():set_stack("hand", 1, hand) end
player:get_inventory():set_stack("hand", 1, mcl_potions.hf_update_internal(hand, player))
end
minetest.register_on_joinplayer(function(player)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 B

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B