2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2020-12-14 14:08:55 +01:00
2020-11-01 13:44:05 +01:00
-- Taken from https://minecraft.gamepedia.com/Enchanting
2020-11-13 12:21:36 +01:00
local function increase_damage ( damage_group , factor )
return function ( itemstack , level )
local tool_capabilities = itemstack : get_tool_capabilities ( )
tool_capabilities.damage_groups [ damage_group ] = ( tool_capabilities.damage_groups [ damage_group ] or 0 ) + level * factor
itemstack : get_meta ( ) : set_tool_capabilities ( tool_capabilities )
end
end
2020-11-09 18:59:08 +01:00
-- implemented via on_enchant and additions in mobs_mc; Slowness IV part unimplemented
mcl_enchanting.enchantments . bane_of_arthropods = {
2020-12-14 14:08:55 +01:00
name = S ( " Bane of Arthropods " ) ,
2020-11-01 13:44:05 +01:00
max_level = 5 ,
primary = { sword = true } ,
secondary = { axe = true } ,
disallow = { } ,
2021-01-06 19:04:04 +01:00
incompatible = { smite = true , sharpness = true } ,
2020-11-01 13:44:05 +01:00
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases damage and applies Slowness IV to arthropod mobs (spiders, cave spiders, silverfish and endermites). " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
2020-11-09 18:59:08 +01:00
on_enchant = increase_damage ( " anthropod " , 2.5 ) ,
2020-11-01 13:44:05 +01:00
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 5 , 25 } , { 13 , 33 } , { 21 , 41 } , { 29 , 49 } , { 37 , 57 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-25 12:47:27 +01:00
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.channeling = {
2020-12-14 14:08:55 +01:00
name = S ( " Channeling " ) ,
2020-11-25 12:47:27 +01:00
max_level = 1 ,
primary = { trident = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { riptide = true } ,
weight = 1 ,
2020-12-14 14:08:55 +01:00
description = S ( " Channels a bolt of lightning toward a target. Works only during thunderstorms and if target is unobstructed with opaque blocks. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 25 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-25 12:47:27 +01:00
} ] ] --
2020-11-01 13:44:05 +01:00
-- implemented in mcl_death_drop
mcl_enchanting.enchantments . curse_of_vanishing = {
2020-12-14 14:08:55 +01:00
name = S ( " Curse of Vanishing " ) ,
2020-11-01 13:44:05 +01:00
max_level = 1 ,
primary = { } ,
secondary = { armor_head = true , armor_torso = true , armor_legs = true , armor_feet = true , tool = true , weapon = true } ,
2020-11-25 12:47:27 +01:00
disallow = { } ,
2020-11-01 13:44:05 +01:00
incompatible = { } ,
weight = 1 ,
2020-12-14 14:08:55 +01:00
description = S ( " Item destroyed on death. " ) ,
2020-11-01 13:44:05 +01:00
curse = true ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = true ,
power_range_table = { { 25 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}
2021-02-27 16:35:59 +01:00
-- implemented in mcl_playerplus
mcl_enchanting.enchantments . depth_strider = {
2020-12-14 14:08:55 +01:00
name = S ( " Depth Strider " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { } ,
secondary = { armor_feet = true } ,
disallow = { non_combat_armor = true } ,
incompatible = { frost_walker = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases underwater movement speed. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 10 , 25 } , { 20 , 35 } , { 30 , 45 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-02-27 16:35:59 +01:00
}
2020-11-01 13:44:05 +01:00
2020-11-02 13:38:17 +01:00
-- implemented via on_enchant
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . efficiency = {
2020-12-14 14:08:55 +01:00
name = S ( " Efficiency " ) ,
2020-11-01 13:44:05 +01:00
max_level = 5 ,
primary = { pickaxe = true , shovel = true , axe = true , hoe = true } ,
secondary = { shears = true } ,
disallow = { } ,
incompatible = { } ,
weight = 10 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases mining speed. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
2022-02-12 19:41:22 +01:00
on_enchant = function ( )
-- Updating digging speed is handled by update_groupcaps which
-- is called from load_enchantments.
2020-11-02 13:38:17 +01:00
end ,
2020-11-01 13:44:05 +01:00
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 1 , 61 } , { 11 , 71 } , { 21 , 81 } , { 31 , 91 } , { 41 , 101 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = false ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}
2021-01-02 10:56:40 +01:00
-- implemented in mcl_mobs and via register_on_punchplayer callback
2021-01-01 19:51:31 +01:00
mcl_enchanting.enchantments . fire_aspect = {
2020-12-14 14:08:55 +01:00
name = S ( " Fire Aspect " ) ,
2020-11-01 13:44:05 +01:00
max_level = 2 ,
primary = { sword = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Sets target on fire. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 10 , 61 } , { 30 , 71 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-01-01 19:51:31 +01:00
}
minetest.register_on_punchplayer ( function ( player , hitter , time_from_last_punch , tool_capabilities , dir , damage )
if hitter and hitter : is_player ( ) then
local wielditem = hitter : get_wielded_item ( )
if wielditem then
local fire_aspect_level = mcl_enchanting.get_enchantment ( wielditem , " fire_aspect " )
if fire_aspect_level > 0 then
2023-12-14 09:12:13 +01:00
local player_pos = player : get_pos ( )
local hitter_pos = hitter : get_pos ( )
if vector.distance ( hitter_pos , player_pos ) <= 3 then
mcl_burning.set_on_fire ( player , fire_aspect_level * 4 )
end
2021-01-01 19:51:31 +01:00
end
end
end
end )
2020-11-01 13:44:05 +01:00
2021-01-27 20:11:02 +01:00
mcl_enchanting.enchantments . flame = {
2020-12-14 14:08:55 +01:00
name = S ( " Flame " ) ,
2020-11-01 13:44:05 +01:00
max_level = 1 ,
primary = { bow = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Arrows set target on fire. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 20 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-01-27 20:11:02 +01:00
}
2020-11-01 13:44:05 +01:00
2020-11-06 15:05:31 +01:00
-- implemented in mcl_item_entity
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . fortune = {
2020-12-14 14:08:55 +01:00
name = S ( " Fortune " ) ,
2020-11-25 12:47:27 +01:00
max_level = 3 ,
2020-11-01 13:44:05 +01:00
primary = { pickaxe = true , shovel = true , axe = true , hoe = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { silk_touch = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases certain block drops. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 15 , 61 } , { 24 , 71 } , { 33 , 81 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = false ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}
2020-11-06 13:46:52 +01:00
-- implemented via walkover.register_global
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . frost_walker = {
2020-12-14 14:08:55 +01:00
name = S ( " Frost Walker " ) ,
2020-11-01 13:44:05 +01:00
max_level = 2 ,
primary = { } ,
secondary = { armor_feet = true } ,
disallow = { non_combat_armor = true } ,
incompatible = { depth_strider = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Turns water beneath the player into frosted ice and prevents the damage from magma blocks. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = true ,
power_range_table = { { 10 , 25 } , { 20 , 35 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-05 16:05:42 +01:00
walkover.register_global ( function ( pos , _ , player )
local boots = player : get_inventory ( ) : get_stack ( " armor " , 5 )
local frost_walker = mcl_enchanting.get_enchantment ( boots , " frost_walker " )
if frost_walker <= 0 then
return
end
2024-06-11 19:17:12 +02:00
-- 1011 = sqrt(4096000)/2; 4096000 is the max number of nodes for find_nodes_in_area_under_air
local radius = math.min ( frost_walker + 2 , 1011 )
2020-11-05 16:05:42 +01:00
local minp = { x = pos.x - radius , y = pos.y , z = pos.z - radius }
local maxp = { x = pos.x + radius , y = pos.y , z = pos.z + radius }
local positions = minetest.find_nodes_in_area_under_air ( minp , maxp , " mcl_core:water_source " )
for _ , p in ipairs ( positions ) do
if vector.distance ( pos , p ) <= radius then
minetest.set_node ( p , { name = " mcl_core:frosted_ice_0 " } )
end
end
end )
2020-11-25 12:47:27 +01:00
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.impaling = {
2020-12-14 14:08:55 +01:00
name = S ( " Impaling " ) ,
2020-11-25 12:47:27 +01:00
max_level = 5 ,
primary = { trident = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Trident deals additional damage to ocean mobs. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 1 , 21 } , { 9 , 29 } , { 17 , 37 } , { 25 , 45 } , { 33 , 53 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-25 12:47:27 +01:00
} ] ] --
2020-11-01 13:44:05 +01:00
-- implemented in mcl_bows
mcl_enchanting.enchantments . infinity = {
2020-12-14 14:08:55 +01:00
name = S ( " Infinity " ) ,
2020-11-01 13:44:05 +01:00
max_level = 1 ,
primary = { bow = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { mending = true } ,
weight = 1 ,
2020-12-14 14:08:55 +01:00
description = S ( " Shooting consumes no regular arrows. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 20 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-04 12:00:42 +01:00
-- implemented via minetest.calculate_knockback
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . knockback = {
2020-12-14 14:08:55 +01:00
name = S ( " Knockback " ) ,
2020-11-01 13:44:05 +01:00
max_level = 2 ,
primary = { sword = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases knockback. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 5 , 61 } , { 25 , 71 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-04 12:00:42 +01:00
local old_calculate_knockback = minetest.calculate_knockback
function minetest . calculate_knockback ( player , hitter , time_from_last_punch , tool_capabilities , dir , distance , damage )
local knockback = old_calculate_knockback ( player , hitter , time_from_last_punch , tool_capabilities , dir , distance , damage )
2020-11-06 15:05:31 +01:00
local luaentity
if hitter then
luaentity = hitter : get_luaentity ( )
end
2023-12-13 21:36:54 +01:00
if hitter and hitter : is_player ( ) and distance <= 3 then
2020-11-04 12:00:42 +01:00
local wielditem = hitter : get_wielded_item ( )
2023-12-16 10:46:18 +01:00
--knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback")
local enchant = mcl_enchanting.get_enchantment ( wielditem , " knockback " )
knockback = knockback + 3.22 * enchant
2023-12-14 08:46:16 +01:00
-- add vertical lift to knockback
2023-12-13 18:42:42 +01:00
local v = player : get_velocity ( )
2023-12-17 18:48:39 +01:00
local added_v = 0
2023-12-15 16:52:26 +01:00
local invul = player : get_meta ( ) : get_int ( " mcl_damage:invulnerable " )
2023-12-15 22:02:07 +01:00
if v and v.y <= 0.01 and v.y >= - 0.01 and invul == 0 then
2023-12-16 13:58:58 +01:00
local regular_v = 6.4
local enchant_v = 7
regular_v = regular_v * math.abs ( dir.y - 1 )
enchant_v = enchant_v * math.abs ( dir.y - 1 )
if enchant == 0 then
player : add_velocity ( { x = 0 , y = regular_v , z = 0 } )
2023-12-17 17:39:04 +01:00
added_v = regular_v
2023-12-16 13:58:58 +01:00
else
player : add_velocity ( { x = 0 , y = enchant_v , z = 0 } )
2023-12-17 17:39:04 +01:00
added_v = enchant_v
2023-12-15 17:27:09 +01:00
end
2023-12-14 08:46:16 +01:00
-- add minimum knockback
if knockback <= 1.5 then
2023-12-14 10:27:28 +01:00
knockback = knockback + 4.875
2023-12-19 17:49:48 +01:00
elseif knockback <= 6.19 then
knockback = knockback + 0.609375
2023-12-14 08:46:16 +01:00
end
end
2023-12-20 16:50:37 +01:00
-- counteract forward velocity when hit
local self_dir_dot = ( v.x * dir.x ) + ( v.z * dir.z )
if self_dir_dot < 0 then
player : add_velocity ( { x = v.x * - 1 , y = 0 , z = v.z * - 1 } )
end
2023-12-14 08:46:16 +01:00
-- add player velocity to knockback
2023-12-19 17:15:41 +01:00
local h_name = hitter : get_player_name ( )
2023-11-28 03:34:26 +01:00
local hv = hitter : get_velocity ( )
local dir_dot = ( hv.x * dir.x ) + ( hv.z * dir.z )
2023-12-13 18:42:42 +01:00
local hitter_mag = math.sqrt ( ( hv.x * hv.x ) + ( hv.z * hv.z ) )
2023-12-19 17:15:41 +01:00
if dir_dot > 0 and mcl_sprint.is_sprinting ( h_name ) then
2023-12-16 10:20:29 +01:00
knockback = knockback + hitter_mag * 0.6875
2023-12-19 17:15:41 +01:00
elseif dir_dot > 0 then
2023-12-19 18:19:09 +01:00
knockback = knockback + hitter_mag * 0.515625
2023-12-14 12:57:55 +01:00
end
2023-12-17 18:48:39 +01:00
-- reduce floatiness
minetest.after ( 0.25 , function ( )
2023-12-18 22:42:26 +01:00
player : add_velocity ( { x = 0 , y = ( v.y + added_v ) * - 0.375 , z = 0 } )
2023-12-17 18:48:39 +01:00
end )
2023-12-18 22:42:26 +01:00
-- reduce knockback when moving towards hitter while attacking
local self_dir_dot = ( v.x * dir.x ) + ( v.z * dir.z )
local control = player : get_player_control ( )
if self_dir_dot < - 4.3 and control.up and control.LMB then
knockback = knockback * 0.6
end
2023-12-15 16:52:26 +01:00
-- remove knockback if invulnerable
if invul > 0 then
knockback = 0
end
2023-12-13 21:36:54 +01:00
elseif hitter and hitter : is_player ( ) and distance > 3 then
knockback = 0
2020-11-06 15:05:31 +01:00
elseif luaentity and luaentity._knockback then
2023-11-28 04:35:42 +01:00
local kb = knockback + luaentity._knockback / 4
local punch_dir = dir
punch_dir.y = 0
punch_dir = vector.normalize ( punch_dir ) * kb
punch_dir.y = 4
player : add_velocity ( punch_dir )
knockback = 0
2020-11-04 12:00:42 +01:00
end
return knockback
end
2021-01-02 21:42:07 +01:00
-- implemented in mcl_mobs and mobs_mc
2020-12-23 17:41:42 +01:00
mcl_enchanting.enchantments . looting = {
2020-12-14 14:08:55 +01:00
name = S ( " Looting " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { sword = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases mob loot. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 15 , 61 } , { 24 , 71 } , { 33 , 81 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-12-23 17:41:42 +01:00
}
2020-11-25 12:47:27 +01:00
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.loyalty = {
2020-12-14 14:08:55 +01:00
name = S ( " Loyalty " ) ,
2020-11-25 12:47:27 +01:00
max_level = 3 ,
primary = { trident = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { riptide = true } ,
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Trident returns after being thrown. Higher levels reduce return time. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 12 , 50 } , { 19 , 50 } , { 26 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-25 12:47:27 +01:00
} ] ] --
2020-11-01 13:44:05 +01:00
2020-12-23 17:41:42 +01:00
-- implemented in mcl_fishing
2020-12-23 15:18:20 +01:00
mcl_enchanting.enchantments . luck_of_the_sea = {
2020-12-14 14:08:55 +01:00
name = S ( " Luck of the Sea " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { fishing_rod = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases rate of good loot (enchanting books, etc.) " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 15 , 61 } , { 24 , 71 } , { 33 , 81 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = false ,
inv_tool_tab = true ,
2020-12-23 15:18:20 +01:00
}
2020-11-01 13:44:05 +01:00
2020-11-09 18:59:08 +01:00
-- implemented in mcl_fishing
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . lure = {
2020-12-14 14:08:55 +01:00
name = S ( " Lure " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { fishing_rod = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Decreases time until rod catches something. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 15 , 61 } , { 24 , 71 } , { 33 , 81 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = false ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}
2020-12-21 15:12:24 +01:00
-- implemented in mcl_experience
mcl_enchanting.enchantments . mending = {
2020-12-14 14:08:55 +01:00
name = S ( " Mending " ) ,
2020-11-01 13:44:05 +01:00
max_level = 1 ,
primary = { } ,
secondary = { armor_head = true , armor_torso = true , armor_legs = true , armor_feet = true , tool = true , weapon = true } ,
2020-11-01 14:23:43 +01:00
disallow = { } ,
2020-11-01 13:44:05 +01:00
incompatible = { infinity = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Repair the item while gaining XP orbs. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = true ,
2020-11-25 12:47:27 +01:00
treasure = true ,
power_range_table = { { 25 , 75 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = true ,
2020-12-21 15:12:24 +01:00
}
2020-11-25 12:47:27 +01:00
2021-11-03 19:36:57 +01:00
mcl_experience.register_on_add_xp ( function ( player , xp )
local inv = player : get_inventory ( )
local candidates = {
{ list = " main " , index = player : get_wield_index ( ) } ,
{ list = " armor " , index = 2 } ,
{ list = " armor " , index = 3 } ,
{ list = " armor " , index = 4 } ,
{ list = " armor " , index = 5 } ,
2022-03-15 15:58:27 +01:00
{ list = " offhand " , index = 1 } ,
2021-11-03 19:36:57 +01:00
}
local final_candidates = { }
for _ , can in ipairs ( candidates ) do
local stack = inv : get_stack ( can.list , can.index )
local wear = stack : get_wear ( )
if mcl_enchanting.has_enchantment ( stack , " mending " ) and wear > 0 then
can.stack = stack
can.wear = wear
table.insert ( final_candidates , can )
end
end
if # final_candidates > 0 then
local can = final_candidates [ math.random ( # final_candidates ) ]
local stack , list , index , wear = can.stack , can.list , can.index , can.wear
local uses = mcl_util.calculate_durability ( stack )
local multiplier = 2 * 65535 / uses
local repair = xp * multiplier
local new_wear = wear - repair
if new_wear < 0 then
xp = math.floor ( - new_wear / multiplier + 0.5 )
new_wear = 0
else
xp = 0
end
stack : set_wear ( math.floor ( new_wear ) )
2024-05-22 20:55:07 +02:00
tt.reload_itemstack_description ( stack ) -- update tooltip
2021-11-03 19:36:57 +01:00
inv : set_stack ( list , index , stack )
end
return xp
end , 0 )
2021-10-15 21:00:37 +02:00
mcl_enchanting.enchantments . multishot = {
2020-12-14 14:08:55 +01:00
name = S ( " Multishot " ) ,
2020-11-25 12:47:27 +01:00
max_level = 1 ,
primary = { crossbow = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { piercing = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Shoot 3 arrows at the cost of one. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 20 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-10-15 21:00:37 +02:00
}
2020-11-25 12:47:27 +01:00
-- requires missing MineClone2 feature
2021-10-15 21:00:37 +02:00
mcl_enchanting.enchantments . piercing = {
2020-12-14 14:08:55 +01:00
name = S ( " Piercing " ) ,
2020-11-25 12:47:27 +01:00
max_level = 4 ,
primary = { crossbow = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { multishot = true } ,
weight = 10 ,
2020-12-14 14:08:55 +01:00
description = S ( " Arrows passes through multiple objects. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 1 , 50 } , { 11 , 50 } , { 21 , 50 } , { 31 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-10-15 21:00:37 +02:00
}
2020-11-01 13:44:05 +01:00
2020-11-05 15:25:44 +01:00
-- implemented in mcl_bows
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . power = {
2020-12-14 14:08:55 +01:00
name = S ( " Power " ) ,
2020-11-01 13:44:05 +01:00
max_level = 5 ,
2020-11-25 12:47:27 +01:00
primary = { bow = true } ,
secondary = { } ,
2020-11-01 13:44:05 +01:00
disallow = { } ,
incompatible = { } ,
weight = 10 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases arrow damage. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 1 , 16 } , { 11 , 26 } , { 21 , 36 } , { 31 , 46 } , { 41 , 56 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-06 15:05:31 +01:00
-- implemented via minetest.calculate_knockback (together with the Knockback enchantment) and mcl_bows
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . punch = {
2020-12-14 14:08:55 +01:00
name = S ( " Punch " ) ,
2020-11-01 13:44:05 +01:00
max_level = 2 ,
primary = { } ,
secondary = { bow = true } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases arrow knockback. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 12 , 37 } , { 32 , 57 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-25 12:47:27 +01:00
-- requires missing MineClone2 feature
2021-10-15 21:00:37 +02:00
mcl_enchanting.enchantments . quick_charge = {
2020-12-14 14:08:55 +01:00
name = S ( " Quick Charge " ) ,
2020-11-25 12:47:27 +01:00
max_level = 3 ,
primary = { crossbow = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Decreases crossbow charging time. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 12 , 50 } , { 32 , 50 } , { 52 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2021-10-15 21:00:37 +02:00
}
2020-11-25 12:47:27 +01:00
2020-11-01 13:44:05 +01:00
-- unimplemented
2020-11-25 12:47:27 +01:00
--[[mcl_enchanting.enchantments.respiration = {
2020-12-14 14:08:55 +01:00
name = S ( " Respiration " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { armor_head = true } ,
secondary = { } ,
disallow = { non_combat_armor = true } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Extends underwater breathing time. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 10 , 40 } , { 20 , 50 } , { 30 , 60 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-25 12:47:27 +01:00
} ] ] --
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.riptide = {
2020-12-14 14:08:55 +01:00
name = S ( " Riptide " ) ,
2020-11-25 12:47:27 +01:00
max_level = 3 ,
primary = { trident = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { channeling = true , loyalty = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Trident launches player with itself when thrown. Works only in water or rain. " ) ,
2020-11-25 12:47:27 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
treasure = false ,
power_range_table = { { 17 , 50 } , { 24 , 50 } , { 31 , 50 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-25 12:47:27 +01:00
} ] ] --
2020-11-01 13:44:05 +01:00
2020-11-02 17:58:13 +01:00
-- implemented via on_enchant
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . sharpness = {
2020-12-14 14:08:55 +01:00
name = S ( " Sharpness " ) ,
2020-11-01 13:44:05 +01:00
max_level = 5 ,
primary = { sword = true } ,
secondary = { axe = true } ,
disallow = { } ,
2020-11-09 18:59:08 +01:00
incompatible = { bane_of_arthropods = true , smite = true } ,
2020-11-01 13:44:05 +01:00
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases damage. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
2020-11-09 18:59:08 +01:00
on_enchant = increase_damage ( " fleshy " , 0.5 ) ,
2020-11-01 13:44:05 +01:00
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 1 , 21 } , { 12 , 32 } , { 23 , 43 } , { 34 , 54 } , { 45 , 65 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-02 19:09:23 +01:00
-- implemented in mcl_item_entity
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . silk_touch = {
2020-12-14 14:08:55 +01:00
name = S ( " Silk Touch " ) ,
2020-11-01 13:44:05 +01:00
max_level = 1 ,
primary = { pickaxe = true , shovel = true , axe = true , hoe = true } ,
secondary = { shears = true } ,
disallow = { } ,
incompatible = { fortune = true } ,
weight = 1 ,
2020-12-14 14:08:55 +01:00
description = S ( " Mined blocks drop themselves. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 15 , 61 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = false ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}
2020-11-09 18:59:08 +01:00
-- implemented via on_enchant and additions in mobs_mc
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . smite = {
2020-12-14 14:08:55 +01:00
name = S ( " Smite " ) ,
2020-11-01 13:44:05 +01:00
max_level = 5 ,
primary = { sword = true } ,
secondary = { axe = true } ,
disallow = { } ,
2020-11-09 18:59:08 +01:00
incompatible = { bane_of_arthropods = true , sharpness = true } ,
2020-11-01 13:44:05 +01:00
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases damage to undead mobs. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
2020-11-09 18:59:08 +01:00
on_enchant = increase_damage ( " undead " , 2.5 ) ,
2020-11-01 13:44:05 +01:00
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 5 , 25 } , { 13 , 33 } , { 21 , 41 } , { 29 , 49 } , { 37 , 57 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-09 10:50:27 +01:00
-- implemented in mcl_playerplus
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . soul_speed = {
2020-12-14 14:08:55 +01:00
name = S ( " Soul Speed " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { } ,
secondary = { armor_feet = true } ,
disallow = { non_combat_armor = true } ,
incompatible = { frost_walker = true } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases walking speed on soul sand. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = true ,
power_range_table = { { 10 , 25 } , { 20 , 35 } , { 30 , 45 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-01 13:44:05 +01:00
}
2020-11-02 17:58:13 +01:00
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.sweeping_edge = {
2020-12-14 14:08:55 +01:00
name = S ( " Sweeping Edge " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { sword = true } ,
secondary = { } ,
disallow = { } ,
incompatible = { } ,
weight = 2 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases sweeping attack damage. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
on_enchant = function ( ) end ,
requires_tool = false ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 5 , 20 } , { 14 , 29 } , { 23 , 38 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = false ,
2020-11-02 17:58:13 +01:00
} ] ] --
2020-11-01 13:44:05 +01:00
2020-11-02 17:38:51 +01:00
-- for tools & weapons implemented via on_enchant; for bows implemented in mcl_bows; for armor implemented in mcl_armor and mcl_tt; for fishing rods implemented in mcl_fishing
2020-11-01 13:44:05 +01:00
mcl_enchanting.enchantments . unbreaking = {
2020-12-14 14:08:55 +01:00
name = S ( " Unbreaking " ) ,
2020-11-01 13:44:05 +01:00
max_level = 3 ,
primary = { armor_head = true , armor_torso = true , armor_legs = true , armor_feet = true , pickaxe = true , shovel = true , axe = true , hoe = true , sword = true , fishing_rod = true , bow = true } ,
secondary = { tool = true } ,
disallow = { non_combat_armor = true } ,
incompatible = { } ,
weight = 5 ,
2020-12-14 14:08:55 +01:00
description = S ( " Increases item durability. " ) ,
2020-11-01 13:44:05 +01:00
curse = false ,
2021-01-04 17:53:49 +01:00
on_enchant = function ( itemstack , level )
2021-04-17 23:40:19 +02:00
local name = itemstack : get_name ( )
if not minetest.registered_tools [ name ] . tool_capabilities then
return
2020-11-02 13:38:17 +01:00
end
2021-04-17 23:40:19 +02:00
2020-11-02 17:58:13 +01:00
local tool_capabilities = itemstack : get_tool_capabilities ( )
tool_capabilities.punch_attack_uses = tool_capabilities.punch_attack_uses * ( 1 + level )
itemstack : get_meta ( ) : set_tool_capabilities ( tool_capabilities )
2021-04-17 23:03:57 +02:00
2022-02-12 19:41:22 +01:00
-- Updating digging durability is handled by update_groupcaps
-- which is called from load_enchantments.
2020-11-02 13:38:17 +01:00
end ,
2020-11-01 13:44:05 +01:00
requires_tool = true ,
2020-11-25 12:47:27 +01:00
treasure = false ,
power_range_table = { { 5 , 61 } , { 13 , 71 } , { 21 , 81 } } ,
2021-01-04 13:02:55 +01:00
inv_combat_tab = true ,
inv_tool_tab = true ,
2020-11-01 13:44:05 +01:00
}