mirror of
https://github.com/minetest-mods/enchanting.git
synced 2024-11-24 07:43:44 +01:00
Backport changes from xdecor
NOTE: Minetest 0.4.14-dev or 0.4.15 required
This commit is contained in:
parent
cac16639a5
commit
5d4070e54a
68
init.lua
68
init.lua
@ -1,16 +1,49 @@
|
|||||||
local enchanting = {}
|
|
||||||
screwdriver = screwdriver or {}
|
screwdriver = screwdriver or {}
|
||||||
|
local ceil, abs, random = math.ceil, math.abs, math.random
|
||||||
|
|
||||||
-- Cost in Mese crystal(s) for enchanting.
|
-- Cost in Mese crystal(s) for enchanting.
|
||||||
local mese_cost = 1
|
local mese_cost = 1
|
||||||
|
|
||||||
-- Force of the enchantments.
|
-- Force of the enchantments.
|
||||||
enchanting.uses = 1.2 -- Durability
|
local enchanting = {
|
||||||
enchanting.times = 0.1 -- Efficiency
|
uses = 1.2, -- Durability
|
||||||
enchanting.damages = 1 -- Sharpness
|
times = 0.1, -- Efficiency
|
||||||
enchanting.strength = 1.2 -- Armor strength (3d_armor only)
|
damages = 1, -- Sharpness
|
||||||
enchanting.speed = 0.2 -- Player speed (3d_armor only)
|
strength = 1.2, -- Armor strength (3d_armor only)
|
||||||
enchanting.jump = 0.2 -- Player jumping (3d_armor only)
|
speed = 0.2, -- Player speed (3d_armor only)
|
||||||
|
jump = 0.2 -- Player jumping (3d_armor only)
|
||||||
|
}
|
||||||
|
|
||||||
|
local function cap(S) return S:gsub("^%l", string.upper) end
|
||||||
|
local function to_percent(orig_value, final_value)
|
||||||
|
return abs(ceil(((final_value - orig_value) / orig_value) * 100))
|
||||||
|
end
|
||||||
|
|
||||||
|
function enchanting:get_tooltip(enchant, orig_caps, fleshy)
|
||||||
|
local bonus = {durable=0, efficiency=0, damages=0}
|
||||||
|
if orig_caps then
|
||||||
|
bonus.durable = to_percent(orig_caps.uses, orig_caps.uses * enchanting.uses)
|
||||||
|
local sum_caps_times = 0
|
||||||
|
for i=1, #orig_caps.times do
|
||||||
|
sum_caps_times = sum_caps_times + orig_caps.times[i]
|
||||||
|
end
|
||||||
|
local average_caps_time = sum_caps_times / #orig_caps.times
|
||||||
|
bonus.efficiency = to_percent(average_caps_time, average_caps_time - enchanting.times)
|
||||||
|
end
|
||||||
|
if fleshy then
|
||||||
|
bonus.damages = to_percent(fleshy, fleshy + enchanting.damages)
|
||||||
|
end
|
||||||
|
|
||||||
|
local specs = { -- not finished, to complete
|
||||||
|
durable = {"#00baff", " (+"..bonus.durable.."%)"},
|
||||||
|
fast = {"#74ff49", " (+"..bonus.efficiency.."%)"},
|
||||||
|
sharp = {"#ffff00", " (+"..bonus.damages.."%)"},
|
||||||
|
strong = {"#ff3d3d", ""},
|
||||||
|
speed = {"#fd5eff", ""}
|
||||||
|
}
|
||||||
|
return minetest.colorize(specs[enchant][1], "\n"..cap(enchant)..specs[enchant][2])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function enchanting.formspec(pos, num)
|
function enchanting.formspec(pos, num)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -85,9 +118,7 @@ function enchanting.dig(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function allowed(tool)
|
local function allowed(tool)
|
||||||
if not tool then
|
if not tool then return false end
|
||||||
return false
|
|
||||||
end
|
|
||||||
for item in pairs(minetest.registered_tools) do
|
for item in pairs(minetest.registered_tools) do
|
||||||
if item:find("enchanted_"..tool) then return true end
|
if item:find("enchanted_"..tool) then return true end
|
||||||
end
|
end
|
||||||
@ -133,7 +164,6 @@ end
|
|||||||
|
|
||||||
function enchanting.timer(pos)
|
function enchanting.timer(pos)
|
||||||
local num = #minetest.get_objects_inside_radius(pos, 0.9)
|
local num = #minetest.get_objects_inside_radius(pos, 0.9)
|
||||||
|
|
||||||
if num == 0 then
|
if num == 0 then
|
||||||
minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open")
|
minetest.add_entity({x=pos.x, y=pos.y+0.85, z=pos.z}, "xdecor:book_open")
|
||||||
end
|
end
|
||||||
@ -143,7 +173,7 @@ function enchanting.timer(pos)
|
|||||||
local bookshelves = minetest.find_nodes_in_area(minp, maxp, "default:bookshelf")
|
local bookshelves = minetest.find_nodes_in_area(minp, maxp, "default:bookshelf")
|
||||||
if #bookshelves == 0 then return true end
|
if #bookshelves == 0 then return true end
|
||||||
|
|
||||||
local bookshelf_pos = bookshelves[math.random(1, #bookshelves)]
|
local bookshelf_pos = bookshelves[random(1, #bookshelves)]
|
||||||
local x = pos.x - bookshelf_pos.x
|
local x = pos.x - bookshelf_pos.x
|
||||||
local y = bookshelf_pos.y - pos.y
|
local y = bookshelf_pos.y - pos.y
|
||||||
local z = pos.z - bookshelf_pos.z
|
local z = pos.z - bookshelf_pos.z
|
||||||
@ -155,7 +185,7 @@ function enchanting.timer(pos)
|
|||||||
acceleration = {x=0, y=-2.2, z=0},
|
acceleration = {x=0, y=-2.2, z=0},
|
||||||
expirationtime = 1,
|
expirationtime = 1,
|
||||||
size = 2,
|
size = 2,
|
||||||
texture = "xdecor_glyph"..math.random(1,18)..".png"
|
texture = "xdecor_glyph"..random(1,18)..".png"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -207,8 +237,6 @@ minetest.register_craft({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
local function cap(S) return S:gsub("^%l", string.upper) end
|
|
||||||
|
|
||||||
function enchanting:register_tools(mod, def)
|
function enchanting:register_tools(mod, def)
|
||||||
for tool in pairs(def.tools) do
|
for tool in pairs(def.tools) do
|
||||||
for material in def.materials:gmatch("[%w_]+") do
|
for material in def.materials:gmatch("[%w_]+") do
|
||||||
@ -226,7 +254,7 @@ function enchanting:register_tools(mod, def)
|
|||||||
local group = next(original_groupcaps)
|
local group = next(original_groupcaps)
|
||||||
|
|
||||||
if enchant == "durable" then
|
if enchant == "durable" then
|
||||||
groupcaps[group].uses = math.ceil(original_groupcaps[group].uses * enchanting.uses)
|
groupcaps[group].uses = ceil(original_groupcaps[group].uses * enchanting.uses)
|
||||||
elseif enchant == "fast" then
|
elseif enchant == "fast" then
|
||||||
for i, time in pairs(original_groupcaps[group].times) do
|
for i, time in pairs(original_groupcaps[group].times) do
|
||||||
groupcaps[group].times[i] = time - enchanting.times
|
groupcaps[group].times[i] = time - enchanting.times
|
||||||
@ -236,7 +264,8 @@ function enchanting:register_tools(mod, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
|
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
|
||||||
description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
|
description = "Enchanted "..cap(material).." "..cap(tool)..
|
||||||
|
self:get_tooltip(enchant, original_groupcaps[group], fleshy),
|
||||||
inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
|
inventory_image = original_tool.inventory_image.."^[colorize:violet:50",
|
||||||
wield_image = original_tool.wield_image,
|
wield_image = original_tool.wield_image,
|
||||||
groups = {not_in_creative_inventory=1},
|
groups = {not_in_creative_inventory=1},
|
||||||
@ -254,7 +283,7 @@ function enchanting:register_tools(mod, def)
|
|||||||
|
|
||||||
for armor_group, value in pairs(original_armor_groups) do
|
for armor_group, value in pairs(original_armor_groups) do
|
||||||
if enchant == "strong" then
|
if enchant == "strong" then
|
||||||
armorcaps[armor_group] = math.ceil(value * enchanting.strength)
|
armorcaps[armor_group] = ceil(value * enchanting.strength)
|
||||||
elseif enchant == "speed" then
|
elseif enchant == "speed" then
|
||||||
armorcaps[armor_group] = value
|
armorcaps[armor_group] = value
|
||||||
armorcaps.physics_speed = enchanting.speed
|
armorcaps.physics_speed = enchanting.speed
|
||||||
@ -263,7 +292,8 @@ function enchanting:register_tools(mod, def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
|
minetest.register_tool(":"..mod..":enchanted_"..tool.."_"..material.."_"..enchant, {
|
||||||
description = "Enchanted "..cap(material).." "..cap(tool).." ("..cap(enchant)..")",
|
description = "Enchanted "..cap(material).." "..cap(tool)..
|
||||||
|
self:get_tooltip(enchant),
|
||||||
inventory_image = original_tool.inventory_image,
|
inventory_image = original_tool.inventory_image,
|
||||||
texture = "3d_armor_"..tool.."_"..material,
|
texture = "3d_armor_"..tool.."_"..material,
|
||||||
wield_image = original_tool.wield_image,
|
wield_image = original_tool.wield_image,
|
||||||
|
Loading…
Reference in New Issue
Block a user