2021-04-17 04:47:33 +02:00
|
|
|
|
local S = minetest.get_translator("mcl_crafting_table")
|
|
|
|
|
local formspec_escape = minetest.formspec_escape
|
|
|
|
|
local show_formspec = minetest.show_formspec
|
|
|
|
|
local C = minetest.colorize
|
2021-04-22 05:08:02 +02:00
|
|
|
|
local text_color = "#313131"
|
2021-05-03 10:51:26 +02:00
|
|
|
|
local itemslot_bg, size2r, xy2r = mcl_formspec.get_itemslot_bgv2, mcl_formspec.size2r, mcl_formspec.xy2r
|
2021-04-17 04:47:33 +02:00
|
|
|
|
|
2021-04-17 05:00:44 +02:00
|
|
|
|
mcl_crafting_table = {
|
|
|
|
|
last_table={}
|
|
|
|
|
}
|
|
|
|
|
function mcl_crafting_table.show_crafting_form(player, overlay)
|
2021-04-17 04:47:33 +02:00
|
|
|
|
player:get_inventory():set_width("craft", 3)
|
|
|
|
|
player:get_inventory():set_size("craft", 9)
|
|
|
|
|
|
2021-04-17 05:00:44 +02:00
|
|
|
|
show_formspec(player:get_player_name(), "mcl_crafting_table:main",
|
2021-05-03 10:51:26 +02:00
|
|
|
|
"formspec_version[3]"..
|
|
|
|
|
"size["..size2r(9,8.75).."]"..
|
|
|
|
|
"image["..xy2r(4.7,1.5)..";1.5,1;gui_crafting_arrow.png]"..
|
|
|
|
|
"label["..xy2r(0,4)..";"..formspec_escape(C(text_color, S("Inventory"))).."]".. --"#313131"
|
2021-04-17 04:47:33 +02:00
|
|
|
|
itemslot_bg(0,4.5,9,3)..
|
2021-05-03 10:51:26 +02:00
|
|
|
|
"list[current_player;main;"..xy2r(0,4.5)..";9,3;9]"..
|
2021-04-17 04:47:33 +02:00
|
|
|
|
itemslot_bg(0,7.74,9,1)..
|
2021-05-03 10:51:26 +02:00
|
|
|
|
"list[current_player;main;"..xy2r(0,7.74)..";9,1;]"..
|
|
|
|
|
"label["..xy2r(1.75,0)..";"..formspec_escape(C(text_color, S("Crafting"))).."]"..
|
2021-04-17 04:47:33 +02:00
|
|
|
|
itemslot_bg(1.75,0.5,3,3)..
|
2021-05-03 10:51:26 +02:00
|
|
|
|
"list[current_player;craft;"..xy2r(1.75,0.5)..";3,3;]"..
|
2021-04-17 04:47:33 +02:00
|
|
|
|
itemslot_bg(6.1,1.5,1,1)..
|
2021-05-03 10:51:26 +02:00
|
|
|
|
"list[current_player;craftpreview;"..xy2r(6.1,1.5)..";1,1;]"..
|
|
|
|
|
"image_button["..xy2r(0.75,1.5)..";1,1;craftguide_book.png;__mcl_craftguide;]"..
|
2021-04-17 04:47:33 +02:00
|
|
|
|
"tooltip[__mcl_craftguide;"..formspec_escape(S("Recipe book")).."]"..
|
|
|
|
|
"listring[current_player;main]"..
|
2021-04-17 05:00:44 +02:00
|
|
|
|
"listring[current_player;craft]"..
|
2021-05-03 10:51:26 +02:00
|
|
|
|
(overlay and "image["..xy2r(6.1,1.5)..";1,1;"..formspec_escape(overlay).."]" or "")
|
2021-04-17 04:47:33 +02:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-17 05:00:44 +02:00
|
|
|
|
if minetest.get_modpath("mcl_banners") then
|
|
|
|
|
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
|
|
|
|
|
if mcl_crafting_table.last_table[player:get_player_name()] then
|
|
|
|
|
local ovl=mcl_banners.get_overlay(itemstack)
|
|
|
|
|
mcl_crafting_table.show_crafting_form(player, ovl)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
|
if formname ~= "mcl_crafting_table:main" then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
if fields["quit"] then
|
|
|
|
|
mcl_crafting_table.last_table[player:get_player_name()]=nil
|
|
|
|
|
minetest.close_formspec(player:get_player_name(), formname)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-17 04:47:33 +02:00
|
|
|
|
local show_crafting_form = mcl_crafting_table.show_crafting_form --cache function for better performances
|
|
|
|
|
minetest.register_node("mcl_crafting_table:crafting_table", {
|
|
|
|
|
description = S("Crafting Table"),
|
|
|
|
|
_tt_help = S("3×3 crafting grid"),
|
|
|
|
|
_doc_items_longdesc = S("A crafting table is a block which grants you access to a 3×3 crafting grid which allows you to perform advanced crafts."),
|
|
|
|
|
_doc_items_usagehelp = S("Rightclick the crafting table to access the 3×3 crafting grid."),
|
|
|
|
|
_doc_items_hidden = false,
|
|
|
|
|
is_ground_content = false,
|
|
|
|
|
tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png",
|
|
|
|
|
"crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"},
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
|
groups = {handy=1,axey=1, deco_block=1, material_wood=1,flammable=-1},
|
|
|
|
|
on_rightclick = function(pos, node, player, itemstack)
|
2021-04-17 05:00:44 +02:00
|
|
|
|
mcl_crafting_table.last_table[player:get_player_name()]=node
|
2021-04-17 04:47:33 +02:00
|
|
|
|
show_crafting_form(player)
|
|
|
|
|
end,
|
|
|
|
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
|
|
|
|
_mcl_blast_resistance = 2.5,
|
|
|
|
|
_mcl_hardness = 2.5,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
output = "mcl_crafting_table:crafting_table",
|
|
|
|
|
recipe = {
|
|
|
|
|
{"group:wood", "group:wood"},
|
|
|
|
|
{"group:wood", "group:wood"}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
type = "fuel",
|
|
|
|
|
recipe = "mcl_crafting_table:crafting_table",
|
|
|
|
|
burntime = 15,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_alias("crafting:workbench", "mcl_crafting_table:crafting_table")
|
|
|
|
|
minetest.register_alias("mcl_inventory:workbench", "mcl_crafting_table:crafting_table")
|