SmallJoker
2013-12-01 7a3cd495972f2dc399d7af7f596a6d9a4a5c728b
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,    
0809dd 36     can_dig = technic.machine_can_dig,
S 37     allow_metadata_inventory_put = technic.machine_inventory_put,
38     allow_metadata_inventory_take = technic.machine_inventory_take,
ee0765 39 })
S 40
41 minetest.register_abm({
42     nodenames = {"technic:tool_workshop"},
43     interval = 1,
44     chance   = 1,
45     action = function(pos, node, active_object_count, active_object_count_wider)
46         local meta         = minetest.get_meta(pos)
47         local inv          = meta:get_inventory()
48         local eu_input     = meta:get_int("MV_EU_input")
be2f30 49         local machine_name = S("Tool Workshop")
ee0765 50         local machine_node = "technic:tool_workshop"
S 51         local demand       = 5000
52
53         -- Setup meta data if it does not exist.
54         if not eu_input then
55             meta:set_int("MV_EU_demand", demand)
56             meta:set_int("MV_EU_input", 0)
57             return
58         end
59
60         -- Power off automatically if no longer connected to a switching station
61         technic.switching_station_timeout_count(pos, "MV")
62
63         srcstack = inv:get_stack("src", 1)
64         if inv:is_empty("src") or
65            srcstack:get_wear() == 0 or
66            srcstack:get_name() == "technic:water_can" or
67            srcstack:get_name() == "technic:lava_can" then
be2f30 68             meta:set_string("infotext", S("%s Idle"):format(machine_name))
ee0765 69             meta:set_int("MV_EU_demand", 0)
S 70             return
71         end
72         
73         if eu_input < demand then
be2f30 74             meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
ee0765 75         elseif eu_input >= demand then
be2f30 76             meta:set_string("infotext", S("%s Active"):format(machine_name))
ee0765 77             srcstack:add_wear(-1000)
S 78             inv:set_stack("src", 1, srcstack)
79         end
80         meta:set_int("MV_EU_demand", demand)
81     end
82 }) 
83
84 technic.register_machine("MV", "technic:tool_workshop", technic.receiver)
85