mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-20 22:33:16 -04:00
Workbench. Built using 4 wood blocks, required for the 3 x 3 crafting grid in non-creative mode
This commit is contained in:
parent
4ea001fa37
commit
6bb6fc293f
9 changed files with 96 additions and 0 deletions
|
@ -72,6 +72,7 @@ trash:set_size("main", 1)
|
||||||
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
||||||
pagenum = math.floor(pagenum)
|
pagenum = math.floor(pagenum)
|
||||||
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
||||||
|
craft_resize(player, _)
|
||||||
player:set_inventory_formspec("size[13,7.5]"..
|
player:set_inventory_formspec("size[13,7.5]"..
|
||||||
--"image[6,0.6;1,2;player.png]"..
|
--"image[6,0.6;1,2;player.png]"..
|
||||||
"list[current_player;main;5,3.5;8,4;]"..
|
"list[current_player;main;5,3.5;8,4;]"..
|
||||||
|
|
|
@ -90,6 +90,10 @@ Calinou (CC BY-SA):
|
||||||
|
|
||||||
MirceaKitsune (WTFPL):
|
MirceaKitsune (WTFPL):
|
||||||
character.x
|
character.x
|
||||||
|
default_workbench_bottom.png
|
||||||
|
default_workbench_top.png
|
||||||
|
default_workbench_side.png
|
||||||
|
default_workbench_front.png
|
||||||
|
|
||||||
Jordach (CC BY-SA 3.0):
|
Jordach (CC BY-SA 3.0):
|
||||||
character.png
|
character.png
|
||||||
|
|
|
@ -298,6 +298,15 @@ minetest.register_craft({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = 'default:workbench',
|
||||||
|
recipe = {
|
||||||
|
{'group:wood', 'group:wood', ''},
|
||||||
|
{'group:wood', 'group:wood', ''},
|
||||||
|
{'', '', ''},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
output = "default:bronze_ingot",
|
output = "default:bronze_ingot",
|
||||||
|
|
|
@ -1,5 +1,51 @@
|
||||||
-- mods/default/functions.lua
|
-- mods/default/functions.lua
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Crafting
|
||||||
|
--
|
||||||
|
|
||||||
|
function move_items(s_inv, s_listname, d_inv, d_listname)
|
||||||
|
local s_size = s_inv:get_size(s_listname)
|
||||||
|
for i = 1, s_size do
|
||||||
|
local stack = s_inv:get_stack(s_listname, i)
|
||||||
|
if stack and not stack:is_empty() then
|
||||||
|
d_inv:add_item(d_listname, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
s_inv:set_list(s_listname, {})
|
||||||
|
end
|
||||||
|
|
||||||
|
function craft_resize(player, size)
|
||||||
|
-- if no size is given, set to default
|
||||||
|
if not size then
|
||||||
|
if minetest.setting_getbool("creative_mode") or
|
||||||
|
minetest.setting_getbool("inventory_crafting_full") then
|
||||||
|
size = 3
|
||||||
|
else
|
||||||
|
size = 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
if inv:get_width("craft") ~= size then
|
||||||
|
move_items(inv, "craft", inv, "main")
|
||||||
|
inv:set_width("craft", size)
|
||||||
|
inv:set_size("craft", size*size)
|
||||||
|
return size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- set non-creative inventory
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
local size = craft_resize(player, _)
|
||||||
|
if size and size < 3 then
|
||||||
|
player:set_inventory_formspec("size[8,7.5]"
|
||||||
|
.."list[current_player;main;0,3.5;8,4;]"
|
||||||
|
.."list[current_player;craft;3,0.5;2,2;]"
|
||||||
|
.."list[current_player;craftpreview;6,1;1,1;]")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Sounds
|
-- Sounds
|
||||||
--
|
--
|
||||||
|
|
|
@ -1061,6 +1061,42 @@ minetest.register_abm({
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname == "default:workbench" then
|
||||||
|
if fields.quit then
|
||||||
|
craft_resize(player, _)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function default.get_workbench_formspec(size)
|
||||||
|
size = math.min(6, math.max(1, size))
|
||||||
|
local formspec =
|
||||||
|
"size[8,"..(size+4.5).."]"
|
||||||
|
.."list[current_player;main;0,"..(size+0.5)..";8,4;]"
|
||||||
|
.."list[current_player;craft;0,0;"..size..","..size..";]"
|
||||||
|
.."list[current_player;craftpreview;6,"..(size/2-0.5)..";1,1;]"
|
||||||
|
return formspec
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node("default:workbench", {
|
||||||
|
description = "WorkBench",
|
||||||
|
tiles = {"default_workbench_top.png", "default_workbench_bottom.png", "default_workbench_side.png",
|
||||||
|
"default_workbench_side.png", "default_workbench_side.png", "default_workbench_front.png"},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||||
|
legacy_facedir_simple = true,
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("infotext", "Workbench")
|
||||||
|
end,
|
||||||
|
on_rightclick = function(pos, node, clicker)
|
||||||
|
craft_resize(clicker, 3)
|
||||||
|
minetest.show_formspec(clicker:get_player_name(), "default:workbench", default.get_workbench_formspec(3))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_node("default:cobble", {
|
minetest.register_node("default:cobble", {
|
||||||
description = "Cobblestone",
|
description = "Cobblestone",
|
||||||
tiles = {"default_cobble.png"},
|
tiles = {"default_cobble.png"},
|
||||||
|
|
BIN
mods/default/textures/default_workbench_bottom.png
Normal file
BIN
mods/default/textures/default_workbench_bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 469 B |
BIN
mods/default/textures/default_workbench_front.png
Normal file
BIN
mods/default/textures/default_workbench_front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/default/textures/default_workbench_side.png
Normal file
BIN
mods/default/textures/default_workbench_side.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/default/textures/default_workbench_top.png
Normal file
BIN
mods/default/textures/default_workbench_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
Loading…
Add table
Reference in a new issue