1
0
Fork 0

Added Enchanting Table

This commit is contained in:
Lizzy Fleckenstein 2020-11-25 12:47:27 +01:00
parent a3cf6b0e5d
commit ed738da016
25 changed files with 952 additions and 528 deletions

View File

@ -1,5 +0,0 @@
Enchanting for MineClone2
--------------------------
This is a rewrite of the mtg enchanting mod. Beta Version, more features coming soon.
The textures look absolutely shit, but as far as I know I have to use the textures from Pixel Perfection so I dont get trouble with Mocrisoft. There is a version with original textures and sounds, but I can't publish that one. If you'd like to advice me how I can somehow do that anyway, please open an issue or contact me via email (eliasfleckenstein@web.de).

View File

@ -1,9 +0,0 @@
minetest.register_craftitem("mcl_enchanting:book_enchanted", {
description = "Enchanted Book",
inventory_image = "mcl_enchanting_book_enchanted.png^[colorize:purple:50",
groups = {enchanted = 1, not_in_creative_inventory = 1},
_mcl_enchanting_enchanted_tool = "mcl_enchanting:book_enchanted",
stack_max = 1,
})
minetest.registered_items["mcl_books:book"]._mcl_enchanting_enchanted_tool = "mcl_enchanting:book_enchanted"

View File

@ -1,41 +0,0 @@
minetest.register_chatcommand("enchant", {
description = "Enchant an item.",
params = "<player> <enchantment> [<level>]",
privs = {give = true},
func = function(_, param)
local sparam = param:split(" ")
local target_name = sparam[1]
local enchantment = sparam[2]
local level_str = sparam[3]
local level = tonumber(level_str or "1")
if not target_name or not enchantment then
return false, "Usage: /enchant <player> <enchantment> [<level>]"
end
local target = minetest.get_player_by_name(target_name)
if not target then
return false, "Player '" .. target_name .. "' cannot be found"
end
local itemstack = target:get_wielded_item()
local can_enchant, errorstring, extra_info = mcl_enchanting.can_enchant(itemstack, enchantment, level)
if not can_enchant then
if errorstring == "enchantment invalid" then
return false, "There is no such enchantment '" .. enchantment .. "'"
elseif errorstring == "item missing" then
return false, "The target doesn't hold an item"
elseif errorstring == "item not supported" then
return false, "The selected enchantment can't be added to the target item"
elseif errorstring == "level invalid" then
return false, "'" .. level_str .. "' is not a valid number"
elseif errorstring == "level too high" then
return false, "The number you have entered (" .. level_str .. ") is too big, it must be at most " .. extra_info
elseif errorstring == "level too small" then
return false, "The number you have entered (" .. level_str .. ") is too small, it must be at least " .. extra_info
elseif errorstring == "incompatible" then
return false, mcl_enchanting.get_enchantment_description(enchantment, level) .. " can't be combined with " .. extra_info
end
else
target:set_wielded_item(mcl_enchanting.enchant(itemstack, enchantment, level))
return true, "Enchanting succeded"
end
end
})

View File

@ -21,6 +21,8 @@ end
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 41}},
}]]-- }]]--
-- implemented via on_enchant and additions in mobs_mc; Slowness IV part unimplemented -- implemented via on_enchant and additions in mobs_mc; Slowness IV part unimplemented
@ -36,6 +38,8 @@ mcl_enchanting.enchantments.bane_of_arthropods = {
curse = false, curse = false,
on_enchant = increase_damage("anthropod", 2.5), on_enchant = increase_damage("anthropod", 2.5),
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 25}, {13, 33}, {21, 41}, {29, 49}, {37, 57}},
} }
-- implemented in mcl_armor -- implemented in mcl_armor
@ -51,8 +55,27 @@ mcl_enchanting.enchantments.blast_protection = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 13}, {13, 21}, {21, 29}, {29, 37}},
} }
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.channeling = {
name = "Channeling",
max_level = 1,
primary = {trident = true},
secondary = {},
disallow = {},
incompatible = {riptide = true},
weight = 1,
description = "Trident \"channels\" a bolt of lightning toward a hit entity. Functions only during thunderstorms and if target is unobstructed with opaque blocks.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{25, 50}},
}]]--
-- implemented in mcl_armor -- implemented in mcl_armor
mcl_enchanting.enchantments.curse_of_binding = { mcl_enchanting.enchantments.curse_of_binding = {
name = "Curse of Binding", name = "Curse of Binding",
@ -66,6 +89,8 @@ mcl_enchanting.enchantments.curse_of_binding = {
curse = true, curse = true,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = true,
power_range_table = {{25, 50}},
} }
-- implemented in mcl_death_drop -- implemented in mcl_death_drop
@ -74,17 +99,19 @@ mcl_enchanting.enchantments.curse_of_vanishing = {
max_level = 1, max_level = 1,
primary = {}, primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true}, secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {clock = true}, disallow = {},
incompatible = {}, incompatible = {},
weight = 1, weight = 1,
description = "Item destroyed on death.", description = "Item destroyed on death.",
curse = true, curse = true,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = true,
power_range_table = {{25, 50}},
} }
-- unimplemented -- unimplemented
mcl_enchanting.enchantments.depth_strider = { --[[mcl_enchanting.enchantments.depth_strider = {
name = "Depth Strider", name = "Depth Strider",
max_level = 3, max_level = 3,
primary = {}, primary = {},
@ -96,7 +123,9 @@ mcl_enchanting.enchantments.depth_strider = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
} treasure = false,
power_range_table = {{10, 25}, {20, 35}, {30, 45}},
}]]--
-- implemented via on_enchant -- implemented via on_enchant
mcl_enchanting.enchantments.efficiency = { mcl_enchanting.enchantments.efficiency = {
@ -121,6 +150,8 @@ mcl_enchanting.enchantments.efficiency = {
itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_tool_capabilities(tool_capabilities)
end, end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 61}, {11, 71}, {21, 81}, {31, 91}, {41, 101}},
} }
-- implemented in mcl_armor -- implemented in mcl_armor
@ -135,6 +166,8 @@ mcl_enchanting.enchantments.feather_falling = {
description = "Reduces fall damage.",curse = false, description = "Reduces fall damage.",curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 11}, {11, 17}, {17, 23}, {23, 29}},
} }
-- requires missing MineClone2 feature -- requires missing MineClone2 feature
@ -150,6 +183,8 @@ mcl_enchanting.enchantments.feather_falling = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{10, 61}, {30, 71}},
}]]-- }]]--
-- implemented in mcl_armor -- implemented in mcl_armor
@ -165,6 +200,8 @@ mcl_enchanting.enchantments.fire_protection = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{10, 18}, {18, 26}, {26, 34}, {34, 42}},
} }
-- requires missing MineClone2 feature -- requires missing MineClone2 feature
@ -180,12 +217,14 @@ mcl_enchanting.enchantments.fire_protection = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{20, 50}},
}]]-- }]]--
-- implemented in mcl_item_entity -- implemented in mcl_item_entity
mcl_enchanting.enchantments.fortune = { mcl_enchanting.enchantments.fortune = {
name = "Fortune", name = "Fortune",
max_level = 4, max_level = 3,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true}, primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {}, secondary = {},
disallow = {}, disallow = {},
@ -195,6 +234,8 @@ mcl_enchanting.enchantments.fortune = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{15, 61}, {24, 71}, {33, 81}},
} }
-- implemented via walkover.register_global -- implemented via walkover.register_global
@ -210,6 +251,8 @@ mcl_enchanting.enchantments.frost_walker = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = true,
power_range_table = {{10, 25}, {20, 35}},
} }
walkover.register_global(function(pos, _, player) walkover.register_global(function(pos, _, player)
@ -229,6 +272,23 @@ walkover.register_global(function(pos, _, player)
end end
end) end)
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.impaling = {
name = "Impaling",
max_level = 5,
primary = {trident = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Trident deals additional damage to mobs that spawn naturally in the ocean.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{1, 21}, {9, 29}, {17, 37}, {25, 45}, {33, 53}},
}]]--
-- implemented in mcl_bows -- implemented in mcl_bows
mcl_enchanting.enchantments.infinity = { mcl_enchanting.enchantments.infinity = {
name = "Infinity", name = "Infinity",
@ -242,6 +302,8 @@ mcl_enchanting.enchantments.infinity = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{20, 50}},
} }
-- implemented via minetest.calculate_knockback -- implemented via minetest.calculate_knockback
@ -257,6 +319,8 @@ mcl_enchanting.enchantments.knockback = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 61}, {25, 71}},
} }
local old_calculate_knockback = minetest.calculate_knockback local old_calculate_knockback = minetest.calculate_knockback
@ -276,7 +340,7 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
end end
-- unimplemented -- unimplemented
mcl_enchanting.enchantments.looting = { --[[mcl_enchanting.enchantments.looting = {
name = "Looting", name = "Looting",
max_level = 3, max_level = 3,
primary = {sword = true}, primary = {sword = true},
@ -288,10 +352,29 @@ mcl_enchanting.enchantments.looting = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
} treasure = false,
power_range_table = {{15, 61}, {24, 71}, {33, 81}},
}]]--
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.loyalty = {
name = "Loyalty",
max_level = 3,
primary = {trident = true},
secondary = {},
disallow = {},
incompatible = {riptide = true},
weight = 5,
description = "Trident returns after being thrown. Higher levels reduce return time.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{12, 50}, {19, 50}, {26, 50}},
}]]--
-- unimplemented -- unimplemented
mcl_enchanting.enchantments.luck_of_the_sea = { --[[mcl_enchanting.enchantments.luck_of_the_sea = {
name = "Luck of the Sea", name = "Luck of the Sea",
max_level = 3, max_level = 3,
primary = {fishing_rod = true}, primary = {fishing_rod = true},
@ -303,7 +386,9 @@ mcl_enchanting.enchantments.luck_of_the_sea = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
} treasure = false,
power_range_table = {{15, 61}, {24, 71}, {33, 81}},
}]]--
-- implemented in mcl_fishing -- implemented in mcl_fishing
mcl_enchanting.enchantments.lure = { mcl_enchanting.enchantments.lure = {
@ -318,10 +403,12 @@ mcl_enchanting.enchantments.lure = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{15, 61}, {24, 71}, {33, 81}},
} }
-- unimplemented -- unimplemented
mcl_enchanting.enchantments.mending = { --[[mcl_enchanting.enchantments.mending = {
name = "Mending", name = "Mending",
max_level = 1, max_level = 1,
primary = {}, primary = {},
@ -333,14 +420,50 @@ mcl_enchanting.enchantments.mending = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = true, requires_tool = true,
} treasure = true,
power_range_table = {{25, 75}},
}]]--
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.multishot = {
name = "Multishot",
max_level = 1,
primary = {crossbow = true},
secondary = {},
disallow = {},
incompatible = {piercing = true},
weight = 2,
description = "Shoot 3 arrows at the cost of one.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{20, 50}},
}]]--
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.piercing = {
name = "Piercing",
max_level = 4,
primary = {crossbow = true},
secondary = {},
disallow = {},
incompatible = {multishot = true},
weight = 10,
description = "Arrows pass through multiple entities.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{1, 50}, {11, 50}, {21, 50}, {31, 50}},
}]]--
-- implemented in mcl_bows -- implemented in mcl_bows
mcl_enchanting.enchantments.power = { mcl_enchanting.enchantments.power = {
name = "Power", name = "Power",
max_level = 5, max_level = 5,
primary = {}, primary = {bow = true},
secondary = {bow = true}, secondary = {},
disallow = {}, disallow = {},
incompatible = {}, incompatible = {},
weight = 10, weight = 10,
@ -348,6 +471,8 @@ mcl_enchanting.enchantments.power = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 16}, {11, 26}, {21, 36}, {31, 46}, {41, 56}},
} }
-- implemented in mcl_armor -- implemented in mcl_armor
@ -363,6 +488,8 @@ mcl_enchanting.enchantments.projectile_protection = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 16}, {11, 26}, {21, 36}, {31, 46}, {41, 56}},
} }
-- implemented in mcl_armor -- implemented in mcl_armor
@ -378,6 +505,8 @@ mcl_enchanting.enchantments.protection = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 12}, {12, 23}, {23, 34}, {34, 45}},
} }
-- implemented via minetest.calculate_knockback (together with the Knockback enchantment) and mcl_bows -- implemented via minetest.calculate_knockback (together with the Knockback enchantment) and mcl_bows
@ -393,10 +522,29 @@ mcl_enchanting.enchantments.punch = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{12, 37}, {32, 57}},
} }
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.quick_charge = {
name = "Quick Charge",
max_level = 3,
primary = {crossbow = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 5,
description = "Decreases crossbow charging time.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{12, 50}, {32, 50}, {52, 50}},
}]]--
-- unimplemented -- unimplemented
mcl_enchanting.enchantments.respiration = { --[[mcl_enchanting.enchantments.respiration = {
name = "Respiration", name = "Respiration",
max_level = 3, max_level = 3,
primary = {armor_head = true}, primary = {armor_head = true},
@ -408,7 +556,26 @@ mcl_enchanting.enchantments.respiration = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
} treasure = false,
power_range_table = {{10, 40}, {20, 50}, {30, 60}},
}]]--
-- requires missing MineClone2 feature
--[[mcl_enchanting.enchantments.riptide = {
name = "Riptide",
max_level = 3,
primary = {trident = true},
secondary = {},
disallow = {},
incompatible = {channeling = true, loyalty = true},
weight = 2,
description = "Trident launches player with itself when thrown. Functions only in water or rain.",
curse = false,
on_enchant = function() end,
requires_tool = false,
treasure = false,
power_range_table = {{17, 50}, {24, 50}, {31, 50}},
}]]--
-- implemented via on_enchant -- implemented via on_enchant
mcl_enchanting.enchantments.sharpness = { mcl_enchanting.enchantments.sharpness = {
@ -423,6 +590,8 @@ mcl_enchanting.enchantments.sharpness = {
curse = false, curse = false,
on_enchant = increase_damage("fleshy", 0.5), on_enchant = increase_damage("fleshy", 0.5),
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{1, 21}, {12, 32}, {23, 43}, {34, 54}, {45, 65}},
} }
-- implemented in mcl_item_entity -- implemented in mcl_item_entity
@ -438,6 +607,8 @@ mcl_enchanting.enchantments.silk_touch = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{15, 61}},
} }
-- implemented via on_enchant and additions in mobs_mc -- implemented via on_enchant and additions in mobs_mc
@ -453,6 +624,8 @@ mcl_enchanting.enchantments.smite = {
curse = false, curse = false,
on_enchant = increase_damage("undead", 2.5), on_enchant = increase_damage("undead", 2.5),
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 25}, {13, 33}, {21, 41}, {29, 49}, {37, 57}},
} }
-- implemented in mcl_playerplus -- implemented in mcl_playerplus
@ -468,6 +641,8 @@ mcl_enchanting.enchantments.soul_speed = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = true,
power_range_table = {{10, 25}, {20, 35}, {30, 45}},
} }
-- requires missing MineClone2 feature -- requires missing MineClone2 feature
@ -483,6 +658,8 @@ mcl_enchanting.enchantments.soul_speed = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{5, 20}, {14, 29}, {23, 38}},
}]]-- }]]--
-- implemented in mcl_armor -- implemented in mcl_armor
@ -498,6 +675,8 @@ mcl_enchanting.enchantments.thorns = {
curse = false, curse = false,
on_enchant = function() end, on_enchant = function() end,
requires_tool = false, requires_tool = false,
treasure = false,
power_range_table = {{10, 61}, {30, 71}, {50, 81}},
} }
-- 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 -- 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
@ -520,4 +699,6 @@ mcl_enchanting.enchantments.unbreaking = {
itemstack:get_meta():set_tool_capabilities(tool_capabilities) itemstack:get_meta():set_tool_capabilities(tool_capabilities)
end, end,
requires_tool = true, requires_tool = true,
treasure = false,
power_range_table = {{5, 61}, {13, 71}, {21, 81}},
} }

View File

@ -1,3 +1,7 @@
function mcl_enchanting.is_book(itemname)
return itemname == "mcl_books:book" or itemname == "mcl_enchanting:book_enchanted"
end
function mcl_enchanting.get_enchantments(itemstack) function mcl_enchanting.get_enchantments(itemstack)
return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {} return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {}
end end
@ -5,7 +9,7 @@ end
function mcl_enchanting.set_enchantments(itemstack, enchantments) function mcl_enchanting.set_enchantments(itemstack, enchantments)
itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments)) itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
local itemdef = itemstack:get_definition() local itemdef = itemstack:get_definition()
if itemstack:get_name() ~= "mcl_enchanting:book_enchanted" then if not mcl_enchanting.is_book(itemstack:get_name()) then
if itemdef.tool_capabilities then if itemdef.tool_capabilities then
itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities) itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities)
end end
@ -20,9 +24,6 @@ function mcl_enchanting.set_enchantments(itemstack, enchantments)
end end
function mcl_enchanting.get_enchantment(itemstack, enchantment) function mcl_enchanting.get_enchantment(itemstack, enchantment)
if itemstack:get_name() == "mcl_enchanting:book_enchanted" then
return 0
end
return mcl_enchanting.get_enchantments(itemstack)[enchantment] or 0 return mcl_enchanting.get_enchantments(itemstack)[enchantment] or 0
end end
@ -44,22 +45,34 @@ function mcl_enchanting.get_enchanted_itemstring(itemname)
return def and def._mcl_enchanting_enchanted_tool return def and def._mcl_enchanting_enchanted_tool
end end
function mcl_enchanting.is_enchanted_def(itemname) function mcl_enchanting.set_enchanted_itemstring(itemstack)
itemstack:set_name(mcl_enchanting.get_enchanted_itemstring(itemstack:get_name()))
end
function mcl_enchanting.is_enchanted(itemname)
return minetest.get_item_group(itemname, "enchanted") > 0 return minetest.get_item_group(itemname, "enchanted") > 0
end end
function mcl_enchanting.is_enchanted(itemstack) function mcl_enchanting.is_enchantable(itemname)
return mcl_enchanting.is_enchanted_def(itemstack:get_name()) return mcl_enchanting.get_enchantability(itemname) > 0
end
function mcl_enchanting.can_enchant_freshly(itemname)
return mcl_enchanting.is_enchantable(itemname) and not mcl_enchanting.is_enchanted(itemname)
end
function mcl_enchanting.get_enchantability(itemname)
return minetest.get_item_group(itemname, "enchantability")
end end
function mcl_enchanting.item_supports_enchantment(itemname, enchantment, early) function mcl_enchanting.item_supports_enchantment(itemname, enchantment, early)
if itemname == "mcl_enchanting:book_enchanted" then if not mcl_enchanting.is_enchantable(itemname) then
return true, true
end
if not early and not mcl_enchanting.get_enchanted_itemstring(itemname) then
return false return false
end end
local enchantment_def = mcl_enchanting.enchantments[enchantment] local enchantment_def = mcl_enchanting.enchantments[enchantment]
if mcl_enchanting.is_book(itemname) then
return true, (not enchantment_def.treasure)
end
local itemdef = minetest.registered_items[itemname] local itemdef = minetest.registered_items[itemname]
if itemdef.type ~= "tool" and enchantment_def.requires_tool then if itemdef.type ~= "tool" and enchantment_def.requires_tool then
return false return false
@ -91,7 +104,8 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
if itemname == "" then if itemname == "" then
return false, "item missing" return false, "item missing"
end end
if not mcl_enchanting.item_supports_enchantment(itemstack:get_name(), enchantment) then local supported, primary = mcl_enchanting.item_supports_enchantment(itemstack:get_name(), enchantment)
if not supported then
return false, "item not supported" return false, "item not supported"
end end
if not level then if not level then
@ -107,7 +121,7 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
if enchantment_level then if enchantment_level then
return false, "incompatible", mcl_enchanting.get_enchantment_description(enchantment, enchantment_level) return false, "incompatible", mcl_enchanting.get_enchantment_description(enchantment, enchantment_level)
end end
if itemname ~= "mcl_enchanting:book_enchanted" then if not mcl_enchanting.is_book(itemname) then
for incompatible in pairs(enchantment_def.incompatible) do for incompatible in pairs(enchantment_def.incompatible) do
local incompatible_level = item_enchantments[incompatible] local incompatible_level = item_enchantments[incompatible]
if incompatible_level then if incompatible_level then
@ -115,11 +129,11 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
end end
end end
end end
return true return true, nil, nil, primary
end end
function mcl_enchanting.enchant(itemstack, enchantment, level) function mcl_enchanting.enchant(itemstack, enchantment, level)
itemstack:set_name(mcl_enchanting.get_enchanted_itemstring(itemstack:get_name())) mcl_enchanting.set_enchanted_itemstring(itemstack)
local enchantments = mcl_enchanting.get_enchantments(itemstack) local enchantments = mcl_enchanting.get_enchantments(itemstack)
enchantments[enchantment] = level enchantments[enchantment] = level
mcl_enchanting.set_enchantments(itemstack, enchantments) mcl_enchanting.set_enchantments(itemstack, enchantments)
@ -130,7 +144,7 @@ function mcl_enchanting.combine(itemstack, combine_with)
local itemname = itemstack:get_name() local itemname = itemstack:get_name()
local combine_name = combine_with:get_name() local combine_name = combine_with:get_name()
local enchanted_itemname = mcl_enchanting.get_enchanted_itemstring(itemname) local enchanted_itemname = mcl_enchanting.get_enchanted_itemstring(itemname)
if enchanted_itemname ~= mcl_enchanting.get_enchanted_itemstring(combine_name) and combine_name ~= "mcl_enchanting:book_enchanted" then if enchanted_itemname ~= mcl_enchanting.get_enchanted_itemstring(combine_name) and not mcl_enchanting.is_book(itemname) then
return false return false
end end
local enchantments = mcl_enchanting.get_enchantments(itemstack) local enchantments = mcl_enchanting.get_enchantments(itemstack)
@ -173,57 +187,34 @@ function mcl_enchanting.combine(itemstack, combine_with)
return true return true
end end
function mcl_enchanting.enchantments_snippet(_, _, itemstack)
if not itemstack then
return
end
local enchantments = mcl_enchanting.get_enchantments(itemstack)
local text = ""
for enchantment, level in pairs(enchantments) do
text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n"
end
if text ~= "" then
if not itemstack:get_definition()._tt_original_description then
text = text:sub(1, text:len() - 1)
end
return text, false
end
end
function mcl_enchanting.initialize() function mcl_enchanting.initialize()
local all_groups = {}
local weighted = {}
local accum_weight = 0
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
accum_weight = accum_weight + enchantment_def.weight
weighted[#weighted + 1] = {enchantment = enchantment, weight = accum_weight}
for primary in pairs(enchantment_def.primary) do
all_groups[primary] = true
end
for secondary in pairs(enchantment_def.secondary) do
all_groups[secondary] = true
end
end
mcl_enchanting.accumulated_weight = accum_weight
mcl_enchanting.accumulated_weight = weighted
local register_tool_list = {} local register_tool_list = {}
local register_item_list = {} local register_item_list = {}
for itemname, itemdef in pairs(minetest.registered_items) do for itemname, itemdef in pairs(minetest.registered_items) do
if itemdef.groups.enchanted then if mcl_enchanting.can_enchant_freshly(itemname) then
break
end
local quick_test = false
for group, groupv in pairs(itemdef.groups) do
if groupv > 0 and all_groups[group] then
quick_test = true
break
end
end
if quick_test then
if mcl_enchanting.debug then
print(itemname)
end
local expensive_test = false
for enchantment in pairs(mcl_enchanting.enchantments) do
if mcl_enchanting.item_supports_enchantment(itemname, enchantment, true) then
expensive_test = true
if mcl_enchanting.debug then
print("\tSupports " .. enchantment)
else
break
end
end
end
if expensive_test then
local new_name = itemname .. "_enchanted" local new_name = itemname .. "_enchanted"
minetest.override_item(itemname, {_mcl_enchanting_enchanted_tool = new_name}) minetest.override_item(itemname, {_mcl_enchanting_enchanted_tool = new_name})
local new_def = table.copy(itemdef) local new_def = table.copy(itemdef)
new_def.inventory_image = itemdef.inventory_image .. "^[colorize:white:50^[colorize:purple:50" new_def.inventory_image = itemdef.inventory_image .. mcl_enchanting.overlay
if new_def.wield_image then if new_def.wield_image then
new_def.wield_image = new_def.wield_image .. "^[colorize:white:50^[colorize:purple:50" new_def.wield_image = new_def.wield_image .. mcl_enchanting.overlay
end end
new_def.groups.not_in_creative_inventory = 1 new_def.groups.not_in_creative_inventory = 1
new_def.groups.enchanted = 1 new_def.groups.enchanted = 1
@ -236,7 +227,6 @@ function mcl_enchanting.initialize()
register_list[":" .. new_name] = new_def register_list[":" .. new_name] = new_def
end end
end end
end
for new_name, new_def in pairs(register_item_list) do for new_name, new_def in pairs(register_item_list) do
minetest.register_craftitem(new_name, new_def) minetest.register_craftitem(new_name, new_def)
end end
@ -244,3 +234,366 @@ function mcl_enchanting.initialize()
minetest.register_tool(new_name, new_def) minetest.register_tool(new_name, new_def)
end end
end end
function mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure)
local possible_enchantments, weights, accum_weight = {}, {}, 0
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local supported, _, _, primary = mcl_enchanting.can_enchant(itemstack, enchantment, 1)
if primary or treasure then
table.insert(possible_enchantments, enchantment)
accum_weight = accum_weight + enchantment_def.weight
weights[enchantment] = accum_weight
end
end
return possible_enchantments, weights, accum_weight
end
function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance)
local itemname = itemstack:get_name()
if not mcl_enchanting.can_enchant_freshly(itemname) then
return
end
itemstack = ItemStack(itemstack)
local enchantability = minetest.get_item_group(itemname, "enchantability")
enchantability = 1 + math.random(0, math.floor(enchantability / 4)) + math.random(0, math.floor(enchantability / 4))
enchantment_level = enchantment_level + enchantability
enchantment_level = enchantment_level + enchantment_level * (math.random() + math.random() - 1) * 0.15
enchantment_level = math.max(math.floor(enchantment_level + 0.5), 1)
local enchantments = {}
local description
enchantment_level = enchantment_level * 2
repeat
enchantment_level = math.floor(enchantment_level / 2)
if enchantment_level == 0 then
break
end
local possible, weights, accum_weight = mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure)
local selected_enchantment, enchantment_power
if #possible > 0 then
local r = math.random(accum_weight)
for _, enchantment in ipairs(possible) do
if weights[enchantment] >= r then
selected_enchantment = enchantment
break
end
end
local enchantment_def = mcl_enchanting.enchantments[selected_enchantment]
local power_range_table = enchantment_def.power_range_table
for i = enchantment_def.max_level, 1, -1 do
local power_range = power_range_table[i]
if enchantment_level >= power_range[1] and enchantment_level <= power_range[2] then
enchantment_power = i
break
end
end
if not description then
if not enchantment_power then
return
end
description = mcl_enchanting.get_enchantment_description(selected_enchantment, enchantment_power)
end
if enchantment_power then
enchantments[selected_enchantment] = enchantment_power
mcl_enchanting.enchant(itemstack, selected_enchantment, enchantment_power)
end
else
break
end
until not no_reduced_bonus_chance and math.random() >= (enchantment_level + 1) / 50
return enchantments, description
end
function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance)
local enchantments = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance)
if enchantments then
mcl_enchanting.set_enchanted_itemstring(itemstack)
mcl_enchanting.set_enchantments(itemstack, enchantments)
end
return itemstack
end
function mcl_enchanting.get_randomly_enchanted_book(enchantment_level, treasure, no_reduced_bonus_chance)
return mcl_enchanting.enchant_randomly(enchantment_level, treasure, no_reduced_bonus_chance)
end
function mcl_enchanting.get_random_glyph_row()
local glyphs = ""
local x = 1.3
for i = 1, 9 do
glyphs = glyphs .. "image[".. x .. ",0.1;0.5,0.5;mcl_enchanting_glyph_" .. math.random(18) .. ".png^[colorize:#675D49:255]"
x = x + 0.6
end
return glyphs
end
function mcl_enchanting.generate_random_table_slots(itemstack, num_bookshelves)
local base = math.random(8) + math.floor(num_bookshelves / 2) + math.random(0, num_bookshelves)
local required_levels = {
math.max(base / 3, 1),
(base * 2) / 3 + 1,
math.max(base, num_bookshelves * 2)
}
local slots = {}
for i, enchantment_level in ipairs(required_levels) do
local slot = false
local enchantments, description = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level)
if enchantments then
slot = {
enchantments = enchantments,
description = description,
glyphs = mcl_enchanting.get_random_glyph_row(),
level_requirement = math.max(i, math.floor(enchantment_level)),
}
end
slots[i] = slot
end
return slots
end
function mcl_enchanting.get_table_slots(player, itemstack, num_bookshelves)
if not mcl_enchanting.can_enchant_freshly(itemstack:get_name()) then
return {false, false, false}
end
local itemname = itemstack:get_name()
local meta = player:get_meta()
local player_slots = minetest.deserialize(meta:get_string("mcl_enchanting:slots")) or {}
local player_bookshelves_slots = player_slots[num_bookshelves] or {}
local player_bookshelves_item_slots = player_bookshelves_slots[itemname]
if player_bookshelves_item_slots then
return player_bookshelves_item_slots
else
player_bookshelves_item_slots = mcl_enchanting.generate_random_table_slots(itemstack, num_bookshelves)
if player_bookshelves_item_slots then
player_bookshelves_slots[itemname] = player_bookshelves_item_slots
player_slots[num_bookshelves] = player_bookshelves_slots
meta:set_string("mcl_enchanting:slots", minetest.serialize(player_slots))
return player_bookshelves_item_slots
else
return {false, false, false}
end
end
end
function mcl_enchanting.reset_table_slots(player)
player:get_meta():set_string("mcl_enchanting:slots", "")
end
function mcl_enchanting.show_enchanting_formspec(player)
local C = minetest.get_color_escape_sequence
local name = player:get_player_name()
local meta = player:get_meta()
local inv = player:get_inventory()
local num_bookshelves = meta:get_int("mcl_enchanting:num_bookshelves")
local table_name = meta:get_string("mcl_enchanting:table_name")
local formspec = ""
.. "size[9.07,8.6;]"
.. "formspec_version[3]"
.. "label[0,0;" .. C("#313131") .. table_name .. "]"
.. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1)
.. "list[detached:" .. name .. "_enchanting;enchanting;0.2,2.4;1,1;1]"
.. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1)
.. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]"
.. "list[detached:" .. name .. "_enchanting;enchanting;1.1,2.4;1,1;2]"
.. "label[0,4;" .. C("#313131") .. "Inventory]"
.. mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3)
.. mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1)
.. "list[current_player;main;0,4.5;9,3;9]"
.. "listring[detached:" .. name .. "_enchanting;enchanting]"
.. "listring[current_player;main]"
.. "list[current_player;main;0,7.74;9,1;]"
.. "real_coordinates[true]"
.. "image[3.15,0.6;7.6,4.1;mcl_enchanting_button_background.png]"
local itemstack = inv:get_stack("enchanting_item", 1)
local player_levels = mcl_experience.get_player_xp_level(player)
local y = 0.65
local any_enchantment = false
local table_slots = mcl_enchanting.get_table_slots(player, itemstack, num_bookshelves)
for i, slot in ipairs(table_slots) do
any_enchantment = any_enchantment or slot
local enough_lapis = inv:contains_item("enchanting_lapis", ItemStack({name = "mcl_dye:blue", count = i}))
local enough_levels = slot and slot.level_requirement <= player_levels
local can_enchant = (slot and enough_lapis and enough_levels)
local ending = (can_enchant and "" or "_off")
local hover_ending = (can_enchant and "_hovered" or "_off")
formspec = formspec
.. "container[3.2," .. y .. "]"
.. (slot and "tooltip[button_" .. i .. ";" .. C("#818181") .. slot.description .. " " .. C("#FFFFFF") .. " . . . ?\n\n" .. (enough_levels and C(enough_lapis and "#818181" or "#FC5454") .. i .. " Lapis Lazuli\n" .. C("#818181") .. i .. " Enchantment Levels" or C("#FC5454") .. "Level Requirement: " .. slot.level_requirement) .. "]" or "")
.. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]"
.. "button[0,0;7.5,1.3;button_" .. i .. ";]"
.. (slot and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "")
.. (slot and "label[7.2,1.1;" .. C(can_enchant and "#80FF20" or "#407F10") .. slot.level_requirement .. "]" or "")
.. (slot and slot.glyphs or "")
.. "container_end[]"
y = y + 1.35
end
formspec = formspec
.. "image[" .. (any_enchantment and 0.58 or 1.15) .. ",1.2;" .. (any_enchantment and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (any_enchantment and "open" or "closed") .. ".png]"
minetest.show_formspec(name, "mcl_enchanting:table", formspec)
end
function mcl_enchanting.handle_formspec_fields(player, formname, fields)
if formname == "mcl_enchanting:table" then
local button_pressed
for i = 1, 3 do
if fields["button_" .. i] then
button_pressed = i
end
end
if not button_pressed then return end
local name = player:get_player_name()
local inv = player:get_inventory()
local meta = player:get_meta()
local num_bookshelfes = meta:get_int("mcl_enchanting:num_bookshelves")
local itemstack = inv:get_stack("enchanting_item", 1)
local cost = ItemStack({name = "mcl_dye:blue", count = button_pressed})
if not inv:contains_item("enchanting_lapis", cost) then
return
end
local slots = mcl_enchanting.get_table_slots(player, itemstack, num_bookshelfes)
local slot = slots[button_pressed]
if not slot then
return
end
local player_level = mcl_experience.get_player_xp_level(player)
if player_level < slot.level_requirement then
return
end
mcl_experience.set_player_xp_level(player, player_level - button_pressed)
inv:remove_item("enchanting_lapis", cost)
mcl_enchanting.set_enchanted_itemstring(itemstack)
mcl_enchanting.set_enchantments(itemstack, slot.enchantments)
inv:set_stack("enchanting_item", 1, itemstack)
minetest.sound_play("mcl_enchanting_enchant", {to_player = name, gain = 5.0})
mcl_enchanting.reset_table_slots(player)
mcl_enchanting.reload_inventory(player)
mcl_enchanting.show_enchanting_formspec(player)
end
end
function mcl_enchanting.initialize_player(player)
local player_inv = player:get_inventory()
player_inv:set_size("enchanting_lapis", 1)
player_inv:set_size("enchanting_item", 1)
local name = player:get_player_name()
local detached_inv = minetest.create_detached_inventory(name .. "_enchanting", {
allow_put = function(inv, listname, index, stack, player)
if player:get_player_name() ~= name then
return 0
end
if stack:get_name() == "mcl_dye:blue" and index ~= 2 then
return math.min(inv:get_stack(listname, 3):get_free_space(), stack:get_count())
elseif index ~= 3 and inv:get_stack(listname, 2):get_count() == 0 then
return 1
else
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_player_name() ~= name or index == 1 then
return 0
end
return stack:get_count()
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0
end,
on_put = function(inv, listname, index, stack, player)
local result_list
if index == 1 then
if stack:get_name() == "mcl_dye:blue" then
result_list = "lapis"
stack:add_item(inv:get_stack(listname, 3))
inv:set_stack(listname, 1, nil)
inv:set_stack(listname, 3, stack)
else
result_list = "item"
inv:set_stack(listname, 1, nil)
inv:set_stack(listname, 2, stack)
end
elseif index == 2 then
result_list = "item"
elseif index == 3 then
result_list = "lapis"
stack = inv:get_stack(listname, 3)
end
player:get_inventory():set_stack("enchanting_" .. result_list, 1, stack)
mcl_enchanting.show_enchanting_formspec(player)
end,
on_take = function(inv, listname, index, stack, player)
local result_list
if index == 2 then
result_list = "item"
elseif index == 3 then
result_list = "lapis"
end
player:get_inventory():set_stack("enchanting_" .. result_list, 1, nil)
mcl_enchanting.show_enchanting_formspec(player)
end
}, name)
detached_inv:set_size("enchanting", 3)
mcl_enchanting.reload_inventory(player)
end
function mcl_enchanting.reload_inventory(player)
local player_inv = player:get_inventory()
local detached_inv = minetest.get_inventory({type = "detached", name = player:get_player_name() .. "_enchanting"})
detached_inv:set_stack("enchanting", 2, player_inv:get_stack("enchanting_item", 1))
detached_inv:set_stack("enchanting", 3, player_inv:get_stack("enchanting_lapis", 1))
end
function mcl_enchanting.schedule_book_animation(self, anim)
self.scheduled_anim = {timer = self.anim_length, anim = anim}
end
function mcl_enchanting.set_book_animation(self, anim)
local anim_index = mcl_enchanting.book_animations[anim]
local start, stop = mcl_enchanting.book_animation_steps[anim_index], mcl_enchanting.book_animation_steps[anim_index + 1]
self.object:set_animation({x = start, y = stop}, mcl_enchanting.book_animation_speed)
self.scheduled_anim = nil
self.anim_length = (stop - start) / 40
end
function mcl_enchanting.check_animation_schedule(self, dtime)
local schedanim = self.scheduled_anim
if schedanim then
schedanim.timer = schedanim.timer - dtime
if schedanim.timer <= 0 then
mcl_enchanting.set_book_animation(self, schedanim.anim)
end
end
end
function mcl_enchanting.look_at(self, pos2)
local pos1 = self.object:get_pos()
local vec = vector.subtract(pos1, pos2)
local yaw = math.atan(vec.z / vec.x) - math.pi/2
yaw = yaw + (pos1.x >= pos2.x and math.pi or 0)
self.object:set_yaw(yaw + math.pi)
end
function mcl_enchanting.check_book(pos)
local obj_pos = vector.add(pos, mcl_enchanting.book_offset)
for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.1)) do
local luaentity = obj:get_luaentity()
if luaentity and luaentity.name == "mcl_enchanting:book" then
if minetest.get_node(pos).name ~= "mcl_enchanting:table" then
obj:remove()
end
return
end
end
minetest.add_entity(obj_pos, "mcl_enchanting:book")
end
function mcl_enchanting.get_bookshelves(pos)
local absolute, relative = {}, {}
for i, rp in ipairs(mcl_enchanting.bookshelf_positions) do
local airp = vector.add(pos, mcl_enchanting.air_positions[i])
local ap = vector.add(pos, rp)
if minetest.get_node(ap).name == "mcl_books:bookshelf" and minetest.get_node(airp).name == "air" then
table.insert(absolute, ap)
table.insert(relative, rp)
end
end
return absolute, relative
end

View File

@ -2,21 +2,265 @@ local modpath = minetest.get_modpath("mcl_enchanting")
mcl_enchanting = { mcl_enchanting = {
book_offset = vector.new(0, 0.75, 0), book_offset = vector.new(0, 0.75, 0),
book_animations = {["close"] = 1, ["opening"] = 2, ["open"] = 3, ["closing"] = 4},
book_animation_steps = {0, 640, 680, 700, 740},
book_animation_speed = 40,
roman_numerals = dofile(modpath .. "/roman_numerals.lua"), -- https://exercism.io/tracks/lua/exercises/roman-numerals/solutions/73c2fb7521e347209312d115f872fa49 roman_numerals = dofile(modpath .. "/roman_numerals.lua"), -- https://exercism.io/tracks/lua/exercises/roman-numerals/solutions/73c2fb7521e347209312d115f872fa49
enchantments = {}, enchantments = {},
weighted_enchantments = {}, overlay = "^[colorize:white:50^[colorize:purple:50",
accumulated_weight = 0, bookshelf_positions = {
debug = false, {x = -2, y = 0, z = -2}, {x = -2, y = 1, z = -2},
{x = -1, y = 0, z = -2}, {x = -1, y = 1, z = -2},
{x = 0, y = 0, z = -2}, {x = 0, y = 1, z = -2},
{x = 1, y = 0, z = -2}, {x = 1, y = 1, z = -2},
{x = 2, y = 0, z = -2}, {x = 2, y = 1, z = -2},
{x = -2, y = 0, z = 2}, {x = -2, y = 1, z = 2},
{x = -1, y = 0, z = 2}, {x = -1, y = 1, z = 2},
{x = 0, y = 0, z = 2}, {x = 0, y = 1, z = 2},
{x = 1, y = 0, z = 2}, {x = 1, y = 1, z = 2},
{x = 2, y = 0, z = 2}, {x = 2, y = 1, z = 2},
-- {x = -2, y = 0, z = -2}, {x = -2, y = 1, z = -2},
{x = -2, y = 0, z = -1}, {x = -2, y = 1, z = -1},
{x = -2, y = 0, z = 0}, {x = -2, y = 1, z = 0},
{x = -2, y = 0, z = 1}, {x = -2, y = 1, z = 1},
{x = -2, y = 0, z = 2}, {x = -2, y = 1, z = 2},
{x = 2, y = 0, z = -2}, {x = 2, y = 1, z = -2},
{x = 2, y = 0, z = -1}, {x = 2, y = 1, z = -1},
{x = 2, y = 0, z = 0}, {x = 2, y = 1, z = 0},
{x = 2, y = 0, z = 1}, {x = 2, y = 1, z = 1},
-- {x = 2, y = 0, z = 2}, {x = 2, y = 1, z = 2},
},
air_positions = {
{x = -1, y = 0, z = -1}, {x = -1, y = 1, z = -1},
{x = -1, y = 0, z = -1}, {x = -1, y = 1, z = -1},
{x = 0, y = 0, z = -1}, {x = 0, y = 1, z = -1},
{x = 1, y = 0, z = -1}, {x = 1, y = 1, z = -1},
{x = 1, y = 0, z = -1}, {x = 1, y = 1, z = -1},
{x = -1, y = 0, z = 1}, {x = -1, y = 1, z = 1},
{x = -1, y = 0, z = 1}, {x = -1, y = 1, z = 1},
{x = 0, y = 0, z = 1}, {x = 0, y = 1, z = 1},
{x = 1, y = 0, z = 1}, {x = 1, y = 1, z = 1},
{x = 1, y = 0, z = 1}, {x = 1, y = 1, z = 1},
-- {x = -1, y = 0, z = -1}, {x = -1, y = 1, z = -1},
{x = -1, y = 0, z = -1}, {x = -1, y = 1, z = -1},
{x = -1, y = 0, z = 0}, {x = -1, y = 1, z = 0},
{x = -1, y = 0, z = 1}, {x = -1, y = 1, z = 1},
{x = -1, y = 0, z = 1}, {x = -1, y = 1, z = 1},
{x = 1, y = 0, z = -1}, {x = 1, y = 1, z = -1},
{x = 1, y = 0, z = -1}, {x = 1, y = 1, z = -1},
{x = 1, y = 0, z = 0}, {x = 1, y = 1, z = 0},
{x = 1, y = 0, z = 1}, {x = 1, y = 1, z = 1},
-- {x = 1, y = 0, z = 1}, {x = 1, y = 1, z = 1},
},
} }
dofile(modpath .. "/engine.lua") dofile(modpath .. "/engine.lua")
dofile(modpath .. "/enchantments.lua") dofile(modpath .. "/enchantments.lua")
dofile(modpath .. "/command.lua")
dofile(modpath .. "/tt.lua") minetest.register_chatcommand("enchant", {
dofile(modpath .. "/book.lua") description = "Enchant an item.",
-- dofile(modpath .. "/ui.lua") params = "<player> <enchantment> [<level>]",
-- dofile(modpath .. "/fx.lua") privs = {give = true},
-- dofile(modpath .. "/book.lua") func = function(_, param)
-- dofile(modpath .. "/table.lua") local sparam = param:split(" ")
local target_name = sparam[1]
local enchantment = sparam[2]
local level_str = sparam[3]
local level = tonumber(level_str or "1")
if not target_name or not enchantment then
return false, "Usage: /enchant <player> <enchantment> [<level>]"
end
local target = minetest.get_player_by_name(target_name)
if not target then
return false, "Player '" .. target_name .. "' cannot be found"
end
local itemstack = target:get_wielded_item()
local can_enchant, errorstring, extra_info = mcl_enchanting.can_enchant(itemstack, enchantment, level)
if not can_enchant then
if errorstring == "enchantment invalid" then
return false, "There is no such enchantment '" .. enchantment .. "'"
elseif errorstring == "item missing" then
return false, "The target doesn't hold an item"
elseif errorstring == "item not supported" then
return false, "The selected enchantment can't be added to the target item"
elseif errorstring == "level invalid" then
return false, "'" .. level_str .. "' is not a valid number"
elseif errorstring == "level too high" then
return false, "The number you have entered (" .. level_str .. ") is too big, it must be at most " .. extra_info
elseif errorstring == "level too small" then
return false, "The number you have entered (" .. level_str .. ") is too small, it must be at least " .. extra_info
elseif errorstring == "incompatible" then
return false, mcl_enchanting.get_enchantment_description(enchantment, level) .. " can't be combined with " .. extra_info
end
else
target:set_wielded_item(mcl_enchanting.enchant(itemstack, enchantment, level))
return true, "Enchanting succeded"
end
end
})
minetest.register_chatcommand("forceenchant", {
description = "Forcefully enchant an item.",
params = "<player> <enchantment> [<level>]",
func = function(_, param)
local sparam = param:split(" ")
local target_name = sparam[1]
local enchantment = sparam[2]
local level_str = sparam[3]
local level = tonumber(level_str or "1")
if not target_name or not enchantment then
return false, "Usage: /forceenchant <player> <enchantment> [<level>]"
end
local target = minetest.get_player_by_name(target_name)
if not target then
return false, "Player '" .. target_name .. "' cannot be found"
end
local itemstack = target:get_wielded_item()
local can_enchant, errorstring, extra_info = mcl_enchanting.can_enchant(itemstack, enchantment, level)
if errorstring == "enchantment invalid" then
return false, "There is no such enchantment '" .. enchantment .. "'"
elseif errorstring == "item missing" then
return false, "The target doesn't hold an item"
elseif errorstring == "item not supported" and not mcl_enchanting.is_enchantable(itemstack:get_name()) then
return false, "The target item is not enchantable"
elseif errorstring == "level invalid" then
return false, "'" .. level_str .. "' is not a valid number"
else
target:set_wielded_item(mcl_enchanting.enchant(itemstack, enchantment, level))
return true, "Enchanting succeded"
end
end
})
minetest.register_craftitem("mcl_enchanting:book_enchanted", {
description = "Enchanted Book",
inventory_image = "mcl_enchanting_book_enchanted.png" .. mcl_enchanting.overlay,
groups = {enchanted = 1, not_in_creative_inventory = 1, enchantability = 1},
_mcl_enchanting_enchanted_tool = "mcl_enchanting:book_enchanted",
stack_max = 1,
})
minetest.register_entity("mcl_enchanting:book", {
initial_properties = {
visual = "mesh",
mesh = "mcl_enchanting_book.b3d",
visual_size = {x = 12.5, y = 12.5},
collisionbox = {0, 0, 0},
physical = false,
textures = {"mcl_enchanting_book_entity.png"},
},
player_near = false,
on_activate = function(self)
self.object:set_armor_groups({immortal = 1})
mcl_enchanting.set_book_animation(self, "close")
mcl_enchanting.check_book(vector.subtract(self.object:get_pos(), mcl_enchanting.book_offset))
end,
on_step = function(self, dtime)
local old_player_near = self.player_near
local player_near = false
local player
for _, obj in ipairs(minetest.get_objects_inside_radius(vector.subtract(self.object:get_pos(), mcl_enchanting.book_offset), 2.5)) do
if obj:is_player() then
player_near = true
player = obj
end
end
if player_near and not old_player_near then
mcl_enchanting.set_book_animation(self, "opening")
mcl_enchanting.schedule_book_animation(self, "open")
elseif old_player_near and not player_near then
mcl_enchanting.set_book_animation(self, "closing")
mcl_enchanting.schedule_book_animation(self, "close")
end
if player then
mcl_enchanting.look_at(self, player:get_pos())
end
self.player_near = player_near
mcl_enchanting.check_animation_schedule(self, dtime)
end,
})
minetest.register_node("mcl_enchanting:table", {
description = "Enchanting Table",
drawtype = "nodebox",
tiles = {"mcl_enchanting_table_top.png", "mcl_enchanting_table_bottom.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png"},
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.25, 0.5},
},
sounds = mcl_sounds.node_sound_stone_defaults(),
groups = {pickaxey = 2},
on_rotate = (rawget(_G, "screwdriver") or {}).rotate_simple,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local player_meta = clicker:get_meta()
local table_meta = minetest.get_meta(pos)
local num_bookshelves = table_meta:get_int("mcl_enchanting:num_bookshelves")
local table_name = table_meta:get_string("name")
if table_name == "" then
table_name = "Enchant"
end
player_meta:set_int("mcl_enchanting:num_bookshelves", num_bookshelves)
player_meta:set_string("mcl_enchanting:table_name", table_name)
mcl_enchanting.show_enchanting_formspec(clicker)
end,
on_construct = function(pos)
minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
end,
on_destruct = function(pos)
local itemstack = ItemStack("mcl_enchanting:table")
local meta = minetest.get_meta(pos)
local itemmeta = itemstack:get_meta()
itemmeta:set_string("name", meta:get_string("name"))
itemmeta:set_string("description", meta:get_string("description"))
minetest.add_item(pos, itemstack)
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local itemmeta = itemstack:get_meta()
meta:set_string("name", itemmeta:get_string("name"))
meta:set_string("description", itemmeta:get_string("description"))
end,
after_destruct = mcl_enchanting.check_table,
drop = "",
_mcl_blast_resistance = 1200,
_mcl_hardness = 5,
})
minetest.register_craft({
output = "mcl_enchanting:table",
recipe = {
{"", "mcl_books:book", ""},
{"mcl_core:diamond", "mcl_core:obsidian", "mcl_core:diamond"},
{"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}
}
})
minetest.register_abm({
name = "Enchanting table bookshelf particles",
interval = 1,
chance = 1,
nodenames = "mcl_enchanting:table",
action = function(pos)
mcl_enchanting.check_book(pos)
local absolute, relative = mcl_enchanting.get_bookshelves(pos)
for i, ap in ipairs(absolute) do
if math.random(10) == 1 then
local rp = relative[i]
minetest.add_particle({
pos = ap,
velocity = vector.subtract(vector.new(0, 5, 0), rp),
acceleration = {x = 0, y = -9.81, z = 0},
expirationtime = 2,
size = 2,
texture = "mcl_enchanting_glyph_" .. math.random(18) .. ".png"
})
end
end
minetest.get_meta(pos):set_int("mcl_enchanting:num_bookshelves", math.min(15, #absolute))
end
})
minetest.register_on_mods_loaded(mcl_enchanting.initialize) minetest.register_on_mods_loaded(mcl_enchanting.initialize)
minetest.register_on_joinplayer(mcl_enchanting.initialize_player)
minetest.register_on_player_receive_fields(mcl_enchanting.handle_formspec_fields)
table.insert(tt.registered_snippets, 1, mcl_enchanting.enchantments_snippet)

View File

@ -1,5 +1,5 @@
name = mcl_enchanting name = mcl_enchanting
description = The rewrite of the Enchanting mod for MineClone2 description = Enchanting for MineClone2
depends = mcl_formspec, tt, mcl_books, walkover depends = tt, walkover, mcl_sounds
optional_depends = screwdriver optional_depends = screwdriver
author = Fleckenstein author = Fleckenstein

View File

@ -1,189 +0,0 @@
local enchanting_table_formspec = ""
.. "size[9.07,8.6;]"
.. "formspec_version[3]"
.. "label[0,0;" .. minetest.formspec_escape(minetest.colorize("#313131", "Enchant")) .. "]"
.. mcl_formspec.get_itemslot_bg(1.1, 2.4, 1, 1)
.. "image[1.1,2.4;1,1;mcl_enchanting_lapis_background.png]"
.. "list[context;lapis;1.1,2.4;1,1;]"
.. mcl_formspec.get_itemslot_bg(0.2, 2.4, 1, 1)
.. "list[context;tool;0.2,2.4;1,1;]"
.. "label[0,4;" .. minetest.formspec_escape(minetest.colorize("#313131", "Inventory")) .. "]"
.. mcl_formspec.get_itemslot_bg(0,4.5,9,3)
.. mcl_formspec.get_itemslot_bg(0,7.74,9,1)
.. "list[current_player;main;0,4.5;9,3;9]"
.. "listring[]"
.. "list[current_player;main;0,7.74;9,1;]"
.. "real_coordinates[true]"
.. "image[3.15,0.6;7.6,4.1;mcl_enchanting_button_background.png]"
local bookshelf_positions = {{x = 1}, {x = -1}, {z = 1}, {z = -1}}
for _, p in pairs(bookshelf_positions) do
for _, d in pairs({"x", "y", "z"}) do
p[d] = p[d] or 0
end
end
minetest.register_abm({
name = "Enchanting table bookshelf particles",
interval = 0.1,
chance = 1,
nodenames = "mcl_books:bookshelf",
action = function(pos)
for _, relative_pos in pairs(bookshelf_positions) do
if minetest.get_node(vector.add(pos, vector.multiply(relative_pos, 2))).name == "mcl_enchanting:table" and minetest.get_node(vector.add(pos, relative_pos, 2)).name == "air" then
minetest.add_particle({
pos = pos,
velocity = vector.subtract(relative_pos, vector.new(0, -2, 0)),
acceleration = {x = 0, y = -2, z = 0},
expirationtime = 2,
size = 2,
texture = "mcl_enchanting_glyph_" .. math.random(18) .. ".png"
})
end
end
end
})
function mcl_enchanting.update_formspec(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local full_tool_name = inv:get_stack("tool", 1):get_name()
local shortened_tool_name = mcl_enchanting.all_tools[full_tool_name]
local supported_enchantments = (shortened_tool_name and mcl_enchanting.tools[shortened_tool_name].enchantments or {})
local sup_ench = false
local formspec = enchanting_table_formspec
local e_list = minetest.deserialize(meta:get_string("enchantments"))
local y = 0.65
for i, e in pairs(e_list) do
local enchantment_supported = table.indexof(supported_enchantments, e.enchantment) ~= -1
sup_ench = sup_ench or enchantment_supported
local enough_lapis = inv:contains_item("lapis", ItemStack(mcl_enchanting.lapis_itemstring .. " " .. e.cost))
local ending = (enough_lapis and enchantment_supported and "" or "_off")
local hover_ending = (enough_lapis and enchantment_supported and "_hovered" or "_off")
formspec = formspec
.. "container[3.2," .. y .. "]"
.. (enchantment_supported and "tooltip[button_" .. i .. ";" .. C("#818181") .. mcl_enchanting.get_enchantment_description(e.enchantment, e.level) .. " " .. C("#FFFFFF") .. " . . . ?\n\n" .. C(enough_lapis and "#818181" or "#FC5454") .. e.cost .. " Lapis Lazuli" .. "]" or "")
.. "style[button_" .. i .. ";bgimg=mcl_enchanting_button" .. ending .. ".png;bgimg_hovered=mcl_enchanting_button" .. hover_ending .. ".png;bgimg_pressed=mcl_enchanting_button" .. hover_ending .. ".png]"
.. "button[0,0;7.5,1.3;button_" .. i .. ";]"
.. (enchantment_supported and "image[0,0;1.3,1.3;mcl_enchanting_number_" .. i .. ending .. ".png]" or "")
.. (enchantment_supported and e.glyphs or "")
.. "container_end[]"
y = y + 1.35
end
formspec = formspec
.. "image[" .. (sup_ench and 0.58 or 1.15) .. ",1.2;" .. (sup_ench and 2 or 0.87) .. ",1.43;mcl_enchanting_book_" .. (sup_ench and "open" or "closed") .. ".png]"
meta:set_string("formspec", formspec)
end
function mcl_enchanting.progress_formspec_input(pos, _, fields, player)
if fields.quit then
return
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local e_list = minetest.deserialize(meta:get_string("enchantments"))
local button_pressed
for i = 1, 3 do
if fields["button_" .. i] then
button_pressed = i
end
end
if not button_pressed then return end
local e = e_list[button_pressed]
local lapis_cost = ItemStack(mcl_enchanting.lapis_itemstring .. " " .. e.cost)
if not inv:contains_item("lapis", lapis_cost) then return end
local tool_stack = inv:get_stack("tool", 1)
local full_tool_name = tool_stack:get_name()
local shortened_tool_name = mcl_enchanting.all_tools[full_tool_name]
if not shortened_tool_name then return end
if table.indexof(mcl_enchanting.tools[shortened_tool_name].enchantments, e.enchantment) == -1 then return end
local wear = tool_stack:get_wear()
inv:remove_item("lapis", lapis_cost)
local enchanted_tool_stack = ItemStack(full_tool_name .. "_enchanted_" .. e.enchantment .. "_" .. e.level)
enchanted_tool_stack:add_wear(tool_stack:get_wear())
inv:set_stack("tool", 1, enchanted_tool_stack)
minetest.sound_play("mcl_enchanting_enchant", {to_player = player:get_player_name(), gain = 5.0})
mcl_enchanting.add_enchantments(pos)
end
function mcl_enchanting.drop_inventory(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for _, listname in ipairs({"tool", "lapis"}) do
local stack = inv:get_stack(listname, 1)
if not stack:is_empty() then
minetest.add_item(vector.add(pos, {x = math.random(0, 10) / 10 - 0.5, y = 0, z = math.random(0, 10) / 10 - 0.5}), stack)
end
end
end
function mcl_enchanting.init_table(pos)
local inv = minetest.get_meta(pos):get_inventory()
inv:set_size("tool", 1)
inv:set_size("lapis", 1)
mcl_enchanting.add_enchantments(pos)
minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
end
function mcl_enchanting.add_enchantments_to_table(pos)
local meta = minetest.get_meta(pos)
local e_list = {}
for i = 1, 3 do
local e = {}
e.cost = math.random(mcl_enchanting.max_cost)
e.enchantment = mcl_enchanting.enchantment_name_list[math.random(#mcl_enchanting.enchantment_name_list)]
local max_level = mcl_enchanting.enchantments[e.enchantment].max_level
e.level = max_level + 1 - math.ceil(math.pow(math.random(math.pow(max_level, mcl_enchanting.level_rarity_grade)), 1 / mcl_enchanting.level_rarity_grade))
e.glyphs = ""
local x = 1.3
for i = 1, 9 do
e.glyphs = e.glyphs .. "image[".. x .. ",0.1;0.5,0.5;mcl_enchanting_glyph_" .. math.random(18) .. ".png^[colorize:#675D49:255]"
x = x + 0.6
end
e_list[i] = e
end
meta:set_string("enchantments", minetest.serialize(e_list))
mcl_enchanting.update_formspec(pos)
end
minetest.register_node("mcl_enchanting:table", {
description = "Enchanting Table",
drawtype = "nodebox",
tiles = {"mcl_enchanting_table_top.png", "mcl_enchanting_table_bottom.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png", "mcl_enchanting_table_side.png"},
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.25, 0.5},
},
sounds = mcl_sounds.node_sound_stone_defaults(),
groups = {pickaxey = 2},
_mcl_blast_resistance = 1200,
_mcl_hardness = 5,
on_rotate = (screwdriver or {}).rotate_simple,
on_construct = mcl_enchanting.init_table,
on_destruct = mcl_enchanting.drop_inventory,
after_destruct = mcl_enchanting.check_book,
on_receive_fields = mcl_enchanting.progress_formspec_input,
on_metadata_inventory_put = mcl_enchanting.update_formspec,
on_metadata_inventory_take = mcl_enchanting.update_formspec,
allow_metadata_inventory_put = function(_, listname, _, stack)
if listname == "lapis" then
return (stack:get_name() == mcl_enchanting.lapis_itemstring) and stack:get_count() or 0
end
return 1
end,
allow_metadata_inventory_move = function()
return 0
end,
})
minetest.register_craft({
output = "mcl_enchanting:table",
recipe = {
{"", "mcl_books:book", ""},
{"mcl_core:diamond", "mcl_core:obsidian", "mcl_core:diamond"},
{"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}
}
})

View File

@ -1,87 +0,0 @@
local book_animations = {["close"] = 1, ["opening"] = 2, ["open"] = 3, ["closing"] = 4}
local book_animation_steps = {0, 640, 680, 700, 740}
local book_animation_speed = 40
function mcl_enchanting.schedule_book_animation(self, anim)
self.scheduled_anim = {timer = self.anim_length, anim = anim}
end
function mcl_enchanting.set_book_animation(self, anim)
local anim_index = book_animations[anim]
local start, stop = book_animation_steps[anim_index], book_animation_steps[anim_index + 1]
self.object:set_animation({x = start, y = stop}, book_animation_speed)
self.scheduled_anim = nil
self.anim_length = (stop - start) / 40
end
function mcl_enchanting.check_animation_schedule(self, dtime)
local schedanim = self.scheduled_anim
if schedanim then
schedanim.timer = schedanim.timer - dtime
if schedanim.timer <= 0 then
mcl_enchanting.set_book_animation(self, schedanim.anim)local pos1=self.object:get_pos()
end
end
end
function mcl_enchanting.look_at(self, pos2)
local pos1 = self.object:get_pos()
local vec = vector.subtract(pos1, pos2)
local yaw = math.atan(vec.z / vec.x) - math.pi/2
yaw = yaw + (pos1.x >= pos2.x and math.pi or 0)
self.object:set_yaw(yaw + math.pi)
end
function mcl_enchanting.check_book(pos)
local obj_pos = vector.add(pos, mcl_enchanting.book_offset)
for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.1)) do
local luaentity = obj:get_luaentity()
if luaentity and luaentity.name == "mcl_enchanting:book" then
if minetest.get_node(pos).name ~= "mcl_enchanting:table" then
obj:remove()
end
return
end
end
minetest.add_entity(obj_pos, "mcl_enchanting:book")
end
minetest.register_entity("mcl_enchanting:book", {
initial_properties = {
visual = "mesh",
mesh = "mcl_enchanting_book.b3d",
visual_size = {x = 12.5, y = 12.5},
collisionbox = {0, 0, 0},
physical = false,
textures = {"mcl_enchanting_book_entity.png"},
},
player_near = false,
on_activate = function(self)
self.object:set_armor_groups({immortal = 1})
mcl_enchanting.set_book_animation(self, "close")
mcl_enchanting.check_book(vector.subtract(self.object:get_pos(), mcl_enchanting.book_offset))
end,
on_step = function(self, dtime)
local old_player_near = self.player_near
local player_near = false
local player
for _, obj in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 2.5)) do
if obj:is_player() then
player_near = true
player = obj
end
end
if player_near and not old_player_near then
mcl_enchanting.set_book_animation(self, "opening")
mcl_enchanting.schedule_book_animation(self, "open")
elseif old_player_near and not player_near then
mcl_enchanting.set_book_animation(self, "closing")
mcl_enchanting.schedule_book_animation(self, "close")
end
if player then
mcl_enchanting.look_at(self, player:get_pos())
end
self.player_near = player_near
mcl_enchanting.check_animation_schedule(self, dtime)
end,
})

View File

@ -1,18 +0,0 @@
function mcl_enchanting.enchantments_snippet(_, _, itemstack)
if not itemstack then
return
end
local enchantments = mcl_enchanting.get_enchantments(itemstack)
local text = ""
for enchantment, level in pairs(enchantments) do
text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n"
end
if text ~= "" then
if not itemstack:get_definition()._tt_original_description then
text = text:sub(1, text:len() - 1)
end
return text, false
end
end
table.insert(tt.registered_snippets, 1, mcl_enchanting.enchantments_snippet)

View File

@ -14,22 +14,6 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
-- Apply item description updates -- Apply item description updates
local function equals(t1, t2)
for k, v in pairs(t1) do
local equal
local v2 = rawget(t2, k)
if type(v) == "table" then
equal = equals(v, v2)
else
equal = (v == v2)
end
if not equal then
return false
end
end
return true
end
local function apply_snippets(desc, itemstring, toolcaps, itemstack) local function apply_snippets(desc, itemstring, toolcaps, itemstack)
local first = true local first = true
-- Apply snippets -- Apply snippets
@ -80,10 +64,9 @@ tt.reload_itemstack_description = function(itemstack)
if def and def._mcl_generate_description then if def and def._mcl_generate_description then
def._mcl_generate_description(itemstack) def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) and meta:get_string("name") == "" then elseif should_change(itemstring, def) and meta:get_string("name") == "" then
local toolcaps = itemstack:get_tool_capabilities() local toolcaps
local hand_toolcaps = ItemStack(""):get_tool_capabilities() if def.tool_capabilities then
if equals(toolcaps, hand_toolcaps) then toolcaps = itemstack:get_tool_capabilities()
toolcaps = nil
end end
local orig_desc = def._tt_original_description or def.description local orig_desc = def._tt_original_description or def.description
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack) local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)

View File

@ -5,3 +5,4 @@ _mcl_autogroup?
mcl_armor? mcl_armor?
mcl_brewing? mcl_brewing?
mcl_potions? mcl_potions?
mcl_enchanting

View File

@ -8,7 +8,7 @@ local mod_player = minetest.get_modpath("mcl_player") ~= nil
local mod_craftguide = minetest.get_modpath("mcl_craftguide") ~= nil local mod_craftguide = minetest.get_modpath("mcl_craftguide") ~= nil
-- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left -- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left
local function return_item(itemstack, dropper, pos, inv) function return_item(itemstack, dropper, pos, inv)
if dropper:is_player() then if dropper:is_player() then
-- Return to main inventory -- Return to main inventory
if inv:room_for_item("main", itemstack) then if inv:room_for_item("main", itemstack) then
@ -36,9 +36,11 @@ local function return_item(itemstack, dropper, pos, inv)
end end
-- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left -- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left
local function return_fields(player, name) function return_fields(player, name)
local inv = player:get_inventory() local inv = player:get_inventory()
for i,stack in ipairs(inv:get_list(name)) do local list = inv:get_list(name)
if not list then return end
for i,stack in ipairs(list) do
return_item(stack, player, player:get_pos(), inv) return_item(stack, player, player:get_pos(), inv)
stack:clear() stack:clear()
inv:set_stack(name, i, stack) inv:set_stack(name, i, stack)
@ -137,6 +139,9 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.quit then if fields.quit then
return_fields(player,"craft") return_fields(player,"craft")
return_fields(player,"enchanting_lapis")
return_fields(player,"enchanting_item")
mcl_enchanting.reload_inventory(player)
if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then
set_inventory(player) set_inventory(player)
end end
@ -152,6 +157,8 @@ end
-- Drop crafting grid items on leaving -- Drop crafting grid items on leaving
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
return_fields(player, "craft") return_fields(player, "craft")
return_fields(player, "enchanting_lapis")
return_fields(player, "enchanting_item")
end) end)
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
@ -189,6 +196,8 @@ minetest.register_on_joinplayer(function(player)
when the server has been shutdown and the server didn't clean up the player when the server has been shutdown and the server didn't clean up the player
inventories. ]] inventories. ]]
return_fields(player, "craft") return_fields(player, "craft")
return_fields(player, "enchanting_item")
return_fields(player, "enchanting_lapis")
end) end)
if minetest.is_creative_enabled("") then if minetest.is_creative_enabled("") then

View File

@ -137,7 +137,7 @@ armor.set_player_armor = function(self, player)
local level = def.groups["armor_"..k] local level = def.groups["armor_"..k]
if level then if level then
local texture = def.texture or item:gsub("%:", "_") local texture = def.texture or item:gsub("%:", "_")
local enchanted_addition = (mcl_enchanting.is_enchanted_def(item) and "^[colorize:white:50^[colorize:purple:50" or "") local enchanted_addition = (mcl_enchanting.is_enchanted(item) and mcl_enchanting.overlay or "")
table.insert(textures, "("..texture..".png"..enchanted_addition..")") table.insert(textures, "("..texture..".png"..enchanted_addition..")")
preview = "(player.png^[opacity:0^"..texture.."_preview.png"..enchanted_addition..")"..(preview and "^"..preview or "") preview = "(player.png^[opacity:0^"..texture.."_preview.png"..enchanted_addition..")"..(preview and "^"..preview or "")
armor_level = armor_level + level armor_level = armor_level + level

View File

@ -13,7 +13,7 @@ minetest.register_tool("mcl_armor:helmet_leather", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_helmet_leather.png", inventory_image = "mcl_armor_inv_helmet_leather.png",
groups = {armor_head=1, mcl_armor_points=1, mcl_armor_uses=56}, groups = {armor_head=1, mcl_armor_points=1, mcl_armor_uses=56, enchantability=15},
_repair_material = "mcl_mobitems:leather", _repair_material = "mcl_mobitems:leather",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_leather", _mcl_armor_equip = "mcl_armor_equip_leather",
@ -28,7 +28,7 @@ minetest.register_tool("mcl_armor:helmet_iron", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_helmet_iron.png", inventory_image = "mcl_armor_inv_helmet_iron.png",
groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166}, groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166, enchantability=9 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -44,7 +44,7 @@ minetest.register_tool("mcl_armor:helmet_gold", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_helmet_gold.png", inventory_image = "mcl_armor_inv_helmet_gold.png",
groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=78}, groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=78, enchantability=25 },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -59,7 +59,7 @@ minetest.register_tool("mcl_armor:helmet_diamond",{
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_helmet_diamond.png", inventory_image = "mcl_armor_inv_helmet_diamond.png",
groups = {armor_head=1, mcl_armor_points=3, mcl_armor_uses=364, mcl_armor_toughness=2}, groups = {armor_head=1, mcl_armor_points=3, mcl_armor_uses=364, mcl_armor_toughness=2, enchantability=10 },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_diamond", _mcl_armor_equip = "mcl_armor_equip_diamond",
@ -74,7 +74,7 @@ minetest.register_tool("mcl_armor:helmet_chain", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_helmet_chain.png", inventory_image = "mcl_armor_inv_helmet_chain.png",
groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166}, groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166, enchantability=12 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_chainmail", _mcl_armor_equip = "mcl_armor_equip_chainmail",
@ -91,7 +91,7 @@ minetest.register_tool("mcl_armor:chestplate_leather", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_chestplate_leather.png", inventory_image = "mcl_armor_inv_chestplate_leather.png",
groups = {armor_torso=1, mcl_armor_points=3, mcl_armor_uses=81}, groups = {armor_torso=1, mcl_armor_points=3, mcl_armor_uses=81, enchantability=15 },
_repair_material = "mcl_mobitems:leather", _repair_material = "mcl_mobitems:leather",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_leather", _mcl_armor_equip = "mcl_armor_equip_leather",
@ -106,7 +106,7 @@ minetest.register_tool("mcl_armor:chestplate_iron", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_chestplate_iron.png", inventory_image = "mcl_armor_inv_chestplate_iron.png",
groups = {armor_torso=1, mcl_armor_points=6, mcl_armor_uses=241}, groups = {armor_torso=1, mcl_armor_points=6, mcl_armor_uses=241, enchantability=9 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -121,7 +121,7 @@ minetest.register_tool("mcl_armor:chestplate_gold", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_chestplate_gold.png", inventory_image = "mcl_armor_inv_chestplate_gold.png",
groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=113}, groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=113, enchantability=25 },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -136,7 +136,7 @@ minetest.register_tool("mcl_armor:chestplate_diamond",{
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_chestplate_diamond.png", inventory_image = "mcl_armor_inv_chestplate_diamond.png",
groups = {armor_torso=1, mcl_armor_points=8, mcl_armor_uses=529, mcl_armor_toughness=2}, groups = {armor_torso=1, mcl_armor_points=8, mcl_armor_uses=529, mcl_armor_toughness=2, enchantability=10 },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_diamond", _mcl_armor_equip = "mcl_armor_equip_diamond",
@ -151,7 +151,7 @@ minetest.register_tool("mcl_armor:chestplate_chain", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_chestplate_chain.png", inventory_image = "mcl_armor_inv_chestplate_chain.png",
groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=241}, groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=241, enchantability=12 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_chainmail", _mcl_armor_equip = "mcl_armor_equip_chainmail",
@ -168,7 +168,7 @@ minetest.register_tool("mcl_armor:leggings_leather", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_leggings_leather.png", inventory_image = "mcl_armor_inv_leggings_leather.png",
groups = {armor_legs=1, mcl_armor_points=2, mcl_armor_uses=76}, groups = {armor_legs=1, mcl_armor_points=2, mcl_armor_uses=76, enchantability=15 },
_repair_material = "mcl_mobitems:leather", _repair_material = "mcl_mobitems:leather",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_leather", _mcl_armor_equip = "mcl_armor_equip_leather",
@ -183,7 +183,7 @@ minetest.register_tool("mcl_armor:leggings_iron", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_leggings_iron.png", inventory_image = "mcl_armor_inv_leggings_iron.png",
groups = {armor_legs=1, mcl_armor_points=5, mcl_armor_uses=226}, groups = {armor_legs=1, mcl_armor_points=5, mcl_armor_uses=226, enchantability=9 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -198,7 +198,7 @@ minetest.register_tool("mcl_armor:leggings_gold", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_leggings_gold.png", inventory_image = "mcl_armor_inv_leggings_gold.png",
groups = {armor_legs=1, mcl_armor_points=3, mcl_armor_uses=106}, groups = {armor_legs=1, mcl_armor_points=3, mcl_armor_uses=106, enchantability=25 },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -213,7 +213,7 @@ minetest.register_tool("mcl_armor:leggings_diamond",{
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_leggings_diamond.png", inventory_image = "mcl_armor_inv_leggings_diamond.png",
groups = {armor_legs=1, mcl_armor_points=6, mcl_armor_uses=496, mcl_armor_toughness=2}, groups = {armor_legs=1, mcl_armor_points=6, mcl_armor_uses=496, mcl_armor_toughness=2, enchantability=10 },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_diamond", _mcl_armor_equip = "mcl_armor_equip_diamond",
@ -228,7 +228,7 @@ minetest.register_tool("mcl_armor:leggings_chain", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_leggings_chain.png", inventory_image = "mcl_armor_inv_leggings_chain.png",
groups = {armor_legs=1, mcl_armor_points=4, mcl_armor_uses=226}, groups = {armor_legs=1, mcl_armor_points=4, mcl_armor_uses=226, enchantability=12 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_chainmail", _mcl_armor_equip = "mcl_armor_equip_chainmail",
@ -244,7 +244,7 @@ minetest.register_tool("mcl_armor:boots_leather", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_boots_leather.png", inventory_image = "mcl_armor_inv_boots_leather.png",
groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=66}, groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=66, enchantability=15 },
_repair_material = "mcl_mobitems:leather", _repair_material = "mcl_mobitems:leather",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_leather", _mcl_armor_equip = "mcl_armor_equip_leather",
@ -259,7 +259,7 @@ minetest.register_tool("mcl_armor:boots_iron", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_boots_iron.png", inventory_image = "mcl_armor_inv_boots_iron.png",
groups = {armor_feet=1, mcl_armor_points=2, mcl_armor_uses=196}, groups = {armor_feet=1, mcl_armor_points=2, mcl_armor_uses=196, enchantability=9 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -274,7 +274,7 @@ minetest.register_tool("mcl_armor:boots_gold", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_boots_gold.png", inventory_image = "mcl_armor_inv_boots_gold.png",
groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=92}, groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=92, enchantability=25 },
_repair_material = "mcl_core:gold_ingot", _repair_material = "mcl_core:gold_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_iron", _mcl_armor_equip = "mcl_armor_equip_iron",
@ -289,7 +289,7 @@ minetest.register_tool("mcl_armor:boots_diamond",{
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_boots_diamond.png", inventory_image = "mcl_armor_inv_boots_diamond.png",
groups = {armor_feet=1, mcl_armor_points=3, mcl_armor_uses=430, mcl_armor_toughness=2}, groups = {armor_feet=1, mcl_armor_points=3, mcl_armor_uses=430, mcl_armor_toughness=2, enchantability=10 },
_repair_material = "mcl_core:diamond", _repair_material = "mcl_core:diamond",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_diamond", _mcl_armor_equip = "mcl_armor_equip_diamond",
@ -304,7 +304,7 @@ minetest.register_tool("mcl_armor:boots_chain", {
_doc_items_longdesc = longdesc, _doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage, _doc_items_usagehelp = usage,
inventory_image = "mcl_armor_inv_boots_chain.png", inventory_image = "mcl_armor_inv_boots_chain.png",
groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=196}, groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=196, enchantability=12 },
_repair_material = "mcl_core:iron_ingot", _repair_material = "mcl_core:iron_ingot",
sounds = { sounds = {
_mcl_armor_equip = "mcl_armor_equip_chainmail", _mcl_armor_equip = "mcl_armor_equip_chainmail",

View File

@ -15,7 +15,8 @@ minetest.register_craftitem("mcl_books:book", {
_doc_items_longdesc = S("Books are used to make bookshelves and book and quills."), _doc_items_longdesc = S("Books are used to make bookshelves and book and quills."),
inventory_image = "default_book.png", inventory_image = "default_book.png",
stack_max = 64, stack_max = 64,
groups = { book=1, craftitem = 1 }, groups = { book=1, craftitem = 1, enchantability = 1 },
_mcl_enchanting_enchanted_tool = "mcl_enchanting:book_enchanted",
}) })
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then

View File

@ -133,7 +133,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
range = 1, range = 1,
-- Trick to disable digging as well -- Trick to disable digging as well
on_use = function() end, on_use = function() end,
groups = {weapon=1,weapon_ranged=1,bow=1}, groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1},
}) })
-- Iterates through player inventory and resets all the bows in "charging" state back to their original stage -- Iterates through player inventory and resets all the bows in "charging" state back to their original stage
@ -173,10 +173,10 @@ for level=0, 2 do
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
stack_max = 1, stack_max = 1,
range = 0, -- Pointing range to 0 to prevent punching with bow :D range = 0, -- Pointing range to 0 to prevent punching with bow :D
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1},
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)
reset_bow_state(dropper) reset_bow_state(dropper)
if mcl_enchanting.is_enchanted(itemstack) then if mcl_enchanting.is_enchanted(itemstack:get_name()) then
itemstack:set_name("mcl_bows:bow_enchanted") itemstack:set_name("mcl_bows:bow_enchanted")
else else
itemstack:set_name("mcl_bows:bow") itemstack:set_name("mcl_bows:bow")
@ -201,7 +201,7 @@ controls.register_on_release(function(player, key, time)
wielditem:get_name()=="mcl_bows:bow_0_enchanted" or wielditem:get_name()=="mcl_bows:bow_1_enchanted" or wielditem:get_name()=="mcl_bows:bow_2_enchanted") then wielditem:get_name()=="mcl_bows:bow_0_enchanted" or wielditem:get_name()=="mcl_bows:bow_1_enchanted" or wielditem:get_name()=="mcl_bows:bow_2_enchanted") then
local has_shot = false local has_shot = false
local enchanted = mcl_enchanting.is_enchanted(wielditem) local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
local speed, damage local speed, damage
local p_load = bow_load[player:get_player_name()] local p_load = bow_load[player:get_player_name()]
local charge local charge
@ -269,7 +269,7 @@ controls.register_on_hold(function(player, key, time)
local inv = minetest.get_inventory({type="player", name=name}) local inv = minetest.get_inventory({type="player", name=name})
local wielditem = player:get_wielded_item() local wielditem = player:get_wielded_item()
if bow_load[name] == nil and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted") and (creative or get_arrow(player)) then if bow_load[name] == nil and (wielditem:get_name()=="mcl_bows:bow" or wielditem:get_name()=="mcl_bows:bow_enchanted") and (creative or get_arrow(player)) then
local enchanted = mcl_enchanting.is_enchanted(wielditem) local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
if enchanted then if enchanted then
wielditem:set_name("mcl_bows:bow_0_enchanted") wielditem:set_name("mcl_bows:bow_0_enchanted")
else else

View File

@ -57,7 +57,7 @@ minetest.register_globalstep(function(dtime)
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
local itemname = "mcl_compass:"..compass_image local itemname = "mcl_compass:"..compass_image
if mcl_enchanting.is_enchanted(stack) then if mcl_enchanting.is_enchanted(stack:get_name()) then
itemname = itemname .. "_enchanted" itemname = itemname .. "_enchanted"
end end
stack:set_name(itemname) stack:set_name(itemname)
@ -98,7 +98,7 @@ for i,img in ipairs(images) do
inventory_image = img, inventory_image = img,
wield_image = img, wield_image = img,
stack_max = 64, stack_max = 64,
groups = {not_in_creative_inventory=inv, compass=i, tool=1, disable_repair=1} groups = {not_in_creative_inventory=inv, compass=i, tool=1, disable_repair=1, enchantability=1 }
}) })
-- Help aliases. Makes sure the lookup tool works correctly -- Help aliases. Makes sure the lookup tool works correctly

View File

@ -70,7 +70,7 @@ minetest.register_tool("mcl_farming:hoe_wood", {
inventory_image = "farming_tool_woodhoe.png", inventory_image = "farming_tool_woodhoe.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
on_place = hoe_on_place_function(uses.wood), on_place = hoe_on_place_function(uses.wood),
groups = { tool=1, hoe=1 }, groups = { tool=1, hoe=1, enchantability=15 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
damage_groups = { fleshy = 1, }, damage_groups = { fleshy = 1, },
@ -109,7 +109,7 @@ minetest.register_tool("mcl_farming:hoe_stone", {
inventory_image = "farming_tool_stonehoe.png", inventory_image = "farming_tool_stonehoe.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
on_place = hoe_on_place_function(uses.stone), on_place = hoe_on_place_function(uses.stone),
groups = { tool=1, hoe=1 }, groups = { tool=1, hoe=1, enchantability=5 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.5, full_punch_interval = 0.5,
damage_groups = { fleshy = 1, }, damage_groups = { fleshy = 1, },
@ -143,7 +143,7 @@ minetest.register_tool("mcl_farming:hoe_iron", {
inventory_image = "farming_tool_steelhoe.png", inventory_image = "farming_tool_steelhoe.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
on_place = hoe_on_place_function(uses.iron), on_place = hoe_on_place_function(uses.iron),
groups = { tool=1, hoe=1 }, groups = { tool=1, hoe=1, enchantability=14 },
tool_capabilities = { tool_capabilities = {
-- 1/3 -- 1/3
full_punch_interval = 0.33333333, full_punch_interval = 0.33333333,
@ -185,7 +185,7 @@ minetest.register_tool("mcl_farming:hoe_gold", {
inventory_image = "farming_tool_goldhoe.png", inventory_image = "farming_tool_goldhoe.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
on_place = hoe_on_place_function(uses.gold), on_place = hoe_on_place_function(uses.gold),
groups = { tool=1, hoe=1 }, groups = { tool=1, hoe=1, enchantability=22 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
damage_groups = { fleshy = 1, }, damage_groups = { fleshy = 1, },
@ -228,7 +228,7 @@ minetest.register_tool("mcl_farming:hoe_diamond", {
inventory_image = "farming_tool_diamondhoe.png", inventory_image = "farming_tool_diamondhoe.png",
wield_scale = { x = 1.8, y = 1.8, z = 1 }, wield_scale = { x = 1.8, y = 1.8, z = 1 },
on_place = hoe_on_place_function(uses.diamond), on_place = hoe_on_place_function(uses.diamond),
groups = { tool=1, hoe=1 }, groups = { tool=1, hoe=1, enchantability=10 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.25, full_punch_interval = 0.25,
damage_groups = { fleshy = 1, }, damage_groups = { fleshy = 1, },

View File

@ -112,6 +112,7 @@ pumpkin_face_base_def._doc_items_longdesc = S("A pumpkin can be worn as a helmet
pumpkin_face_base_def._doc_items_usagehelp = nil pumpkin_face_base_def._doc_items_usagehelp = nil
pumpkin_face_base_def.tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"} pumpkin_face_base_def.tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"}
pumpkin_face_base_def.groups.armor_head=1 pumpkin_face_base_def.groups.armor_head=1
pumpkin_face_base_def.groups.enchantability=1
pumpkin_face_base_def._mcl_armor_mob_range_factor = 0 pumpkin_face_base_def._mcl_armor_mob_range_factor = 0
pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:enderman" pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:enderman"
pumpkin_face_base_def.groups.non_combat_armor=1 pumpkin_face_base_def.groups.non_combat_armor=1

View File

@ -9,7 +9,7 @@ minetest.register_tool("mcl_fire:flint_and_steel", {
inventory_image = "mcl_fire_flint_and_steel.png", inventory_image = "mcl_fire_flint_and_steel.png",
liquids_pointable = false, liquids_pointable = false,
stack_max = 1, stack_max = 1,
groups = { tool = 1 }, groups = { tool = 1, enchantability = 1 },
on_place = function(itemstack, user, pointed_thing) on_place = function(itemstack, user, pointed_thing)
-- Use pointed node's on_rightclick function first, if present -- Use pointed node's on_rightclick function first, if present
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)

View File

@ -322,7 +322,7 @@ minetest.register_tool("mcl_fishing:fishing_rod", {
_tt_help = S("Catches fish in water"), _tt_help = S("Catches fish in water"),
_doc_items_longdesc = S("Fishing rods can be used to catch fish."), _doc_items_longdesc = S("Fishing rods can be used to catch fish."),
_doc_items_usagehelp = S("Rightclick to launch the bobber. When it sinks right-click again to reel in an item. Who knows what you're going to catch?"), _doc_items_usagehelp = S("Rightclick to launch the bobber. When it sinks right-click again to reel in an item. Who knows what you're going to catch?"),
groups = { tool=1, fishing_rod=1 }, groups = { tool=1, fishing_rod=1, enchantability=1 },
inventory_image = "mcl_fishing_fishing_rod.png", inventory_image = "mcl_fishing_fishing_rod.png",
wield_image = "mcl_fishing_fishing_rod.png^[transformR270", wield_image = "mcl_fishing_fishing_rod.png^[transformR270",
wield_scale = { x = 1.5, y = 1.5, z = 1 }, wield_scale = { x = 1.5, y = 1.5, z = 1 },

View File

@ -42,7 +42,7 @@ local function addhead(name, texture, desc, longdesc, rangemob, rangefactor)
{ -0.25, -0.5, -0.25, 0.25, 0.0, 0.25, }, { -0.25, -0.5, -0.25, 0.25, 0.0, 0.25, },
}, },
}, },
groups = {handy=1, armor_head=1,non_combat_armor=1, head=1, deco_block=1, dig_by_piston=1}, groups = {handy=1, armor_head=1,non_combat_armor=1, head=1, deco_block=1, dig_by_piston=1, enchantability=1},
-- The head textures are based off the textures of an actual mob. -- The head textures are based off the textures of an actual mob.
tiles = { tiles = {
-- Note: bottom texture is overlaid over top texture to get rid of possible transparency. -- Note: bottom texture is overlaid over top texture to get rid of possible transparency.

View File

@ -81,7 +81,7 @@ minetest.register_tool("mcl_tools:pick_wood", {
_doc_items_hidden = false, _doc_items_hidden = false,
inventory_image = "default_tool_woodpick.png", inventory_image = "default_tool_woodpick.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, pickaxe=1, dig_speed_class=2, }, groups = { tool=1, pickaxe=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = { tool_capabilities = {
-- 1/1.2 -- 1/1.2
full_punch_interval = 0.83333333, full_punch_interval = 0.83333333,
@ -100,7 +100,7 @@ minetest.register_tool("mcl_tools:pick_stone", {
_doc_items_longdesc = pickaxe_longdesc, _doc_items_longdesc = pickaxe_longdesc,
inventory_image = "default_tool_stonepick.png", inventory_image = "default_tool_stonepick.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, pickaxe=1, dig_speed_class=3, }, groups = { tool=1, pickaxe=1, dig_speed_class=3, enchantability=5 },
tool_capabilities = { tool_capabilities = {
-- 1/1.2 -- 1/1.2
full_punch_interval = 0.83333333, full_punch_interval = 0.83333333,
@ -119,7 +119,7 @@ minetest.register_tool("mcl_tools:pick_iron", {
_doc_items_longdesc = pickaxe_longdesc, _doc_items_longdesc = pickaxe_longdesc,
inventory_image = "default_tool_steelpick.png", inventory_image = "default_tool_steelpick.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, pickaxe=1, dig_speed_class=4, }, groups = { tool=1, pickaxe=1, dig_speed_class=4, enchantability=14 },
tool_capabilities = { tool_capabilities = {
-- 1/1.2 -- 1/1.2
full_punch_interval = 0.83333333, full_punch_interval = 0.83333333,
@ -138,7 +138,7 @@ minetest.register_tool("mcl_tools:pick_gold", {
_doc_items_longdesc = pickaxe_longdesc, _doc_items_longdesc = pickaxe_longdesc,
inventory_image = "default_tool_goldpick.png", inventory_image = "default_tool_goldpick.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, pickaxe=1, dig_speed_class=6, }, groups = { tool=1, pickaxe=1, dig_speed_class=6, enchantability=22 },
tool_capabilities = { tool_capabilities = {
-- 1/1.2 -- 1/1.2
full_punch_interval = 0.83333333, full_punch_interval = 0.83333333,
@ -157,7 +157,7 @@ minetest.register_tool("mcl_tools:pick_diamond", {
_doc_items_longdesc = pickaxe_longdesc, _doc_items_longdesc = pickaxe_longdesc,
inventory_image = "default_tool_diamondpick.png", inventory_image = "default_tool_diamondpick.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, pickaxe=1, dig_speed_class=5, }, groups = { tool=1, pickaxe=1, dig_speed_class=5, enchantability=10 },
tool_capabilities = { tool_capabilities = {
-- 1/1.2 -- 1/1.2
full_punch_interval = 0.83333333, full_punch_interval = 0.83333333,
@ -277,7 +277,7 @@ minetest.register_tool("mcl_tools:shovel_wood", {
inventory_image = "default_tool_woodshovel.png", inventory_image = "default_tool_woodshovel.png",
wield_image = "default_tool_woodshovel.png^[transformR90", wield_image = "default_tool_woodshovel.png^[transformR90",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, shovel=1, dig_speed_class=2, }, groups = { tool=1, shovel=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
max_drop_level=1, max_drop_level=1,
@ -298,7 +298,7 @@ minetest.register_tool("mcl_tools:shovel_stone", {
inventory_image = "default_tool_stoneshovel.png", inventory_image = "default_tool_stoneshovel.png",
wield_image = "default_tool_stoneshovel.png^[transformR90", wield_image = "default_tool_stoneshovel.png^[transformR90",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, shovel=1, dig_speed_class=3, }, groups = { tool=1, shovel=1, dig_speed_class=3, enchantability=5 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
max_drop_level=3, max_drop_level=3,
@ -319,7 +319,7 @@ minetest.register_tool("mcl_tools:shovel_iron", {
inventory_image = "default_tool_steelshovel.png", inventory_image = "default_tool_steelshovel.png",
wield_image = "default_tool_steelshovel.png^[transformR90", wield_image = "default_tool_steelshovel.png^[transformR90",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, shovel=1, dig_speed_class=4, }, groups = { tool=1, shovel=1, dig_speed_class=4, enchantability=14 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
max_drop_level=4, max_drop_level=4,
@ -361,7 +361,7 @@ minetest.register_tool("mcl_tools:shovel_diamond", {
inventory_image = "default_tool_diamondshovel.png", inventory_image = "default_tool_diamondshovel.png",
wield_image = "default_tool_diamondshovel.png^[transformR90", wield_image = "default_tool_diamondshovel.png^[transformR90",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, shovel=1, dig_speed_class=5, }, groups = { tool=1, shovel=1, dig_speed_class=5, enchantability=10 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1, full_punch_interval = 1,
max_drop_level=5, max_drop_level=5,
@ -383,7 +383,7 @@ minetest.register_tool("mcl_tools:axe_wood", {
_doc_items_hidden = false, _doc_items_hidden = false,
inventory_image = "default_tool_woodaxe.png", inventory_image = "default_tool_woodaxe.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, axe=1, dig_speed_class=2, }, groups = { tool=1, axe=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.25, full_punch_interval = 1.25,
max_drop_level=1, max_drop_level=1,
@ -401,7 +401,7 @@ minetest.register_tool("mcl_tools:axe_stone", {
_doc_items_longdesc = axe_longdesc, _doc_items_longdesc = axe_longdesc,
inventory_image = "default_tool_stoneaxe.png", inventory_image = "default_tool_stoneaxe.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, axe=1, dig_speed_class=3, }, groups = { tool=1, axe=1, dig_speed_class=3, enchantability=5 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.25, full_punch_interval = 1.25,
max_drop_level=3, max_drop_level=3,
@ -419,7 +419,7 @@ minetest.register_tool("mcl_tools:axe_iron", {
_doc_items_longdesc = axe_longdesc, _doc_items_longdesc = axe_longdesc,
inventory_image = "default_tool_steelaxe.png", inventory_image = "default_tool_steelaxe.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, axe=1, dig_speed_class=4, }, groups = { tool=1, axe=1, dig_speed_class=4, enchantability=14 },
tool_capabilities = { tool_capabilities = {
-- 1/0.9 -- 1/0.9
full_punch_interval = 1.11111111, full_punch_interval = 1.11111111,
@ -438,7 +438,7 @@ minetest.register_tool("mcl_tools:axe_gold", {
_doc_items_longdesc = axe_longdesc, _doc_items_longdesc = axe_longdesc,
inventory_image = "default_tool_goldaxe.png", inventory_image = "default_tool_goldaxe.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, axe=1, dig_speed_class=6, }, groups = { tool=1, axe=1, dig_speed_class=6, enchantability=22 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.0, full_punch_interval = 1.0,
max_drop_level=2, max_drop_level=2,
@ -456,7 +456,7 @@ minetest.register_tool("mcl_tools:axe_diamond", {
_doc_items_longdesc = axe_longdesc, _doc_items_longdesc = axe_longdesc,
inventory_image = "default_tool_diamondaxe.png", inventory_image = "default_tool_diamondaxe.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { tool=1, axe=1, dig_speed_class=5, }, groups = { tool=1, axe=1, dig_speed_class=5, enchantability=10 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.0, full_punch_interval = 1.0,
max_drop_level=5, max_drop_level=5,
@ -477,7 +477,7 @@ minetest.register_tool("mcl_tools:sword_wood", {
_doc_items_hidden = false, _doc_items_hidden = false,
inventory_image = "default_tool_woodsword.png", inventory_image = "default_tool_woodsword.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { weapon=1, sword=1, dig_speed_class=2, }, groups = { weapon=1, sword=1, dig_speed_class=2, enchantability=15 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.625, full_punch_interval = 0.625,
max_drop_level=1, max_drop_level=1,
@ -496,7 +496,7 @@ minetest.register_tool("mcl_tools:sword_stone", {
_doc_items_longdesc = sword_longdesc, _doc_items_longdesc = sword_longdesc,
inventory_image = "default_tool_stonesword.png", inventory_image = "default_tool_stonesword.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { weapon=1, sword=1, dig_speed_class=3, }, groups = { weapon=1, sword=1, dig_speed_class=3, enchantability=5 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.625, full_punch_interval = 0.625,
max_drop_level=3, max_drop_level=3,
@ -515,7 +515,7 @@ minetest.register_tool("mcl_tools:sword_iron", {
_doc_items_longdesc = sword_longdesc, _doc_items_longdesc = sword_longdesc,
inventory_image = "default_tool_steelsword.png", inventory_image = "default_tool_steelsword.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { weapon=1, sword=1, dig_speed_class=4, }, groups = { weapon=1, sword=1, dig_speed_class=4, enchantability=14 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.625, full_punch_interval = 0.625,
max_drop_level=4, max_drop_level=4,
@ -534,7 +534,7 @@ minetest.register_tool("mcl_tools:sword_gold", {
_doc_items_longdesc = sword_longdesc, _doc_items_longdesc = sword_longdesc,
inventory_image = "default_tool_goldsword.png", inventory_image = "default_tool_goldsword.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { weapon=1, sword=1, dig_speed_class=6, }, groups = { weapon=1, sword=1, dig_speed_class=6, enchantability=22 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.625, full_punch_interval = 0.625,
max_drop_level=2, max_drop_level=2,
@ -553,7 +553,7 @@ minetest.register_tool("mcl_tools:sword_diamond", {
_doc_items_longdesc = sword_longdesc, _doc_items_longdesc = sword_longdesc,
inventory_image = "default_tool_diamondsword.png", inventory_image = "default_tool_diamondsword.png",
wield_scale = wield_scale, wield_scale = wield_scale,
groups = { weapon=1, sword=1, dig_speed_class=5, }, groups = { weapon=1, sword=1, dig_speed_class=5, enchantability=10 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.625, full_punch_interval = 0.625,
max_drop_level=5, max_drop_level=5,
@ -576,7 +576,7 @@ minetest.register_tool("mcl_tools:shears", {
inventory_image = "default_tool_shears.png", inventory_image = "default_tool_shears.png",
wield_image = "default_tool_shears.png", wield_image = "default_tool_shears.png",
stack_max = 1, stack_max = 1,
groups = { tool=1, shears=1, dig_speed_class=4, }, groups = { tool=1, shears=1, dig_speed_class=4, enchantability=1 },
tool_capabilities = { tool_capabilities = {
full_punch_interval = 0.5, full_punch_interval = 0.5,
max_drop_level=1, max_drop_level=1,

View File

@ -176,7 +176,7 @@ minetest.register_tool("screwdriver:screwdriver", {
description = S("Screwdriver"), description = S("Screwdriver"),
inventory_image = "screwdriver.png", inventory_image = "screwdriver.png",
wield_image = "screwdriver.png^[transformFX", wield_image = "screwdriver.png^[transformFX",
groups = { tool = 1, not_in_creative_inventory = 1 }, groups = { tool = 1, not_in_creative_inventory = 1, enchantability = 1 },
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE, 200) screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE, 200)
return itemstack return itemstack