Display recipe and validate input
This commit is contained in:
parent
a776532a30
commit
3646ecaa4b
@ -1,3 +1,30 @@
|
||||
minetest.register_node(":streets:sign_blank",{
|
||||
description = "Emtpy sign",
|
||||
tiles = {"streets_sign_back.png"},
|
||||
inventory_image = "streets_sign_back.png",
|
||||
wield_image = "streets_sign_back.png",
|
||||
groups = {snappy = 1,attached_node = 1},
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "wallmounted",
|
||||
fixed = {
|
||||
{-0.4,-0.5,-0.4,0.4,-0.4,0.4}
|
||||
}
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
walkable = false,
|
||||
sunlight_propagates = true,
|
||||
selection_box = {
|
||||
type = "wallmounted"
|
||||
},
|
||||
streets = {
|
||||
signworkshop = {
|
||||
recipe = {"default:steel_ingot","","",""},
|
||||
time = 5
|
||||
}
|
||||
}
|
||||
})
|
||||
minetest.register_node(":streets:sign_lava",{
|
||||
description = "Warning sign (lava)",
|
||||
tiles = {"streets_sign_lava.png"},
|
||||
@ -17,7 +44,13 @@ minetest.register_node(":streets:sign_lava",{
|
||||
sunlight_propagates = true,
|
||||
selection_box = {
|
||||
type = "wallmounted"
|
||||
},
|
||||
streets = {
|
||||
signworkshop = {
|
||||
recipe = {"streets:sign_blank","bucket:bucket_lava","",""},
|
||||
time = 7
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node(":streets:sign_water",{
|
||||
|
@ -28,6 +28,11 @@ minetest.register_node(":streets:signworkshop",{
|
||||
inv:set_size("streets:signworkshop_input",4*1)
|
||||
inv:set_size("streets:signworkshop_select",1*1)
|
||||
inv:set_size("streets:signworkshop_output",1*1)
|
||||
-- Fill
|
||||
inv:add_item("streets:signworkshop_list","streets:sign_blank")
|
||||
inv:add_item("streets:signworkshop_list","streets:sign_lava")
|
||||
inv:add_item("streets:signworkshop_list","streets:sign_water")
|
||||
inv:add_item("streets:signworkshop_list","streets:sign_construction")
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if listname ~= "streets:signworkshop_input" then
|
||||
@ -37,8 +42,22 @@ minetest.register_node(":streets:signworkshop",{
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
-- Move items inside input slots
|
||||
if to_list == "streets:signworkshop_input" and from_list == "streets:signworkshop_input" then
|
||||
return 1
|
||||
-- List -> selection
|
||||
elseif from_list == "streets:signworkshop_list" and to_list == "streets:signworkshop_select" then
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local selected = inv:get_stack("streets:signworkshop_list",from_index):to_table()
|
||||
local need = minetest.registered_nodes[selected.name].streets.signworkshop.recipe
|
||||
inv:set_list("streets:signworkshop_recipe",{need[1],need[2],need[3],need[4]})
|
||||
return 1
|
||||
-- selection -> list
|
||||
elseif from_list == "streets:signworkshop_select" and to_list == "streets:signworkshop_list" then
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
inv:set_list("streets:signworkshop_recipe",{"","","",""})
|
||||
return 1
|
||||
-- Every other case
|
||||
else
|
||||
return 0
|
||||
end
|
||||
@ -53,8 +72,30 @@ minetest.register_node(":streets:signworkshop",{
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local inv = minetest.get_inventory({type = "node", pos = pos})
|
||||
--
|
||||
if inv:is_emtpy("streets:signworkshop_input") ~= true then
|
||||
|
||||
if inv:is_empty("streets:signworkshop_input") ~= true and inv:is_empty("streets:signworkshop_select") ~= true then
|
||||
local selection = inv:get_stack("streets:signworkshop_select",1):get_name()
|
||||
local def = minetest.registered_nodes[selection].streets.signworkshop
|
||||
local need = inv:get_list("streets:signworkshop_recipe")
|
||||
local has = inv:get_list("streets:signworkshop_input")
|
||||
need[1] = need[1]:to_table()
|
||||
need[2] = need[2]:to_table()
|
||||
need[3] = need[3]:to_table()
|
||||
need[4] = need[4]:to_table()
|
||||
has[1] = has[1]:to_table()
|
||||
has[2] = has[2]:to_table()
|
||||
has[3] = has[3]:to_table()
|
||||
has[4] = has[4]:to_table()
|
||||
if need[1] == nil then need[1] = { name = "" } end
|
||||
if need[2] == nil then need[2] = { name = "" } end
|
||||
if need[3] == nil then need[3] = { name = "" } end
|
||||
if need[4] == nil then need[4] = { name = "" } end
|
||||
if has[1] == nil then has[1] = { name = "" } end
|
||||
if has[2] == nil then has[2] = { name = "" } end
|
||||
if has[3] == nil then has[3] = { name = "" } end
|
||||
if has[4] == nil then has[4] = { name = "" } end
|
||||
if need[1].name == has[1].name and need[2].name == has[2].name and need[3].name == has[3].name and need[4].name == has[4].name then
|
||||
minetest.chat_send_all("yay")
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user