2017-05-16 19:47:12 +02:00
|
|
|
|
2015-09-02 04:11:29 +02:00
|
|
|
--
|
|
|
|
-- Jewels mod
|
|
|
|
-- By Kaadmy
|
|
|
|
--
|
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
local S = minetest.get_translator("jewels")
|
|
|
|
local F = minetest.formspec_escape
|
|
|
|
|
2015-09-02 04:11:29 +02:00
|
|
|
jewels = {}
|
2017-05-16 19:47:12 +02:00
|
|
|
|
|
|
|
-- Array of registered jeweled tools
|
|
|
|
|
2015-09-02 04:11:29 +02:00
|
|
|
jewels.registered_jewels = {}
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- Formspec
|
|
|
|
|
|
|
|
local form_bench = default.ui.get_page("default:2part")
|
|
|
|
|
|
|
|
form_bench = form_bench .. "list[current_name;main;2.25,1.75;1,1;]"
|
|
|
|
form_bench = form_bench .. "listring[current_name;main]"
|
|
|
|
form_bench = form_bench .. default.ui.get_itemslot_bg(2.25, 1.75, 1, 1)
|
|
|
|
|
2019-09-24 04:38:44 +02:00
|
|
|
form_bench = form_bench .. "label[3.25,1.75;"..F(S("1. Place tool here")).."]"
|
2019-08-28 17:31:41 +02:00
|
|
|
form_bench = form_bench .. "label[3.25,2.25;"..F(S("2. Hold a jewel and punch the bench")).."]"
|
2017-05-16 19:47:12 +02:00
|
|
|
|
|
|
|
form_bench = form_bench .. "list[current_player;main;0.25,4.75;8,4;]"
|
|
|
|
form_bench = form_bench .. "listring[current_player;main]"
|
|
|
|
form_bench = form_bench .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
|
|
|
form_bench = form_bench .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
|
|
|
|
|
|
|
default.ui.register_page("jewels_bench", form_bench)
|
|
|
|
|
|
|
|
local function plus_power(i)
|
|
|
|
if i >= 0 then
|
|
|
|
i = "+" .. i
|
|
|
|
end
|
|
|
|
|
2015-09-02 04:11:29 +02:00
|
|
|
return i
|
|
|
|
end
|
|
|
|
|
|
|
|
function jewels.register_jewel(toolname, new_toolname, def)
|
|
|
|
-- registers a new tool with different stats
|
|
|
|
|
|
|
|
local data = {
|
2015-09-02 19:44:07 +02:00
|
|
|
name = new_toolname, -- the new name of the tool
|
2015-09-02 04:11:29 +02:00
|
|
|
overlay = def.overlay or "jewels_jeweled_handle.png", -- overlay image
|
2015-10-19 20:46:45 +02:00
|
|
|
description = def.description or nil,
|
2015-09-02 04:11:29 +02:00
|
|
|
stats = {
|
|
|
|
digspeed = def.stats.digspeed, -- negative digs faster
|
|
|
|
maxlevel = def.stats.maxlevel, -- positive digs higher levels
|
2017-05-18 19:38:17 +02:00
|
|
|
maxdrop = def.stats.maxdrop, -- positive increases max drop level
|
2015-09-02 04:11:29 +02:00
|
|
|
uses = def.stats.uses, -- positive increases uses
|
|
|
|
fleshy = def.stats.fleshy, -- positive increases fleshy damage
|
|
|
|
range = def.stats.range, -- positive increases reach distance with tool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 19:44:07 +02:00
|
|
|
if not jewels.registered_jewels[toolname] then
|
|
|
|
jewels.registered_jewels[toolname] = {}
|
|
|
|
end
|
2017-05-16 19:47:12 +02:00
|
|
|
|
2015-09-02 19:44:07 +02:00
|
|
|
table.insert(jewels.registered_jewels[toolname], data)
|
2015-09-02 04:11:29 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
local tooldef = minetest.deserialize(
|
|
|
|
minetest.serialize(minetest.registered_tools[toolname]))
|
|
|
|
|
|
|
|
if not tooldef then
|
|
|
|
minetest.log("warning",
|
|
|
|
"Trying to register jewel " .. new_toolname
|
|
|
|
.. " that has an unknown output item " .. toolname)
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
2015-09-02 04:11:29 +02:00
|
|
|
|
|
|
|
local new_tool_invimage = ""
|
|
|
|
if tooldef.inventory_image then
|
|
|
|
new_tool_invimage = tooldef.inventory_image .. "^" .. data.overlay
|
|
|
|
end
|
|
|
|
|
|
|
|
local new_tool_wieldimage = ""
|
|
|
|
if tooldef.wield_image then
|
|
|
|
new_tool_wieldimage = tooldef.wield_image .. "^" .. data.overlay
|
|
|
|
end
|
|
|
|
|
2015-09-02 19:44:07 +02:00
|
|
|
local new_tooldef = tooldef
|
2015-09-02 04:11:29 +02:00
|
|
|
local desc = new_tooldef.description or ""
|
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
-- TODO: Add custom description for each tool for better translatability
|
|
|
|
desc = S("Jeweled @1", desc)
|
2015-09-02 04:11:29 +02:00
|
|
|
|
2015-10-19 20:46:45 +02:00
|
|
|
if data.description ~= nil then
|
|
|
|
desc = data.description
|
|
|
|
end
|
|
|
|
|
2015-09-02 04:11:29 +02:00
|
|
|
new_tooldef.inventory_image = new_tool_invimage
|
|
|
|
new_tooldef.wield_image = new_tool_wieldimage
|
|
|
|
|
2019-09-21 23:39:31 +02:00
|
|
|
if data.stats.range then
|
|
|
|
if not new_tooldef.range then
|
|
|
|
new_tooldef.range = 4
|
|
|
|
end
|
2015-09-02 04:11:29 +02:00
|
|
|
new_tooldef.range = new_tooldef.range + data.stats.range
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Range: @1", plus_power(data.stats.range))
|
2015-09-02 04:11:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if new_tooldef.tool_capabilities then
|
|
|
|
if data.stats.maxdrop and new_tooldef.tool_capabilities.max_drop_level then
|
2017-05-17 17:57:14 +02:00
|
|
|
new_tooldef.tool_capabilities.max_drop_level =
|
|
|
|
new_tooldef.tool_capabilities.max_drop_level + data.stats.maxdrop
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Drop level: @1", plus_power(data.stats.maxdrop))
|
2015-09-02 04:11:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if data.stats.digspeed then
|
|
|
|
for group, cap in pairs(new_tooldef.tool_capabilities.groupcaps) do
|
|
|
|
for i, _ in ipairs(cap.times) do
|
|
|
|
cap.times[i] = cap.times[i] + data.stats.digspeed
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.stats.maxlevel and cap.maxlevel then
|
|
|
|
cap.maxlevel = cap.maxlevel + data.stats.maxlevel
|
|
|
|
end
|
|
|
|
|
|
|
|
if data.stats.uses and cap.uses then
|
|
|
|
cap.uses = cap.uses + data.stats.uses
|
|
|
|
end
|
|
|
|
end
|
2015-09-02 17:53:42 +02:00
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Dig time: @1 s", plus_power(data.stats.digspeed))
|
2015-09-02 17:53:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if data.stats.uses then
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Uses: @1", plus_power(data.stats.uses))
|
2015-09-02 17:53:42 +02:00
|
|
|
end
|
|
|
|
if data.stats.maxlevel then
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Dig level: @1", plus_power(data.stats.maxlevel))
|
2015-09-02 04:11:29 +02:00
|
|
|
end
|
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
if data.stats.fleshy and new_tooldef.tool_capabilities.damage_groups
|
|
|
|
and new_tooldef.tool_capabilities.damage_groups.fleshy then
|
|
|
|
new_tooldef.tool_capabilities.damage_groups.fleshy =
|
|
|
|
new_tooldef.tool_capabilities.damage_groups.fleshy + data.stats.fleshy
|
2019-08-28 17:31:41 +02:00
|
|
|
desc = desc .. "\n"..S("Damage: @1", plus_power(data.stats.fleshy))
|
2015-09-02 04:11:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
new_tooldef.description = desc
|
2015-09-02 04:11:29 +02:00
|
|
|
|
2019-06-23 22:37:51 +02:00
|
|
|
if not new_tooldef.groups then
|
|
|
|
new_tooldef.groups = {}
|
|
|
|
end
|
|
|
|
new_tooldef.groups.not_in_creative_inventory = 1
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_tool(new_toolname, new_tooldef)
|
2015-09-02 04:11:29 +02:00
|
|
|
end
|
|
|
|
|
2017-05-18 19:38:17 +02:00
|
|
|
function jewels.can_jewel(toolname)
|
|
|
|
for name, _ in pairs(jewels.registered_jewels) do
|
|
|
|
if name == toolname then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2015-09-02 19:44:07 +02:00
|
|
|
function jewels.get_jeweled(toolname)
|
|
|
|
for name, jables in pairs(jewels.registered_jewels) do
|
|
|
|
if name == toolname then
|
|
|
|
return util.choice_element(jables)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
-- Items
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-02 04:11:29 +02:00
|
|
|
"jewels:jewel",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Jewel"),
|
2015-09-02 04:11:29 +02:00
|
|
|
inventory_image = "jewels_jewel.png",
|
|
|
|
stack_max = 10
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-02 04:11:29 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
-- Nodes
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-02 18:37:01 +02:00
|
|
|
"jewels:bench",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Jeweler's Workbench"),
|
2015-09-02 18:37:01 +02:00
|
|
|
tiles ={"jewels_bench_top.png", "jewels_bench_bottom.png", "jewels_bench_sides.png"},
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
|
|
|
legacy_facedir_simple = true,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2017-05-18 19:38:17 +02:00
|
|
|
|
2015-09-02 18:37:01 +02:00
|
|
|
on_construct = function(pos)
|
2017-05-16 19:47:12 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", default.ui.get_page("jewels_bench"))
|
2019-08-28 17:31:41 +02:00
|
|
|
meta:set_string("infotext", S("Jeweler's Workbench"))
|
2015-09-02 18:37:01 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 1)
|
|
|
|
end,
|
2015-09-02 18:37:01 +02:00
|
|
|
can_dig = function(pos, player)
|
2017-05-16 19:47:12 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
return inv:is_empty("main")
|
|
|
|
end,
|
2015-09-02 19:44:07 +02:00
|
|
|
on_punch = function(pos, node, player, pointed_thing)
|
2017-05-16 19:47:12 +02:00
|
|
|
local itemstack = player:get_wielded_item()
|
2017-05-13 20:50:15 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
if itemstack:get_name() == "jewels:jewel" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
local itemname = inv:get_stack("main", 1):get_name()
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
if jewels.can_jewel(itemname) then
|
|
|
|
inv:set_stack("main", 1, ItemStack(jewels.get_jeweled(itemname)))
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2019-09-21 20:57:09 +02:00
|
|
|
if not minetest.settings:get_bool("creative_mode") then
|
|
|
|
itemstack:take_item()
|
|
|
|
end
|
2015-10-25 22:18:54 +01:00
|
|
|
|
2019-09-21 21:12:33 +02:00
|
|
|
minetest.sound_play({name="jewels_jewelling_a_tool"}, {gain=0.8, pos=pos, max_hear_distance=8})
|
|
|
|
-- TODO: Graphical effect
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
achievements.trigger_achievement(player, "jeweler")
|
|
|
|
achievements.trigger_achievement(player, "master_jeweler")
|
|
|
|
end
|
|
|
|
end
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
player:set_wielded_item(itemstack)
|
|
|
|
end,
|
|
|
|
})
|
2015-09-02 19:44:07 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_node(
|
2015-09-24 02:15:02 +02:00
|
|
|
"jewels:jewel_ore",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Jewel Ore"),
|
2017-05-17 17:57:14 +02:00
|
|
|
tiles = {
|
|
|
|
"default_tree_birch_top.png",
|
|
|
|
"default_tree_birch_top.png",
|
|
|
|
"default_tree_birch.png^jewels_ore.png"
|
|
|
|
},
|
2015-09-24 02:15:02 +02:00
|
|
|
drop = "jewels:jewel",
|
|
|
|
groups = {snappy=1, choppy=1, tree=1},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-24 02:15:02 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
crafting.register_craft(
|
|
|
|
{
|
|
|
|
output = "jewels:bench",
|
|
|
|
items = {
|
|
|
|
"group:planks 5",
|
|
|
|
"default:ingot_carbon_steel 2",
|
|
|
|
"jewels:jewel",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-10-25 22:18:54 +01:00
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"jeweler",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
title = S("Jeweler"),
|
2019-09-02 14:54:29 +02:00
|
|
|
description = S("Jewel a tool."),
|
2015-10-25 22:18:54 +01:00
|
|
|
times = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-10-25 22:18:54 +01:00
|
|
|
|
2019-09-22 03:37:22 +02:00
|
|
|
achievements.register_achievement(
|
|
|
|
"secret_of_jewels",
|
|
|
|
{
|
2019-09-24 00:24:15 +02:00
|
|
|
title = S("Secret of Jewels"),
|
2019-09-22 03:37:22 +02:00
|
|
|
description = S("Discover the origin of jewels."),
|
|
|
|
times = 1,
|
|
|
|
dignode = "jewels:jewel_ore",
|
|
|
|
})
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- The tool jewel definitions
|
|
|
|
|
|
|
|
dofile(minetest.get_modpath("jewels").."/jewels.lua")
|
2019-09-12 15:29:57 +02:00
|
|
|
dofile(minetest.get_modpath("jewels").."/mapgen.lua")
|
2015-10-25 22:18:54 +01:00
|
|
|
|
2015-10-16 21:31:30 +02:00
|
|
|
default.log("mod:jewels", "loaded")
|