Merge changes from X-Decor

This commit is contained in:
Jean-Patrick Guerrero 2016-03-07 13:56:51 +01:00
parent ad7992bdf0
commit 7cd0291d8d

106
init.lua

@ -5,39 +5,15 @@ screwdriver = screwdriver or {}
local mese_cost = 1 local mese_cost = 1
-- Force of the enchantments. -- Force of the enchantments.
enchanting.uses = 1.2 enchanting.uses = 1.2 -- Durability
enchanting.times = 0.1 enchanting.times = 0.1 -- Efficiency
enchanting.damages = 1 enchanting.damages = 1 -- Sharpness
enchanting.strength = 1.2 enchanting.strength = 1.2 -- Armor strength (3d_armor only)
enchanting.speed = 0.2 enchanting.speed = 0.2 -- Player speed (3d_armor only)
enchanting.jump = 0.2 enchanting.jump = 0.2 -- Player jumping (3d_armor only)
-- Enchanted tools registration.
-- Available enchantments: durable, fast, sharp, strong, speed.
enchanting.tools = {
--[[ Registration format:
[Mod name] = {
materials,
{tool name, enchantments}
}
]]
["default"] = {
"steel, bronze, mese, diamond",
{"axe", "durable, fast"},
{"pick", "durable, fast"},
{"shovel", "durable, fast"},
{"sword", "sharp"}
},
["3d_armor"] = {
"steel, bronze, gold, diamond",
{"boots", "strong, speed"},
{"chestplate", "strong"},
{"helmet", "strong"},
{"leggings", "strong"}
}
}
function enchanting.formspec(pos, num) function enchanting.formspec(pos, num)
local meta = minetest.get_meta(pos)
local formspec = [[ size[9,9;] local formspec = [[ size[9,9;]
bgcolor[#080808BB;true] bgcolor[#080808BB;true]
background[0,0;9,9;ench_ui.png] background[0,0;9,9;ench_ui.png]
@ -45,32 +21,38 @@ function enchanting.formspec(pos, num)
list[context;mese;2,2.9;1,1;] list[context;mese;2,2.9;1,1;]
list[current_player;main;0.5,4.5;8,4;] list[current_player;main;0.5,4.5;8,4;]
image[2,2.9;1,1;mese_layout.png] image[2,2.9;1,1;mese_layout.png]
tooltip[sharp;Your sword inflicts more damage] tooltip[sharp;Your weapon inflicts more damages]
tooltip[durable;Your tool is more resistant] tooltip[durable;Your tool last longer]
tooltip[fast;Your tool is more powerful] tooltip[fast;Your tool digs faster]
tooltip[strong;Your armor is more resistant] tooltip[strong;Your armor is more resistant]
tooltip[speed;Your speed is increased] ]] tooltip[speed;Your speed is increased] ]]
..default.gui_slots..default.get_hotbar_bg(0.5,4.5) ..default.gui_slots..default.get_hotbar_bg(0.5,4.5)
local tool_enchs = { local enchant_buttons = {
[[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency] [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]], image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]],
"image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]", "image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]",
"image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]", "image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]",
[[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength] [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]] } image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
}
formspec = formspec..(tool_enchs[num] or "") formspec = formspec..(enchant_buttons[num] or "")
minetest.get_meta(pos):set_string("formspec", formspec) meta:set_string("formspec", formspec)
end end
function enchanting.on_put(pos, listname, _, stack) function enchanting.on_put(pos, listname, _, stack)
if listname == "tool" then if listname == "tool" then
for k, v in pairs({"axe, pick, shovel", local stackname = stack:get_name()
local tool_groups = {
"axe, pick, shovel",
"chestplate, leggings, helmet", "chestplate, leggings, helmet",
"sword", "boots"}) do "sword", "boots"
if v:find(stack:get_name():match(":(%w+)")) then }
enchanting.formspec(pos, k)
for idx, tools in pairs(tool_groups) do
if tools:find(stackname:match(":(%w+)")) then
enchanting.formspec(pos, idx)
end end
end end
end end
@ -137,7 +119,7 @@ minetest.register_node(":xdecor:enchantment_table", {
tiles = {"enchtable_top.png", "enchtable_bottom.png", tiles = {"enchtable_top.png", "enchtable_bottom.png",
"enchtable_side.png", "enchtable_side.png", "enchtable_side.png", "enchtable_side.png",
"enchtable_side.png", "enchtable_side.png"}, "enchtable_side.png", "enchtable_side.png"},
groups = {cracky=1, oddly_breakable_by_hand=1, level=1}, groups = {cracky=1, level=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_rotate = screwdriver.rotate_simple, on_rotate = screwdriver.rotate_simple,
can_dig = enchanting.dig, can_dig = enchanting.dig,
@ -160,14 +142,13 @@ minetest.register_craft({
local function cap(S) return S:gsub("^%l", string.upper) end local function cap(S) return S:gsub("^%l", string.upper) end
for mod, defs in pairs(enchanting.tools) do function enchanting:register_tools(mod, def)
for material in defs[1]:gmatch("[%w_]+") do for tool in pairs(def.tools) do
for _, tooldef in next, defs, 1 do for material in def.materials:gmatch("[%w_]+") do
for enchant in tooldef[2]:gmatch("[%w_]+") do for enchant in def.tools[tool].enchants:gmatch("[%w_]+") do
local tool, group = tooldef[1], ""
local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material] local original_tool = minetest.registered_tools[mod..":"..tool.."_"..material]
if not original_tool then return end
if original_tool then
if original_tool.tool_capabilities then if original_tool.tool_capabilities then
local original_damage_groups = original_tool.tool_capabilities.damage_groups local original_damage_groups = original_tool.tool_capabilities.damage_groups
local original_groupcaps = original_tool.tool_capabilities.groupcaps local original_groupcaps = original_tool.tool_capabilities.groupcaps
@ -175,13 +156,13 @@ for enchant in tooldef[2]:gmatch("[%w_]+") do
local fleshy = original_damage_groups.fleshy local fleshy = original_damage_groups.fleshy
local full_punch_interval = original_tool.tool_capabilities.full_punch_interval local full_punch_interval = original_tool.tool_capabilities.full_punch_interval
local max_drop_level = original_tool.tool_capabilities.max_drop_level local max_drop_level = original_tool.tool_capabilities.max_drop_level
group = tostring(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 = math.ceil(original_groupcaps[group].uses * enchanting.uses)
elseif enchant == "fast" then elseif enchant == "fast" then
for i = 1, 3 do for i, time in pairs(original_groupcaps[group].times) do
groupcaps[group].times[i] = original_groupcaps[group].times[i] - enchanting.times groupcaps[group].times[i] = time - enchanting.times
end end
elseif enchant == "sharp" then elseif enchant == "sharp" then
fleshy = fleshy + enchanting.damages fleshy = fleshy + enchanting.damages
@ -227,5 +208,24 @@ for enchant in tooldef[2]:gmatch("[%w_]+") do
end end
end end
end end
end
enchanting:register_tools("default", {
materials = "steel, bronze, mese, diamond",
tools = {
axe = {enchants = "durable, fast"},
pick = {enchants = "durable, fast"},
shovel = {enchants = "durable, fast"},
sword = {enchants = "sharp"}
}
})
enchanting:register_tools("3d_armor", {
materials = "steel, bronze, gold, diamond",
tools = {
boots = {enchants = "strong, speed"},
chestplate = {enchants = "strong"},
helmet = {enchants = "strong"},
leggings = {enchants = "strong"}
}
})