ShadowNinja
2013-10-30 be2f30a1a2f5b6c2aae7fd4cf8231aec2da0844d
commit | author | age
be2f30 1 -- Tool workshop
ee0765 2 -- This machine repairs tools.
S 3
4 minetest.register_alias("tool_workshop", "technic:tool_workshop")
be2f30 5
S 6 local S = technic.getter
7
ee0765 8 minetest.register_craft({
S 9     output = 'technic:tool_workshop',
10     recipe = {
11         {'group:wood',    'group:wood',           'group:wood'},
12         {'group:wood',    'default:diamond',      'group:wood'},
13         {'default:stone', 'default:copper_ingot', 'default:stone'},
14     }
15 })
16
17 local workshop_formspec =
18     "invsize[8,9;]"..
19     "list[current_name;src;3,1;1,1;]"..
be2f30 20     "label[0,0;"..S("Tool Workshop").."]"..
ee0765 21     "list[current_player;main;0,5;8,4;]"
S 22
23 minetest.register_node("technic:tool_workshop", {
be2f30 24     description = S("Tool Workshop"),
ee0765 25     tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png",
S 26              "technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"},
27     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
28     sounds = default.node_sound_wood_defaults(),
29     on_construct = function(pos)
30         local meta = minetest.get_meta(pos)
be2f30 31         meta:set_string("infotext", S("Tool Workshop"))
ee0765 32         meta:set_string("formspec", workshop_formspec)
S 33         local inv = meta:get_inventory()
34         inv:set_size("src", 1)
35     end,    
36     can_dig = function(pos,player)
37         local meta = minetest.get_meta(pos);
38         local inv = meta:get_inventory()
39         if not inv:is_empty("src") then
40             minetest.chat_send_player(player:get_player_name(),
be2f30 41                 S("Machine cannot be removed because it is not empty"))
ee0765 42             return false
S 43         end
44         return true
45     end,
46 })
47
48 minetest.register_abm({
49     nodenames = {"technic:tool_workshop"},
50     interval = 1,
51     chance   = 1,
52     action = function(pos, node, active_object_count, active_object_count_wider)
53         local meta         = minetest.get_meta(pos)
54         local inv          = meta:get_inventory()
55         local eu_input     = meta:get_int("MV_EU_input")
be2f30 56         local machine_name = S("Tool Workshop")
ee0765 57         local machine_node = "technic:tool_workshop"
S 58         local demand       = 5000
59
60         -- Setup meta data if it does not exist.
61         if not eu_input then
62             meta:set_int("MV_EU_demand", demand)
63             meta:set_int("MV_EU_input", 0)
64             return
65         end
66
67         -- Power off automatically if no longer connected to a switching station
68         technic.switching_station_timeout_count(pos, "MV")
69
70         srcstack = inv:get_stack("src", 1)
71         if inv:is_empty("src") or
72            srcstack:get_wear() == 0 or
73            srcstack:get_name() == "technic:water_can" or
74            srcstack:get_name() == "technic:lava_can" then
be2f30 75             meta:set_string("infotext", S("%s Idle"):format(machine_name))
ee0765 76             meta:set_int("MV_EU_demand", 0)
S 77             return
78         end
79         
80         if eu_input < demand then
be2f30 81             meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
ee0765 82         elseif eu_input >= demand then
be2f30 83             meta:set_string("infotext", S("%s Active"):format(machine_name))
ee0765 84             srcstack:add_wear(-1000)
S 85             inv:set_stack("src", 1, srcstack)
86         end
87         meta:set_int("MV_EU_demand", demand)
88     end
89 }) 
90
91 technic.register_machine("MV", "technic:tool_workshop", technic.receiver)
92