Proper anvil naming support

This commit is contained in:
Elias Fleckenstein 2020-11-01 13:44:05 +01:00
parent 76303ae194
commit 26f3d821a4
57 changed files with 734 additions and 578 deletions

View file

@ -1,344 +0,0 @@
-- Taken from https://minecraft.gamepedia.com/Enchanting
mcl_enchanting.enchantments = {
-- unimplemented
aqua_affinity = {
name = "Aqua Affinity",
max_level = 1,
primary = {armor_head = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 2,
description = "Increases underwater mining speed."
},
-- unimplemented
bane_of_anthropods = {
name = "Bane of Anthropods",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {smite = true, shaprness = true},
weight = 5,
description = "Increases damage and applies Slowness IV to arthropod mobs (spiders, cave spiders, silverfish and endermites)."
},
-- unimplemented
blast_protection = {
name = "Blast Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {fire_protection = true, protection = true, projectile_protection = true},
weight = 2,
description = "Reduces explosion damage and knockback."
},
-- unimplemented
curse_of_binding = {
name = "Curse of Binding",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
disallow = {},
incompatible = {},
weight = 1,
description = "Except when in creative mode, items cannot be removed from armor slots except due to death or breaking."
},
-- unimplemented
curse_of_vanishing = {
name = "Curse of Vanishing",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {clock = true},
incompatible = {},
weight = 1,
description = "Except when in creative mode, items cannot be removed from armor slots except due to death or breaking."
},
-- unimplemented
depth_strider = {
name = "Depth Strider",
max_level = 3,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {frost_walker = true},
weight = 2,
description = "Increases underwater movement speed."
},
-- unimplemented
efficiency = {
name = "Efficiency",
max_level = 5,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {shears = true},
disallow = {},
incompatible = {},
weight = 10,
description = "Increases mining speed."
},
-- unimplemented
feather_falling = {
name = "Feather Falling",
max_level = 4,
primary = {armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 5,
description = "Reduces fall damage."
},
-- unimplemented
fire_aspect = {
name = "Fire Aspect",
max_level = 2,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Sets target on fire."
},
-- unimplemented
fire_protection = {
name = "Fire Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, protection = true, projectile_protection = true},
weight = 5,
description = "Reduces fire damage."
},
-- unimplemented
flame = {
name = "Flame",
max_level = 1,
primary = {bow = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Arrows set target on fire."
},
-- unimplemented
fortune = {
name = "Fortune",
max_level = 4,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {},
disallow = {},
incompatible = {silk_touch = true},
weight = 2,
description = "Increases certain block drops."
},
-- unimplemented
frost_walker = {
name = "Frost Walker",
max_level = 2,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {depth_strider = true},
weight = 2,
description = "Turns water beneath the player into frosted ice and prevents the damage the player would take from standing on magma blocks."
},
infinity = {
name = "Infinity",
max_level = 1,
primary = {bow = true},
secondary = {},
disallow = {},
incompatible = {mending = true},
weight = 1,
description = "Shooting consumes no regular arrows."
},
-- unimplemented
knockback = {
name = "Knockback",
max_level = 2,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 5,
description = "Increases knockback."
},
-- unimplemented
looting = {
name = "Looting",
max_level = 3,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases mob loot."
},
-- unimplemented
luck_of_the_sea = {
name = "Luck of the Sea",
max_level = 3,
primary = {fishing_rod = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases rate of good loot (enchanting books, etc.)"
},
-- unimplemented
lure = {
name = "Lure",
max_level = 3,
primary = {fishing_rod = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Decreases wait time until fish/junk/loot \"bites\"."
},
-- unimplemented
mending = {
name = "Mending",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {non_combat_armor = true, compass = true, clock = true},
incompatible = {infinity = true},
weight = 2,
description = "Repair the item while gaining XP orbs."
},
-- unimplemented
power = {
name = "Power",
max_level = 5,
primary = {},
secondary = {bow = true},
disallow = {},
incompatible = {},
weight = 10,
description = "Increases arrow damage."
},
-- unimplemented
projectile_protection = {
name = "Projectile Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, protection = true},
weight = 5,
description = "Reduces projectile damage."
},
-- unimplemented
protection = {
name = "Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true},
weight = 10,
description = "Reduces most types of damage by 4% for each level."
},
-- unimplemented
punch = {
name = "Punch",
max_level = 2,
primary = {},
secondary = {bow = true},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases arrow knockback."
},
-- unimplemented
respiration = {
name = "Respiration",
max_level = 3,
primary = {armor_head = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 2,
description = "Extends underwater breathing time."
},
-- unimplemented
sharpness = {
name = "Sharpness",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {bane_of_anthropods = true, smite = true},
weight = 5,
description = "Increases damage and applies Slowness IV to arthropod mobs (spiders, cave spiders, silverfish and endermites)."
},
-- unimplemented
silk_touch = {
name = "Silk Touch",
max_level = 1,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {shears = true},
disallow = {},
incompatible = {fortune = true},
weight = 1,
description = "Mined blocks drop themselves."
},
-- unimplemented
smite = {
name = "Smite",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {bane_of_anthropods = true, sharpness = true},
weight = 5,
description = "Increases damage to undead mobs."
},
-- unimplemented
soul_speed = {
name = "Soul Speed",
max_level = 3,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {frost_walker = true},
weight = 2,
description = "Incerases walking speed on soul sand."
},
-- unimplemented
sweeping_edge = {
name = "Sweeping Edge",
max_level = 3,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases sweeping attack damage."
},
-- unimplemented
thorns = {
name = "Thorns",
max_level = 3,
primary = {armor_head = true},
secondary = {armor_torso = true, armor_legs = true, armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true},
weight = 1,
description = "Reflects some of the damage taken when hit, at the cost of reducing durability with each proc."
},
-- unimplemented
unbreaking = {
name = "Unbreaking",
max_level = 3,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, pickaxe = true, shovel = true, axe = true, hoe = true, sword = true, fishing_rod = true, bow = true},
secondary = {tool = true},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 5,
description = "Increases item durability."
},
}

View file

@ -1,124 +0,0 @@
mcl_enchanting.features = {}
--[[
local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local pickaxes_better_than_stone = {"mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local shovels = {"mcl_tools:shovel_wood", "mcl_tools:shovel_stone", "mcl_tools:shovel_gold", "mcl_tools:shovel_iron", "mcl_tools:shovel_diamond"}
local silk_touch_tool_lists = {
["mcl_books:bookshelf"] = true,
["mcl_core:clay"] = true,
["mcl_core:stone_with_coal"] = pickaxes,
["group:coral_block"] = pickaxes,
["group:coral"] = true,
["group:coral_fan"] = true,
["mcl_core:stone_with_diamond"] = pickaxes_better_than_iron,
["mcl_core:stone_with_emerald"] = pickaxes_better_than_iron,
["mcl_chests:ender_chest"] = pickaxes,
["group:glass"] = true,
["mcl_nether:glowstone"] = true,
["mcl_core:dirt_with_grass"] = true,
["mcl_core:gravel"] = true,
["mcl_core:ice"] = true,
["mcl_core:stone_with_lapis"] = pickaxes_better_than_stone,
["group:leaves"] = true,
["mcl_farming:melon"] = true,
["group:huge_mushroom"] = true,
["mcl_core:mycelium"] = true,
["mcl_nether:quartz_ore"] = pickaxes,
["mcl_core:packed_ice"] = true,
["mcl_core:podzol"] = true,
["mcl_core:stone_with_redstone"] = pickaxes_better_than_iron,
["mcl_ocean:sea_lantern"] = true,
["group:top_snow"] = shovels,
["mcl_core:snowblock"] = shovels,
["mcl_core:stone"] = pickaxes,
}
minetest.register_on_mods_loaded(function()
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if digger and digger:is_player() then
local wielditem = digger:get_wielded_item()
local tooldef = wielditem:get_definition()
if tooldef._silk_touch then
local nodename = minetest.get_node(pos).name
local nodedef = minetest.registered_nodes[nodename]
local silk_touch_spec = silk_touch_tool_lists[nodename]
local suitable_tool = false
local tool_list
if silk_touch_spec == true then
suitable_tool = true
elseif silk_touch_spec then
tool_list = silk_touch_spec
else
for k, v in pairs(nodedef.groups) do
if v > 0 then
local group_spec = silk_touch_tool_lists["group:" .. k]
if group_spec == true then
suitable_tool = true
elseif group_spec then
toollist = group_spec
break
end
end
end
end
if tool_list and not suitable_tool then
suitable_tool = (table.indexof(tool_list, tooldef._original_tool) ~= -1)
end
if suitable_tool then
drops = {nodename}
end
end
end
old_handle_node_drops(pos, drops, digger)
end
end)
--]]
--[[
sharpness = {
name = "Sharpness",
max_level = 5,
create_itemdef = function(def, level)
def.tool_capabilities.damage_groups.fleshy = def.tool_capabilities.damage_groups.fleshy + (level + 1) / 2
end,
},
efficiency = {
name = "Efficiency",
max_level = 5,
create_itemdef = function(def, level)
local groupcaps = def.tool_capabilities.groupcaps
for _, groupcap in pairs(groupcaps) do
for i, t in pairs(groupcap.times) do
local m = 1 / t
m = m + math.pow(level, 2) + 1
groupcap.times[i] = 1 / m
end
end
end,
},
unbreaking = {
name = "Unbreaking",
max_level = 3,
create_itemdef = function(def, level)
local toolcaps = def.tool_capabilities
local armor_uses = def.groups.mcl_armor_uses
local factor = 0.5
if toolcaps then
local groupcaps = toolcaps.groupcaps
for _, groupcap in pairs(groupcaps) do
groupcap.uses = math.floor(groupcap.uses * (1 + level))
end
def.tool_capabilities.punch_attack_uses = math.floor(def.tool_capabilities.punch_attack_uses * (1 + level))
elseif armor_uses then
def.groups.mcl_armor_uses = math.floor(armor_uses / (0.6 + (0.4 / (level + 1))))
end
end
},
},--]]

View file

@ -1,87 +1,3 @@
mcl_enchanting.total_weight = 0
mcl_enchanting.all_item_groups = {}
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local all_item_groups = {}
for primary in pairs(enchantment_def.primary) do
all_item_groups[primary] = true
mcl_enchanting.all_item_groups[primary] = true
end
for secondary in pairs(enchantment_def.secondary) do
all_item_groups[secondary] = true
mcl_enchanting.all_item_groups[secondary] = true
end
enchantment_def.all = all_item_groups
mcl_enchanting.total_weight = mcl_enchanting.total_weight + enchantment_def.weight
end
--[[
minetest.register_on_mods_loaded(function()
for toolname, tooldef in pairs(minetest.registered_tools) do
for _, material in pairs(tooldef.materials) do
local full_name = toolname .. ((material == "") and "" or "_" .. material)
local old_def = minetest.registered_tools[full_name]
if not old_def then break end
mcl_enchanting.all_tools[full_name] = toolname
for _, enchantment in pairs(tooldef.enchantments) do
local enchantment_def = mcl_enchanting.enchantments[enchantment]
for lvl = 1, enchantment_def.max_level do
local new_def = table.copy(old_def)
new_def.description = minetest.colorize("#54FCFC", old_def.description) .. "\n" .. mcl_enchanting.get_enchantment_description(enchantment, lvl)
new_def.inventory_image = old_def.inventory_image .. "^[colorize:violet:50"
new_def.groups.not_in_creative_inventory = 1
new_def.texture = old_def.texture or full_name:gsub("%:", "_")
new_def._original_tool = full_name
enchantment_def.create_itemdef(new_def, lvl)
minetest.register_tool(":" .. full_name .. "_enchanted_" .. enchantment .. "_" .. lvl, new_def)
end
end
end
end
end)
--]]
minetest.register_on_mods_loaded(function()
local register_list = {}
for toolname, tooldef in pairs(minetest.registered_tools) do
if tooldef.groups.enchanted then
break
end
local quick_test = false
for group, groupv in pairs(tooldef.groups) do
if groupv > 0 and mcl_enchanting.all_item_groups[group] then
quick_test = true
break
end
end
if quick_test then
--print(toolname)
local expensive_test = false
for enchantment in pairs(mcl_enchanting.enchantments) do
if mcl_enchanting.item_supports_enchantment(toolname, enchantment, true) then
-- print("\tSupports " .. enchantment)
expensive_test = true
break
end
end
if expensive_test then
local new_name = toolname .. "_enchanted"
minetest.override_item(toolname, {_mcl_enchanting_enchanted_tool = new_name})
local new_def = table.copy(tooldef)
new_def.inventory_image = tooldef.inventory_image .. "^[colorize:purple:50"
new_def.groups.not_in_creative_inventory = 1
new_def.groups.enchanted = 1
new_def.texture = tooldef.texture or toolname:gsub("%:", "_")
new_def._mcl_enchanting_enchanted_tool = new_name
register_list[":" .. new_name] = new_def
end
end
end
for new_name, new_def in pairs(register_list) do
minetest.register_tool(new_name, new_def)
end
end)
function mcl_enchanting.get_enchantments(itemstack)
return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {}
end
@ -90,8 +6,12 @@ function mcl_enchanting.set_enchantments(itemstack, enchantments)
return itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
end
function mcl_enchanting.get_enchantment(itemstack, enchantment, data)
return (data or mcl_enchanting.get_enchantments(itemstack))[enchantment] or 0
function mcl_enchanting.get_enchantment(itemstack, enchantment)
return mcl_enchanting.get_enchantments(itemstack)[enchantment] or 0
end
function mcl_enchanting.has_enchantment(itemstack, enchantment)
return mcl_enchanting.get_enchantment(itemstack, enchantment) > 0
end
function mcl_enchanting.get_enchantment_description(enchantment, level)
@ -99,16 +19,32 @@ function mcl_enchanting.get_enchantment_description(enchantment, level)
return enchantment_def.name .. (enchantment_def.max_level == 1 and "" or " " .. mcl_enchanting.roman_numerals.toRoman(level))
end
function mcl_enchanting.get_colorized_enchantment_description(enchantment, level)
return minetest.colorize(mcl_enchanting.enchantments[enchantment].curse and "#FC5454" or "#A8A8A8", mcl_enchanting.get_enchantment_description(enchantment, level))
end
function mcl_enchanting.get_enchanted_itemstring(itemname)
local def = minetest.registered_items[itemname]
local def = minetest.registered_items[itemname]
return def and def._mcl_enchanting_enchanted_tool
end
function mcl_enchanting.is_enchanted_def(itemname)
return minetest.get_item_group(itemname, "enchanted") > 0
end
function mcl_enchanting.is_enchanted(itemstack)
return mcl_enchanting.is_enchanted_def(itemstack:get_name())
end
function mcl_enchanting.item_supports_enchantment(itemname, enchantment, early)
if not early and not mcl_enchanting.get_enchanted_itemstring(itemname) then
return false
end
local enchantment_def = mcl_enchanting.enchantments[enchantment]
local tooldef = minetest.registered_tools[itemname]
if not tooldef and enchantment_def.requires_tool then
return false
end
for disallow in pairs(enchantment_def.disallow) do
if minetest.get_item_group(itemname, disallow) > 0 then
return false
@ -167,10 +103,104 @@ end
function mcl_enchanting.reload_enchantments(itemstack, enchantments)
local itemdef = itemstack:get_definition()
for enchantment, level in pairs(enchantments) do
local func = mcl_enchanting.features[enchantment]
if func then
func(itemstack, level, itemdef)
local enchantment_def = mcl_enchanting.enchantments[enchantment]
if enchantment_def.on_enchant then
enchantment_def.on_enchant(itemstack, level, itemdef)
end
end
tt.reload_itemstack_description(itemstack)
end
function mcl_enchanting.initialize()
local tool_list = {}
local item_list = {}
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local all_item_groups = {}
for primary in pairs(enchantment_def.primary) do
all_item_groups[primary] = true
mcl_enchanting.all_item_groups[primary] = true
end
for secondary in pairs(enchantment_def.secondary) do
all_item_groups[secondary] = true
mcl_enchanting.all_item_groups[secondary] = true
end
enchantment_def.all = all_item_groups
mcl_enchanting.total_weight = mcl_enchanting.total_weight + enchantment_def.weight
end
for itemname, itemdef in pairs(minetest.registered_items) do
if itemdef.groups.enchanted then
break
end
local quick_test = false
for group, groupv in pairs(itemdef.groups) do
if groupv > 0 and mcl_enchanting.all_item_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 tooldef = minetest.registered_tools[itemname]
local new_name = itemname .. "_enchanted"
minetest.override_item(itemname, {_mcl_enchanting_enchanted_tool = new_name})
local new_def = table.copy(itemdef)
new_def.inventory_image = itemdef.inventory_image .. "^[colorize:purple:50"
new_def.groups.not_in_creative_inventory = 1
new_def.groups.enchanted = 1
new_def.texture = itemdef.texture or itemname:gsub("%:", "_")
new_def._mcl_enchanting_enchanted_tool = new_name
local register_list = item_list
if tooldef then
register_list = tool_list
end
register_list[":" .. new_name] = new_def
end
end
end
for new_name, new_def in pairs(item_list) do
minetest.register_craftitem(new_name, new_def)
end
for new_name, new_def in pairs(tool_list) do
minetest.register_tool(new_name, new_def)
end
end
--[[
minetest.register_on_mods_loaded(function()
for toolname, tooldef in pairs(minetest.registered_tools) do
for _, material in pairs(tooldef.materials) do
local full_name = toolname .. ((material == "") and "" or "_" .. material)
local old_def = minetest.registered_tools[full_name]
if not old_def then break end
mcl_enchanting.all_tools[full_name] = toolname
for _, enchantment in pairs(tooldef.enchantments) do
local enchantment_def = mcl_enchanting.enchantments[enchantment]
for lvl = 1, enchantment_def.max_level do
local new_def = table.copy(old_def)
new_def.description = minetest.colorize("#54FCFC", old_def.description) .. "\n" .. mcl_enchanting.get_enchantment_description(enchantment, lvl)
new_def.inventory_image = old_def.inventory_image .. "^[colorize:violet:50"
new_def.groups.not_in_creative_inventory = 1
new_def.texture = old_def.texture or full_name:gsub("%:", "_")
new_def._original_tool = full_name
enchantment_def.create_itemdef(new_def, lvl)
minetest.register_tool(":" .. full_name .. "_enchanted_" .. enchantment .. "_" .. lvl, new_def)
end
end
end
end
end)
--]]

View file

@ -0,0 +1,591 @@
-- Taken from https://minecraft.gamepedia.com/Enchanting
-- unimplemented
mcl_enchanting.enchantments.aqua_affinity = {
name = "Aqua Affinity",
max_level = 1,
primary = {armor_head = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 2,
description = "Increases underwater mining speed.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.bane_of_anthropods = {
name = "Bane of Anthropods",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {smite = true, shaprness = true},
weight = 5,
description = "Increases damage and applies Slowness IV to arthropod mobs (spiders, cave spiders, silverfish and endermites).",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.blast_protection = {
name = "Blast Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {fire_protection = true, protection = true, projectile_protection = true},
weight = 2,
description = "Reduces explosion damage and knockback.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.curse_of_binding = {
name = "Curse of Binding",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
disallow = {},
incompatible = {},
weight = 1,
description = "Except when in creative mode, items cannot be removed from armor slots except due to death or breaking.",
curse = true,
on_enchant = function() end,
requires_tool = false,
}
-- implemented in mcl_death_drop
mcl_enchanting.enchantments.curse_of_vanishing = {
name = "Curse of Vanishing",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {clock = true},
incompatible = {},
weight = 1,
description = "Except when in creative mode, items cannot be removed from armor slots except due to death or breaking.",
curse = true,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.depth_strider = {
name = "Depth Strider",
max_level = 3,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {frost_walker = true},
weight = 2,
description = "Increases underwater movement speed.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.efficiency = {
name = "Efficiency",
max_level = 5,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {shears = true},
disallow = {},
incompatible = {},
weight = 10,
description = "Increases mining speed.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.feather_falling = {
name = "Feather Falling",
max_level = 4,
primary = {armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 5,
description = "Reduces fall damage.",curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.fire_aspect = {
name = "Fire Aspect",
max_level = 2,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Sets target on fire.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.fire_protection = {
name = "Fire Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, protection = true, projectile_protection = true},
weight = 5,
description = "Reduces fire damage.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.flame = {
name = "Flame",
max_level = 1,
primary = {bow = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Arrows set target on fire.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.fortune = {
name = "Fortune",
max_level = 4,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {},
disallow = {},
incompatible = {silk_touch = true},
weight = 2,
description = "Increases certain block drops.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.frost_walker = {
name = "Frost Walker",
max_level = 2,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {depth_strider = true},
weight = 2,
description = "Turns water beneath the player into frosted ice and prevents the damage the player would take from standing on magma blocks.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- implemented in mcl_bows
mcl_enchanting.enchantments.infinity = {
name = "Infinity",
max_level = 1,
primary = {bow = true},
secondary = {},
disallow = {},
incompatible = {mending = true},
weight = 1,
description = "Shooting consumes no regular arrows.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.knockback = {
name = "Knockback",
max_level = 2,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 5,
description = "Increases knockback.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.looting = {
name = "Looting",
max_level = 3,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases mob loot.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.luck_of_the_sea = {
name = "Luck of the Sea",
max_level = 3,
primary = {fishing_rod = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases rate of good loot (enchanting books, etc.)",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.lure = {
name = "Lure",
max_level = 3,
primary = {fishing_rod = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Decreases wait time until fish/junk/loot \"bites\".",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.mending = {
name = "Mending",
max_level = 1,
primary = {},
secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, tool = true, weapon = true},
disallow = {non_combat_armor = true, compass = true, clock = true},
incompatible = {infinity = true},
weight = 2,
description = "Repair the item while gaining XP orbs.",
curse = false,
on_enchant = function() end,
requires_tool = true,
}
-- unimplemented
mcl_enchanting.enchantments.power = {
name = "Power",
max_level = 5,
primary = {},
secondary = {bow = true},
disallow = {},
incompatible = {},
weight = 10,
description = "Increases arrow damage.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.projectile_protection = {
name = "Projectile Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, protection = true},
weight = 5,
description = "Reduces projectile damage.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.protection = {
name = "Protection",
max_level = 4,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true},
weight = 10,
description = "Reduces most types of damage by 4% for each level.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.punch = {
name = "Punch",
max_level = 2,
primary = {},
secondary = {bow = true},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases arrow knockback.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.respiration = {
name = "Respiration",
max_level = 3,
primary = {armor_head = true},
secondary = {},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 2,
description = "Extends underwater breathing time.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.sharpness = {
name = "Sharpness",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {bane_of_anthropods = true, smite = true},
weight = 5,
description = "Increases damage and applies Slowness IV to arthropod mobs (spiders, cave spiders, silverfish and endermites).",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.silk_touch = {
name = "Silk Touch",
max_level = 1,
primary = {pickaxe = true, shovel = true, axe = true, hoe = true},
secondary = {shears = true},
disallow = {},
incompatible = {fortune = true},
weight = 1,
description = "Mined blocks drop themselves.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.smite = {
name = "Smite",
max_level = 5,
primary = {sword = true},
secondary = {axe = true},
disallow = {},
incompatible = {bane_of_anthropods = true, sharpness = true},
weight = 5,
description = "Increases damage to undead mobs.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.soul_speed = {
name = "Soul Speed",
max_level = 3,
primary = {},
secondary = {armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {frost_walker = true},
weight = 2,
description = "Incerases walking speed on soul sand.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.sweeping_edge = {
name = "Sweeping Edge",
max_level = 3,
primary = {sword = true},
secondary = {},
disallow = {},
incompatible = {},
weight = 2,
description = "Increases sweeping attack damage.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.thorns = {
name = "Thorns",
max_level = 3,
primary = {armor_head = true},
secondary = {armor_torso = true, armor_legs = true, armor_feet = true},
disallow = {non_combat_armor = true},
incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true},
weight = 1,
description = "Reflects some of the damage taken when hit, at the cost of reducing durability with each proc.",
curse = false,
on_enchant = function() end,
requires_tool = false,
}
-- unimplemented
mcl_enchanting.enchantments.unbreaking = {
name = "Unbreaking",
max_level = 3,
primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true, pickaxe = true, shovel = true, axe = true, hoe = true, sword = true, fishing_rod = true, bow = true},
secondary = {tool = true},
disallow = {non_combat_armor = true},
incompatible = {},
weight = 5,
description = "Increases item durability.",
curse = false,
on_enchant = function() end,
requires_tool = true,
}
--[[
local pickaxes = {"mcl_tools:pick_wood", "mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local pickaxes_better_than_iron = {"mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local pickaxes_better_than_stone = {"mcl_tools:pick_stone", "mcl_tools:pick_gold", "mcl_tools:pick_iron", "mcl_tools:pick_diamond"}
local shovels = {"mcl_tools:shovel_wood", "mcl_tools:shovel_stone", "mcl_tools:shovel_gold", "mcl_tools:shovel_iron", "mcl_tools:shovel_diamond"}
local silk_touch_tool_lists = {
["mcl_books:bookshelf"] = true,
["mcl_core:clay"] = true,
["mcl_core:stone_with_coal"] = pickaxes,
["group:coral_block"] = pickaxes,
["group:coral"] = true,
["group:coral_fan"] = true,
["mcl_core:stone_with_diamond"] = pickaxes_better_than_iron,
["mcl_core:stone_with_emerald"] = pickaxes_better_than_iron,
["mcl_chests:ender_chest"] = pickaxes,
["group:glass"] = true,
["mcl_nether:glowstone"] = true,
["mcl_core:dirt_with_grass"] = true,
["mcl_core:gravel"] = true,
["mcl_core:ice"] = true,
["mcl_core:stone_with_lapis"] = pickaxes_better_than_stone,
["group:leaves"] = true,
["mcl_farming:melon"] = true,
["group:huge_mushroom"] = true,
["mcl_core:mycelium"] = true,
["mcl_nether:quartz_ore"] = pickaxes,
["mcl_core:packed_ice"] = true,
["mcl_core:podzol"] = true,
["mcl_core:stone_with_redstone"] = pickaxes_better_than_iron,
["mcl_ocean:sea_lantern"] = true,
["group:top_snow"] = shovels,
["mcl_core:snowblock"] = shovels,
["mcl_core:stone"] = pickaxes,
}
minetest.register_on_mods_loaded(function()
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if digger and digger:is_player() then
local wielditem = digger:get_wielded_item()
local tooldef = wielditem:get_definition()
if tooldef._silk_touch then
local nodename = minetest.get_node(pos).name
local nodedef = minetest.registered_nodes[nodename]
local silk_touch_spec = silk_touch_tool_lists[nodename]
local suitable_tool = false
local tool_list
if silk_touch_spec == true then
suitable_tool = true
elseif silk_touch_spec then
tool_list = silk_touch_spec
else
for k, v in pairs(nodedef.groups) do
if v > 0 then
local group_spec = silk_touch_tool_lists["group:" .. k]
if group_spec == true then
suitable_tool = true
elseif group_spec then
toollist = group_spec
break
end
end
end
end
if tool_list and not suitable_tool then
suitable_tool = (table.indexof(tool_list, tooldef._original_tool) ~= -1)
end
if suitable_tool then
drops = {nodename}
end
end
end
old_handle_node_drops(pos, drops, digger)
end
end)
--]]
--[[
sharpness = {
name = "Sharpness",
max_level = 5,
create_itemdef = function(def, level)
def.tool_capabilities.damage_groups.fleshy = def.tool_capabilities.damage_groups.fleshy + (level + 1) / 2
end,
},
efficiency = {
name = "Efficiency",
max_level = 5,
create_itemdef = function(def, level)
local groupcaps = def.tool_capabilities.groupcaps
for _, groupcap in pairs(groupcaps) do
for i, t in pairs(groupcap.times) do
local m = 1 / t
m = m + math.pow(level, 2) + 1
groupcap.times[i] = 1 / m
end
end
end,
},
unbreaking = {
name = "Unbreaking",
max_level = 3,
create_itemdef = function(def, level)
local toolcaps = def.tool_capabilities
local armor_uses = def.groups.mcl_armor_uses
local factor = 0.5
if toolcaps then
local groupcaps = toolcaps.groupcaps
for _, groupcap in pairs(groupcaps) do
groupcap.uses = math.floor(groupcap.uses * (1 + level))
end
def.tool_capabilities.punch_attack_uses = math.floor(def.tool_capabilities.punch_attack_uses * (1 + level))
elseif armor_uses then
def.groups.mcl_armor_uses = math.floor(armor_uses / (0.6 + (0.4 / (level + 1))))
end
end
},
},--]]

View file

@ -4,14 +4,19 @@ mcl_enchanting = {
lapis_itemstring = "mcl_dye:blue",
book_offset = vector.new(0, 0.75, 0),
roman_numerals = dofile(modpath .. "/roman_numerals.lua"), -- https://exercism.io/tracks/lua/exercises/roman-numerals/solutions/73c2fb7521e347209312d115f872fa49
enchantments = {},
total_weight = 0,
all_item_groups = {},
debug = true,
}
dofile(modpath .. "/api.lua")
dofile(modpath .. "/enchantments.lua")
dofile(modpath .. "/features.lua")
dofile(modpath .. "/core.lua")
dofile(modpath .. "/command.lua")
dofile(modpath .. "/tt.lua")
-- dofile(modpath .. "/ui.lua")
-- dofile(modpath .. "/fx.lua")
-- dofile(modpath .. "/book.lua")
-- dofile(modpath .. "/table.lua")
minetest.register_on_mods_loaded(mcl_enchanting.initialize)

View file

Before

Width:  |  Height:  |  Size: 875 B

After

Width:  |  Height:  |  Size: 875 B

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

Before

Width:  |  Height:  |  Size: 875 B

After

Width:  |  Height:  |  Size: 875 B

View file

Before

Width:  |  Height:  |  Size: 876 B

After

Width:  |  Height:  |  Size: 876 B

View file

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 161 B

View file

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 157 B

View file

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

View file

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 156 B

View file

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View file

Before

Width:  |  Height:  |  Size: 106 B

After

Width:  |  Height:  |  Size: 106 B

View file

Before

Width:  |  Height:  |  Size: 160 B

After

Width:  |  Height:  |  Size: 160 B

View file

Before

Width:  |  Height:  |  Size: 166 B

After

Width:  |  Height:  |  Size: 166 B

View file

Before

Width:  |  Height:  |  Size: 145 B

After

Width:  |  Height:  |  Size: 145 B

View file

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 161 B

View file

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View file

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View file

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 105 B

View file

Before

Width:  |  Height:  |  Size: 161 B

After

Width:  |  Height:  |  Size: 161 B

View file

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View file

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 157 B

View file

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

View file

Before

Width:  |  Height:  |  Size: 102 B

After

Width:  |  Height:  |  Size: 102 B

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 298 B

After

Width:  |  Height:  |  Size: 298 B

View file

Before

Width:  |  Height:  |  Size: 315 B

After

Width:  |  Height:  |  Size: 315 B

View file

Before

Width:  |  Height:  |  Size: 340 B

After

Width:  |  Height:  |  Size: 340 B

View file

@ -5,7 +5,7 @@ function mcl_enchanting.enchantments_snippet(_, _, itemstack)
local enchantments = mcl_enchanting.get_enchantments(itemstack)
local text = ""
for enchantment, level in pairs(enchantments) do
text = text .. mcl_enchanting.get_enchantment_description(enchantment, level) .. "\n"
text = text .. mcl_enchanting.get_colorized_enchantment_description(enchantment, level) .. "\n"
end
if text ~= "" then
return text, false

View file

@ -60,8 +60,10 @@ minetest.register_on_mods_loaded(append_snippets)
tt.reload_itemstack_description = function(itemstack)
local itemstring = itemstack:get_name()
local def = itemstack:get_definition()
if should_change(itemstring, def) then
local meta = itemstack:get_meta()
local meta = itemstack:get_meta()
if def._mcl_generate_description then
def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) and meta:get_string("name") == "" then
local orig_desc = def._tt_original_description
local desc = apply_snippets(orig_desc, itemstring, itemstack:get_tool_capabilities(), itemstack)
if desc ~= orig_desc then

View file

@ -3,3 +3,4 @@ mcl_formspec
mcl_sounds
mcl_core?
screwdriver?
tt

View file

@ -170,23 +170,16 @@ local function update_anvil_slots(meta)
new_name = string.sub(new_name, 1, MAX_NAME_LENGTH)
-- Don't rename if names are identical
if new_name ~= old_name then
-- Save the raw name internally
meta:set_string("name", new_name)
-- Rename item
if new_name == "" then
-- Empty name
if name_item:get_definition()._mcl_generate_description then
-- _mcl_generate_description(itemstack): If defined, set custom item description of itemstack.
name_item:get_definition()._mcl_generate_description(name_item)
else
-- Otherwise, just clear description
meta:set_string("description", "")
end
tt.reload_itemstack_description(name_item)
else
-- Custom name set. Colorize it!
-- This makes the name visually different from unnamed items
meta:set_string("description", minetest.colorize(NAME_COLOR, new_name))
end
-- Save the raw name internally, too
meta:set_string("name", new_name)
new_output = name_item
elseif just_rename then
new_output = ""

View file

@ -76,7 +76,7 @@ end
local player_shoot_arrow = function(itemstack, player, power, damage, is_critical)
local arrow_stack, arrow_stack_id = get_arrow(player)
local arrow_itemstring
local has_infinity_enchantment = rawget(_G, "mcl_enchanting") and mcl_enchanting.get_enchantment(player:get_wielded_item(), "infinity") > 0
local has_infinity_enchantment = mcl_enchanting.has_enchantment(player:get_wielded_item(), "infinity")
if minetest.is_creative_enabled(player:get_player_name()) then
if arrow_stack then
@ -165,7 +165,7 @@ for level=0, 2 do
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1},
on_drop = function(itemstack, dropper, pos)
reset_bow_state(dropper)
if minetest.get_item_group(itemstack:get_name(), "enchanted") > 0 then
if mcl_enchanting.is_enchanted(itemstack) then
itemstack:set_name("mcl_bows:bow_enchanted")
else
itemstack:set_name("mcl_bows:bow")
@ -190,7 +190,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
local has_shot = false
local enchanted = minetest.get_item_group(wielditem:get_name(), "enchanted") > 0
local enchanted = mcl_enchanting.is_enchanted(wielditem)
local speed, damage
local p_load = bow_load[player:get_player_name()]
local charge
@ -253,7 +253,7 @@ controls.register_on_hold(function(player, key, time)
local inv = minetest.get_inventory({type="player", name=name})
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
local enchanted = (wielditem:get_name()=="mcl_bows:bow_enchanted")
local enchanted = mcl_enchanting.is_enchanted(wielditem)
if enchanted then
wielditem:set_name("mcl_bows:bow_0_enchanted")
else

View file

@ -8,3 +8,4 @@ doc?
doc_identifier?
mesecons_button?
mcl_particles
mcl_enchanting

View file

@ -1 +1,2 @@
mcl_armor
mcl_enchanting

View file

@ -23,7 +23,7 @@ minetest.register_on_dieplayer(function(player)
local z = math.random(0, 9)/3
pos.x = pos.x + x
pos.z = pos.z + z
if not void_deadly and drop then
if not void_deadly and drop and mcl_enchanting.get_enchantment(stack, "curse_of_vanishing") > 0 then
local def = minetest.registered_items[stack:get_name()]
if def and def.on_drop then
stack = def.on_drop(stack, player, pos)