2022-10-18 15:49:21 +03:00
|
|
|
-- By EliasFleckenstein03 and Code-Sploit
|
2021-04-16 17:00:14 +03:00
|
|
|
|
|
|
|
local S = minetest.get_translator("mcl_smithing_table")
|
2022-10-18 15:49:21 +03:00
|
|
|
local F = minetest.formspec_escape
|
|
|
|
local C = minetest.colorize
|
|
|
|
|
2021-04-16 17:00:14 +03:00
|
|
|
mcl_smithing_table = {}
|
|
|
|
|
|
|
|
-- Function to upgrade diamond tool/armor to netherite tool/armor
|
2022-10-18 15:49:21 +03:00
|
|
|
---@param itemstack ItemStack
|
2023-06-08 11:02:00 +03:00
|
|
|
function mcl_smithing_table.upgrade_item_netherite(itemstack)
|
2021-04-16 17:00:14 +03:00
|
|
|
local def = itemstack:get_definition()
|
|
|
|
|
2021-04-22 15:07:30 +03:00
|
|
|
if not def or not def._mcl_upgradable then
|
2021-04-16 17:00:14 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local itemname = itemstack:get_name()
|
2022-08-24 03:19:57 +03:00
|
|
|
local upgrade_item = itemname:gsub("diamond", "netherite")
|
2021-04-16 17:00:14 +03:00
|
|
|
|
2022-08-24 03:19:57 +03:00
|
|
|
if def._mcl_upgrade_item and upgrade_item == itemname then
|
2021-04-16 17:00:14 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
itemstack:set_name(upgrade_item)
|
2023-08-28 16:09:48 +03:00
|
|
|
mcl_armor.reload_trim_inv_image(itemstack)
|
2021-04-16 17:00:14 +03:00
|
|
|
|
|
|
|
-- Reload the ToolTips of the tool
|
|
|
|
|
|
|
|
tt.reload_itemstack_description(itemstack)
|
|
|
|
|
|
|
|
-- Only return itemstack if upgrade was successfull
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2022-10-18 15:49:21 +03:00
|
|
|
local formspec = table.concat({
|
|
|
|
"formspec_version[4]",
|
|
|
|
"size[11.75,10.425]",
|
|
|
|
|
|
|
|
"label[4.125,0.375;" .. F(C(mcl_formspec.label_color, S("Upgrade Gear"))) .. "]",
|
|
|
|
|
|
|
|
"image[0.875,0.375;1.75,1.75;mcl_smithing_table_inventory_hammer.png]",
|
|
|
|
|
|
|
|
mcl_formspec.get_itemslot_bg_v4(1.625, 2.6, 1, 1),
|
2023-08-28 17:47:31 +03:00
|
|
|
"list[context;upgrade_item;1.625,2.6;1,1;]",
|
|
|
|
|
|
|
|
"image[3.125,2.6;1,1;mcl_anvils_inventory_cross.png]",
|
2022-10-18 15:49:21 +03:00
|
|
|
|
2023-08-28 17:47:31 +03:00
|
|
|
mcl_formspec.get_itemslot_bg_v4(4.75, 2.6, 1, 1),
|
|
|
|
"list[context;mineral;4.75,2.6;1,1;]",
|
2022-10-18 15:49:21 +03:00
|
|
|
|
2023-09-29 17:59:45 +03:00
|
|
|
mcl_formspec.get_itemslot_bg_v4(6, 2.6, 1, 1),
|
|
|
|
mcl_formspec.get_itemslot_bg_v4(6, 2.6, 1, 1, 0, "mcl_smithing_table_inventory_trim_bg.png"),
|
2023-08-28 17:47:31 +03:00
|
|
|
"list[context;template;6,2.6;1,1;]",
|
2022-10-18 15:49:21 +03:00
|
|
|
|
2023-08-28 17:47:31 +03:00
|
|
|
"image[7,2.6;2,1;mcl_anvils_inventory_arrow.png]",
|
2022-10-18 15:49:21 +03:00
|
|
|
|
|
|
|
mcl_formspec.get_itemslot_bg_v4(9.125, 2.6, 1, 1),
|
|
|
|
"list[context;upgraded_item;9.125,2.6;1,1;]",
|
2021-04-16 14:47:21 +03:00
|
|
|
|
2022-10-18 15:49:21 +03:00
|
|
|
-- Player Inventory
|
|
|
|
|
|
|
|
mcl_formspec.get_itemslot_bg_v4(0.375, 5.1, 9, 3),
|
|
|
|
"list[current_player;main;0.375,5.1;9,3;9]",
|
|
|
|
|
|
|
|
mcl_formspec.get_itemslot_bg_v4(0.375, 9.05, 9, 1),
|
|
|
|
"list[current_player;main;0.375,9.05;9,1;]",
|
|
|
|
|
|
|
|
-- Listrings
|
|
|
|
|
2023-08-28 17:47:31 +03:00
|
|
|
"listring[context;upgrade_item]",
|
2022-10-18 15:49:21 +03:00
|
|
|
"listring[current_player;main]",
|
2023-08-28 17:47:31 +03:00
|
|
|
"listring[context;mineral]",
|
2022-10-18 15:49:21 +03:00
|
|
|
"listring[current_player;main]",
|
|
|
|
"listring[context;upgraded_item]",
|
|
|
|
"listring[current_player;main]",
|
|
|
|
"listring[current_player;main]",
|
2023-08-28 17:47:31 +03:00
|
|
|
"listring[context;upgrade_item]",
|
2022-10-18 15:49:21 +03:00
|
|
|
})
|
2021-04-16 14:47:21 +03:00
|
|
|
|
2023-06-21 12:21:39 +03:00
|
|
|
local smithing_materials = {
|
|
|
|
["mcl_nether:netherite_ingot"] = "netherite",
|
|
|
|
["mcl_core:diamond"] = "diamond",
|
|
|
|
["mcl_core:lapis"] = "lapis",
|
|
|
|
["mcl_amethyst:amethyst_shard"] = "amethyst",
|
|
|
|
["mesecons:wire_00000000_off"] = "redstone",
|
|
|
|
["mcl_core:iron_ingot"] = "iron",
|
|
|
|
["mcl_core:gold_ingot"] = "gold",
|
|
|
|
["mcl_copper:copper_ingot"] = "copper",
|
|
|
|
["mcl_core:emerald"] = "emerald",
|
|
|
|
["mcl_nether:quartz"] = "quartz"
|
2023-10-21 23:25:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
local achievement_trims = {
|
|
|
|
["mcl_armor:spire"] = true,
|
|
|
|
["mcl_armor:snout"] = true,
|
|
|
|
["mcl_armor:rib"] = true,
|
|
|
|
["mcl_armor:ward"] = true,
|
|
|
|
["mcl_armor:silence"] = true,
|
|
|
|
["mcl_armor:vex"] = true,
|
|
|
|
["mcl_armor:tide"] = true,
|
|
|
|
["mcl_armor:wayfinder"] = true
|
|
|
|
}
|
2023-06-21 12:21:39 +03:00
|
|
|
|
2023-06-21 12:48:21 +03:00
|
|
|
function mcl_smithing_table.upgrade_trimmed(itemstack, color_mineral, template)
|
2023-06-08 11:02:00 +03:00
|
|
|
--get information required
|
|
|
|
local material_name = color_mineral:get_name()
|
2023-06-21 12:21:39 +03:00
|
|
|
material_name = smithing_materials[material_name]
|
|
|
|
|
2023-08-28 16:09:48 +03:00
|
|
|
local overlay = template:get_name():gsub("mcl_armor:","")
|
2023-06-08 11:02:00 +03:00
|
|
|
|
|
|
|
--trimming process
|
2023-08-28 16:09:48 +03:00
|
|
|
mcl_armor.trim(itemstack, overlay, material_name)
|
2023-06-08 11:02:00 +03:00
|
|
|
tt.reload_itemstack_description(itemstack)
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2023-06-21 12:21:39 +03:00
|
|
|
function mcl_smithing_table.is_smithing_mineral(itemname)
|
|
|
|
return smithing_materials[itemname] ~= nil
|
2023-06-08 11:02:00 +03:00
|
|
|
end
|
|
|
|
|
2022-10-18 15:49:21 +03:00
|
|
|
---@param pos Vector
|
2021-04-16 17:00:14 +03:00
|
|
|
local function reset_upgraded_item(pos)
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
local upgraded_item
|
2023-06-08 11:06:26 +03:00
|
|
|
local original_itemname = inv:get_stack("upgrade_item", 1):get_name()
|
2023-06-08 11:02:00 +03:00
|
|
|
local template_present = inv:get_stack("template",1):get_name() ~= ""
|
|
|
|
local is_armor = original_itemname:find("mcl_armor:") ~= nil
|
|
|
|
local is_trimmed = original_itemname:find("_trimmed") ~= nil
|
|
|
|
|
2023-06-08 11:06:26 +03:00
|
|
|
if inv:get_stack("mineral", 1):get_name() == "mcl_nether:netherite_ingot" and not template_present then
|
|
|
|
upgraded_item = mcl_smithing_table.upgrade_item_netherite(inv:get_stack("upgrade_item", 1))
|
2023-06-21 12:21:39 +03:00
|
|
|
elseif template_present and is_armor and not is_trimmed and mcl_smithing_table.is_smithing_mineral(inv:get_stack("mineral", 1):get_name()) then
|
2023-06-21 12:48:21 +03:00
|
|
|
upgraded_item = mcl_smithing_table.upgrade_trimmed(inv:get_stack("upgrade_item", 1),inv:get_stack("mineral", 1),inv:get_stack("template", 1))
|
2021-04-16 17:00:14 +03:00
|
|
|
end
|
2021-04-16 14:47:21 +03:00
|
|
|
|
2021-04-16 17:00:14 +03:00
|
|
|
inv:set_stack("upgraded_item", 1, upgraded_item)
|
2021-04-16 14:47:21 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("mcl_smithing_table:table", {
|
2021-04-16 17:00:14 +03:00
|
|
|
description = S("Smithing table"),
|
|
|
|
-- ToDo: Add _doc_items_longdesc and _doc_items_usagehelp
|
2021-04-16 14:47:21 +03:00
|
|
|
|
2022-10-18 15:49:21 +03:00
|
|
|
groups = { pickaxey = 2, deco_block = 1 },
|
2021-04-16 14:47:21 +03:00
|
|
|
|
|
|
|
tiles = {
|
2022-06-29 21:18:59 +03:00
|
|
|
"mcl_smithing_table_top.png",
|
|
|
|
"mcl_smithing_table_bottom.png",
|
|
|
|
"mcl_smithing_table_side.png",
|
|
|
|
"mcl_smithing_table_side.png",
|
|
|
|
"mcl_smithing_table_side.png",
|
|
|
|
"mcl_smithing_table_front.png",
|
2021-04-16 14:47:21 +03:00
|
|
|
},
|
|
|
|
|
2021-04-16 17:00:14 +03:00
|
|
|
sounds = mcl_sounds.node_sound_metal_defaults(),
|
|
|
|
|
2021-04-16 14:47:21 +03:00
|
|
|
on_construct = function(pos)
|
2022-06-29 18:12:14 +03:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", formspec)
|
2021-04-16 17:00:14 +03:00
|
|
|
|
2022-06-29 18:12:14 +03:00
|
|
|
local inv = meta:get_inventory()
|
2021-04-16 17:00:14 +03:00
|
|
|
|
2023-06-08 11:06:26 +03:00
|
|
|
inv:set_size("upgrade_item", 1)
|
|
|
|
inv:set_size("mineral", 1)
|
2023-06-08 11:02:00 +03:00
|
|
|
inv:set_size("template",1)
|
2022-06-29 18:12:14 +03:00
|
|
|
inv:set_size("upgraded_item", 1)
|
|
|
|
end,
|
2021-04-16 17:00:14 +03:00
|
|
|
|
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
2023-10-25 18:20:50 +03:00
|
|
|
local stackname = stack:get_name()
|
|
|
|
local def = stack:get_definition()
|
2023-06-21 12:21:39 +03:00
|
|
|
if
|
|
|
|
listname == "upgrade_item"
|
2023-10-25 18:20:50 +03:00
|
|
|
and def._mcl_armor_element -- allow any armor piece to go in (in case the player wants to trim them)
|
|
|
|
and not mcl_armor.trims.blacklisted[stackname]
|
|
|
|
or def._mcl_upgradable -- for diamond tools
|
2023-06-21 12:21:39 +03:00
|
|
|
|
|
|
|
or listname == "mineral"
|
2023-10-25 18:20:50 +03:00
|
|
|
and mcl_smithing_table.is_smithing_mineral(stackname)
|
2023-06-21 12:21:39 +03:00
|
|
|
|
|
|
|
or listname == "template"
|
2023-10-25 18:20:50 +03:00
|
|
|
and string.find(stackname, "mcl_armor")
|
2023-06-21 12:21:39 +03:00
|
|
|
then
|
2021-04-16 17:00:14 +03:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
|
|
|
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_metadata_inventory_put = reset_upgraded_item,
|
|
|
|
|
|
|
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
2023-10-21 23:25:30 +03:00
|
|
|
|
2021-04-16 17:00:14 +03:00
|
|
|
local function take_item(listname)
|
|
|
|
local itemstack = inv:get_stack(listname, 1)
|
|
|
|
itemstack:take_item()
|
|
|
|
inv:set_stack(listname, 1, itemstack)
|
|
|
|
end
|
2023-10-21 23:25:30 +03:00
|
|
|
|
2021-04-16 17:00:14 +03:00
|
|
|
if listname == "upgraded_item" then
|
|
|
|
-- ToDo: make epic sound
|
2022-10-18 15:49:21 +03:00
|
|
|
minetest.sound_play("mcl_smithing_table_upgrade", { pos = pos, max_hear_distance = 16 })
|
2023-10-21 23:25:30 +03:00
|
|
|
|
2022-05-30 06:06:48 +03:00
|
|
|
if stack:get_name() == "mcl_farming:hoe_netherite" then
|
|
|
|
awards.unlock(player:get_player_name(), "mcl:seriousDedication")
|
2023-10-21 23:25:30 +03:00
|
|
|
elseif mcl_armor.is_trimmed(stack) then
|
|
|
|
local template_name = inv:get_stack("template", 1):get_name()
|
|
|
|
local playername = player:get_player_name()
|
|
|
|
awards.unlock(playername, "mcl:trim")
|
|
|
|
|
|
|
|
if not awards.players[playername].unlocked["mcl:lots_of_trimming"] and achievement_trims[template_name] then
|
|
|
|
local meta = player:get_meta()
|
|
|
|
local used_achievement_trims = minetest.deserialize(meta:get_string("mcl_smithing_table:achievement_trims")) or {}
|
|
|
|
if not used_achievement_trims[template_name] then
|
|
|
|
used_achievement_trims[template_name] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local used_all = true
|
|
|
|
for name, _ in pairs(achievement_trims) do
|
|
|
|
if not used_achievement_trims[name] then
|
|
|
|
used_all = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if used_all then
|
|
|
|
awards.unlock(playername, "mcl:lots_of_trimming")
|
|
|
|
else
|
|
|
|
meta:set_string("mcl_smithing_table:achievement_trims", minetest.serialize(used_achievement_trims))
|
|
|
|
end
|
|
|
|
end
|
2022-05-30 06:06:48 +03:00
|
|
|
end
|
2023-10-21 23:25:30 +03:00
|
|
|
|
|
|
|
take_item("upgrade_item")
|
|
|
|
take_item("mineral")
|
|
|
|
take_item("template")
|
2022-05-30 06:06:48 +03:00
|
|
|
end
|
2021-04-16 17:00:14 +03:00
|
|
|
reset_upgraded_item(pos)
|
|
|
|
end,
|
2021-04-16 14:47:21 +03:00
|
|
|
|
|
|
|
_mcl_blast_resistance = 2.5,
|
|
|
|
_mcl_hardness = 2.5
|
2021-04-16 17:00:14 +03:00
|
|
|
})
|
2021-04-22 15:11:47 +03:00
|
|
|
|
2022-05-30 06:06:48 +03:00
|
|
|
|
2021-04-22 15:11:47 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "mcl_smithing_table:table",
|
|
|
|
recipe = {
|
2022-10-18 15:49:21 +03:00
|
|
|
{ "mcl_core:iron_ingot", "mcl_core:iron_ingot", "" },
|
|
|
|
{ "group:wood", "group:wood", "" },
|
|
|
|
{ "group:wood", "group:wood", "" }
|
|
|
|
},
|
2021-04-22 15:11:47 +03:00
|
|
|
})
|
2023-06-21 11:57:50 +03:00
|
|
|
|
|
|
|
-- this is the exact same as mcl_smithing_table.upgrade_item_netherite , in case something relies on the old function
|
|
|
|
function mcl_smithing_table.upgrade_item(itemstack)
|
|
|
|
return mcl_smithing_table.upgrade_item_netherite(itemstack)
|
2023-08-28 17:47:31 +03:00
|
|
|
end
|