mymillwork/machines.lua

305 lines
7.8 KiB
Lua
Raw Normal View History

2015-03-14 21:39:43 -07:00
local material = {}
local shape = {}
local make_ok = {}
local anzahl = {}
minetest.register_node("mymillwork:machine", {
description = "Millwork Machine",
2015-03-15 06:28:26 -07:00
tiles = {
2015-03-14 21:39:43 -07:00
"mymillwork_machine_top.png",
2015-03-15 06:28:26 -07:00
"mymillwork_machine_bottom.png",
"mymillwork_machine_side2.png",
"mymillwork_machine_side1.png",
2015-03-14 21:39:43 -07:00
"mymillwork_machine_back.png",
2015-03-15 06:28:26 -07:00
"mymillwork_machine_front.png"
2015-03-14 21:39:43 -07:00
},
2015-03-15 06:28:26 -07:00
drawtype = "nodebox",
2015-03-14 21:39:43 -07:00
paramtype = "light",
paramtype2 = "facedir",
groups = {oddly_breakable_by_hand=2, cracky=3, dig_immediate=1},
2015-03-15 06:28:26 -07:00
node_box = {
type = "fixed",
fixed = {
2016-04-13 08:22:52 -07:00
{-0.5, -0.1875, -0.5, 0.5, -0.0625, 0.5},
{-0.5, -0.5, -0.5, -0.3125, -0.1875, -0.3125},
{-0.5, -0.5, 0.3125, -0.3125, -0.1875, 0.5},
{0.3125, -0.5, 0.3125, 0.5, -0.1875, 0.5},
{0.3125, -0.5, -0.5, 0.5, -0.1875, -0.3125},
{0, -0.0625, 0.25, 0.0625, 0.375, 0.5},
{-0.125, -0.0625, 0.25, -0.0625, 0.375, 0.5},
{-0.1875, 0.125, -0.3125, 0.125, 0.5, 0.0625},
{-0.125, 0.375, 0.0625, 0.0625, 0.5, 0.5},
{-0.0625, 0.0625, -0.3125, 0, 0.125, 0.0625},
{-0.0625, 0, -0.25, 0, 0.125, 0},
2015-03-15 06:28:26 -07:00
}
},
2015-03-14 21:39:43 -07:00
after_place_node = function(pos, placer)
2015-11-15 05:12:26 -08:00
local meta = minetest.get_meta(pos);
2015-03-14 21:39:43 -07:00
meta:set_string("owner", (placer:get_player_name() or ""));
2015-11-15 05:12:26 -08:00
meta:set_string("infotext", "Millwork Machine (owned by " .. (placer:get_player_name() or "") .. ")");
2015-03-14 21:39:43 -07:00
end,
can_dig = function(pos,player)
2015-11-15 05:12:26 -08:00
local meta = minetest.get_meta(pos);
2015-03-14 21:39:43 -07:00
local inv = meta:get_inventory()
2016-04-13 08:22:52 -07:00
if not inv:is_empty("ingot") or
not inv:is_empty("res") then
2015-03-14 21:39:43 -07:00
return false
end
return true
end,
on_construct = function(pos)
2015-11-15 05:12:26 -08:00
local meta = minetest.get_meta(pos)
2015-03-14 21:39:43 -07:00
meta:set_string("formspec", "invsize[10,11;]"..
"background[-0.15,-0.25;10.40,11.75;mymillwork_background.png]"..
2015-03-15 06:28:26 -07:00
"list[current_name;ingot;7,5.5.5;1,1;]"..
"list[current_name;res;8.5,5.5;1,1;]"..
"label[7,5;Input:]"..
"label[8.5,5;Output:]"..
2015-03-14 21:39:43 -07:00
"label[0,0;Choose Millwork:]"..
"label[0.5,0.5;Crown Mould]"..
2015-03-15 06:28:26 -07:00
"image_button[0.5,1;1,1;mymillwork_mach1.png;crownmould; ]"..
"image_button[1.5,1;1,1;mymillwork_mach2.png;crownmould_ic; ]"..
"image_button[2.5,1;1,1;mymillwork_mach3.png;crownmould_oc; ]"..
"image_button[3.5,1;1,1;mymillwork_mach4.png;crownmould_beam; ]"..
2015-03-14 21:39:43 -07:00
"label[0.5,2;Columns]"..
2015-03-15 06:28:26 -07:00
"image_button[0.5,2.5;1,1;mymillwork_mach5.png;column; ]"..
"image_button[1.5,2.5;1,1;mymillwork_mach6.png;column_base; ]"..
"image_button[2.5,2.5;1,1;mymillwork_mach7.png;column_half; ]"..
"image_button[3.5,2.5;1,1;mymillwork_mach8.png;column_half_base; ]"..
"image_button[4.5,2.5;1,1;mymillwork_mach9.png;column_half_wbeam; ]"..
"image_button[5.5,2.5;1,1;mymillwork_mach10.png;column_quarter; ]"..
"image_button[6.5,2.5;1,1;mymillwork_mach11.png;column_quarter_base; ]"..
"image_button[7.5,2.5;1,1;mymillwork_mach12.png;column_quarter_wbase; ]"..
"image_button[8.5,2.5;1,1;mymillwork_mach13.png;column_quarter_fancybase; ]"..
2015-03-14 21:39:43 -07:00
"label[0.5,3.5;Ceiling and Beams]"..
2015-03-15 06:28:26 -07:00
"image_button[0.5,4;1,1;mymillwork_mach14.png;ceiling; ]"..
"image_button[1.5,4;1,1;mymillwork_mach15.png;ceiling_post; ]"..
"image_button[2.5,4;1,1;mymillwork_mach16.png;beam; ]"..
"image_button[3.5,4;1,1;mymillwork_mach17.png;beam_t; ]"..
"image_button[4.5,4;1,1;mymillwork_mach18.png;beam_ceiling_t; ]"..
2015-03-14 21:39:43 -07:00
"label[0.5,5;Base]"..
2015-03-15 06:28:26 -07:00
"image_button[0.5,5.5;1,1;mymillwork_mach19.png;base; ]"..
"image_button[1.5,5.5;1,1;mymillwork_mach20.png;base_ic; ]"..
"image_button[2.5,5.5;1,1;mymillwork_mach21.png;base_oc; ]"..
"image_button[3.5,5.5;1,1;mymillwork_mach22.png;base_fancy; ]"..
"image_button[4.5,5.5;1,1;mymillwork_mach23.png;base_fancy_ic; ]"..
"image_button[5.5,5.5;1,1;mymillwork_mach24.png;base_fancy_oc; ]"..
"list[current_player;main;1,7;8,4;]")
2015-03-14 21:39:43 -07:00
meta:set_string("infotext", "Millwork Machine")
local inv = meta:get_inventory()
inv:set_size("ingot", 1)
inv:set_size("res", 1)
end,
on_receive_fields = function(pos, formname, fields, sender)
2015-11-15 05:12:26 -08:00
local meta = minetest.get_meta(pos)
2015-03-14 21:39:43 -07:00
local inv = meta:get_inventory()
2016-04-13 08:22:52 -07:00
if fields["crownmould"]
2015-03-14 21:39:43 -07:00
or fields["crownmould_ic"]
or fields["crownmould_oc"]
or fields["crownmould_beam"]
2016-04-13 08:22:52 -07:00
or fields["column"]
2015-03-14 21:39:43 -07:00
or fields["column_base"]
2016-04-13 08:22:52 -07:00
or fields["column_half"]
2015-03-14 21:39:43 -07:00
or fields["column_half_base"]
2016-04-13 08:22:52 -07:00
or fields["column_half_wbeam"]
or fields["column_quarter"]
or fields["column_quarter_base"]
2015-03-14 21:39:43 -07:00
or fields["column_quarter_wbase"]
or fields["column_quarter_fancybase"]
2016-04-13 08:22:52 -07:00
or fields["ceiling"]
or fields["ceiling_post"]
or fields["beam"]
or fields["beam_t"]
2015-03-14 21:39:43 -07:00
or fields["beam_ceiling_t"]
2016-04-13 08:22:52 -07:00
or fields["base"]
or fields["base_ic"]
or fields["base_oc"]
2015-03-14 21:39:43 -07:00
or fields["base_fancy"]
or fields["base_fancy_ic"]
2016-04-13 08:22:52 -07:00
or fields["base_fancy_oc"]
2015-03-14 21:39:43 -07:00
then
2016-04-13 08:22:52 -07:00
if inv:is_empty("ingot") then
return
end
--Crown Mould
2015-03-14 21:39:43 -07:00
if fields["crownmould"] then
make_ok = "0"
anzahl = "1"
shape = "mymillwork:crownmould_"
2016-04-13 08:22:52 -07:00
elseif fields["crownmould_ic"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:crownmould_ic_"
2016-04-13 08:22:52 -07:00
elseif fields["crownmould_oc"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:crownmould_oc_"
2016-04-13 08:22:52 -07:00
elseif fields["crownmould_beam"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:crownmould_beam_"
2016-04-13 08:22:52 -07:00
--Columns
2015-03-14 21:39:43 -07:00
2016-04-13 08:22:52 -07:00
elseif fields["column"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:column_"
2016-04-13 08:22:52 -07:00
elseif fields["column_base"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:column_base_"
2016-04-13 08:22:52 -07:00
elseif fields["column_half"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:column_half_"
2016-04-13 08:22:52 -07:00
elseif fields["column_half_base"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:column_half_base_"
2016-04-13 08:22:52 -07:00
elseif fields["column_half_wbeam"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "1"
shape = "mymillwork:column_half_wbeam_"
2016-04-13 08:22:52 -07:00
elseif fields["column_quarter"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "4"
shape = "mymillwork:column_quarter_"
2016-04-13 08:22:52 -07:00
elseif fields["column_quarter_base"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "4"
shape = "mymillwork:column_quarter_base_"
2016-04-13 08:22:52 -07:00
elseif fields["column_quarter_wbase"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:column_quarter_wbase_"
2016-04-13 08:22:52 -07:00
elseif fields["column_quarter_fancybase"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:column_quarter_fancybase_"
2016-04-13 08:22:52 -07:00
--Ceiling
2015-03-14 21:39:43 -07:00
2016-04-13 08:22:52 -07:00
elseif fields["ceiling"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "6"
shape = "mymillwork:ceiling_"
2016-04-13 08:22:52 -07:00
elseif fields["ceiling_post"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "4"
shape = "mymillwork:ceiling_post_"
2016-04-13 08:22:52 -07:00
--Beam
2015-03-14 21:39:43 -07:00
2016-04-13 08:22:52 -07:00
elseif fields["beam"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:beam_"
2016-04-13 08:22:52 -07:00
elseif fields["beam_t"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:beam_t_"
2016-04-13 08:22:52 -07:00
elseif fields["beam_ceiling_t"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "2"
shape = "mymillwork:beam_ceiling_t_"
2016-04-13 08:22:52 -07:00
--Base
2015-03-14 21:39:43 -07:00
2016-04-13 08:22:52 -07:00
elseif fields["base"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "8"
shape = "mymillwork:base_"
2016-04-13 08:22:52 -07:00
elseif fields["base_ic"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "4"
shape = "mymillwork:base_ic_"
2016-04-13 08:22:52 -07:00
elseif fields["base_oc"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "10"
shape = "mymillwork:base_oc_"
2016-04-13 08:22:52 -07:00
elseif fields["base_fancy"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "6"
shape = "mymillwork:base_fancy_"
2016-04-13 08:22:52 -07:00
elseif fields["base_fancy_ic"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "3"
shape = "mymillwork:base_fancy_ic_"
2016-04-13 08:22:52 -07:00
elseif fields["base_fancy_oc"] then
2015-03-14 21:39:43 -07:00
make_ok = "0"
anzahl = "8"
shape = "mymillwork:base_fancy_oc_"
end
local ingotstack = inv:get_stack("ingot", 1)
local resstack = inv:get_stack("res", 1)
2015-03-16 11:13:47 -07:00
2016-09-30 20:07:45 -06:00
for i in ipairs(mymillwork.registered) do
local itm = mymillwork.registered[i][1]
local mat = mymillwork.registered[i][2]
2016-04-13 08:22:52 -07:00
if ingotstack:get_name()== itm then
material = mat
2015-03-16 11:13:47 -07:00
make_ok = "1"
end
2016-04-13 08:22:52 -07:00
end
2015-03-16 11:13:47 -07:00
2015-03-14 21:39:43 -07:00
if make_ok == "1" then
local give = {}
for i = 0, anzahl-1 do
give[i+1]=inv:add_item("res",shape..material)
end
2016-04-13 08:22:52 -07:00
if not minetest.setting_getbool("creative_mode") then
ingotstack:take_item()
end
2015-03-14 21:39:43 -07:00
inv:set_stack("ingot",1,ingotstack)
2016-04-13 08:22:52 -07:00
end
2015-03-14 21:39:43 -07:00
end
end
})
--Craft
minetest.register_craft({
output = 'mymillwork:machine',
recipe = {
2016-04-13 08:22:52 -07:00
{'', 'default:steel_ingot',''},
2015-03-14 21:39:43 -07:00
{'default:steelblock', 'default:steelblock', 'default:steelblock'},
2016-04-13 08:22:52 -07:00
{'default:steel_ingot','' , 'default:steel_ingot'},
2015-03-14 21:39:43 -07:00
},
})