Carter Kolwey
2014-01-11 ebc114df71cc20868afbd3c6dea4039dc14c1a0e
commit | author | age
be2f30 1
S 2 technic.compressor_recipes = {}
3
4 local S = technic.getter
ee0765 5
S 6 technic.register_compressor_recipe = function(src, src_count, dst, dst_count)
7     technic.compressor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count}
8     if unified_inventory then
be2f30 9         unified_inventory.register_craft({
ee0765 10             type = "compressing",
S 11             output = dst.." "..dst_count,
12             items = {src.." "..src_count},
13             width = 0,
14         })
15     end
16 end
17
18 technic.get_compressor_recipe = function(item)
19     if technic.compressor_recipes[item.name] and 
20        item.count >= technic.compressor_recipes[item.name].src_count then
21         return technic.compressor_recipes[item.name]
22     else
23         return nil
24     end
25 end
26
27 technic.register_compressor_recipe("default:snowblock",         1, "default:ice",             1)
28 technic.register_compressor_recipe("default:sand",              1, "default:sandstone",       1)
29 technic.register_compressor_recipe("default:desert_sand",       1, "default:desert_stone",    1)
30 technic.register_compressor_recipe("technic:mixed_metal_ingot", 1, "technic:composite_plate", 1)
31 technic.register_compressor_recipe("default:copper_ingot",      5, "technic:copper_plate",    1)
32 technic.register_compressor_recipe("technic:coal_dust",         4, "technic:graphite",        1)
33 technic.register_compressor_recipe("technic:carbon_cloth",      1, "technic:carbon_plate",    1)
34 technic.register_compressor_recipe("technic:enriched_uranium",  4, "technic:uranium_fuel",    1)
35
36
37 minetest.register_alias("compressor", "technic:compressor")
38 minetest.register_craft({
39     output = 'technic:compressor',
40     recipe = {
41         {'default:stone',    'default:stone',    'default:stone'},
42         {'mesecons:piston',    'technic:motor',    'mesecons:piston'},
43         {'default:stone',    'technic:lv_cable0',    'default:stone'},
44     }
45 })
46
47 local compressor_formspec =
48     "invsize[8,9;]"..
be2f30 49     "label[0,0;"..S("Compressor").."]"..
ee0765 50     "list[current_name;src;3,1;1,1;]"..
S 51     "list[current_name;dst;5,1;2,2;]"..
52     "list[current_player;main;0,5;8,4;]"
53
54 minetest.register_node("technic:compressor", {
be2f30 55     description = S("Compressor"),
ee0765 56     tiles = {"technic_compressor_top.png",  "technic_compressor_bottom.png",
S 57              "technic_compressor_side.png", "technic_compressor_side.png",
58              "technic_compressor_back.png", "technic_compressor_front.png"},
59     paramtype2 = "facedir",
60     groups = {cracky=2},
61     legacy_facedir_simple = true,
62     sounds = default.node_sound_wood_defaults(),
63     on_construct = function(pos)
64         local meta = minetest.get_meta(pos)
be2f30 65         meta:set_string("infotext", S("Compressor"))
ee0765 66         meta:set_string("formspec", compressor_formspec)
S 67         local inv = meta:get_inventory()
68         inv:set_size("src", 1)
69         inv:set_size("dst", 4)
70     end,
0809dd 71     can_dig = technic.machine_can_dig,
S 72     allow_metadata_inventory_put = technic.machine_inventory_put,
73     allow_metadata_inventory_take = technic.machine_inventory_take,
74     allow_metadata_inventory_move = technic.machine_inventory_move,
ee0765 75 })
S 76
77 minetest.register_node("technic:compressor_active", {
be2f30 78     description = S("Compressor"),
ee0765 79     tiles = {"technic_compressor_top.png",  "technic_compressor_bottom.png",
S 80              "technic_compressor_side.png", "technic_compressor_side.png",
81              "technic_compressor_back.png", "technic_compressor_front_active.png"},
82     paramtype2 = "facedir",
83     groups = {cracky=2, not_in_creative_inventory=1},
84     legacy_facedir_simple = true,
85     sounds = default.node_sound_wood_defaults(),
0809dd 86     can_dig = technic.machine_can_dig,
S 87     allow_metadata_inventory_put = technic.machine_inventory_put,
88     allow_metadata_inventory_take = technic.machine_inventory_take,
89     allow_metadata_inventory_move = technic.machine_inventory_move,
ee0765 90 })
S 91
92 minetest.register_abm({
93     nodenames = {"technic:compressor","technic:compressor_active"},
94     interval = 1,
95     chance   = 1,
96     action = function(pos, node, active_object_count, active_object_count_wider)
97         local meta         = minetest.get_meta(pos)
98         local eu_input     = meta:get_int("LV_EU_input")
be2f30 99         local machine_name = S("Compressor")
ee0765 100         local machine_node = "technic:compressor"
S 101         local demand       = 300
102  
103          -- Setup meta data if it does not exist.
104         if not eu_input then
105             meta:set_int("LV_EU_demand", demand)
106             meta:set_int("LV_EU_input", 0)
107             return
108         end
109  
110         -- Power off automatically if no longer connected to a switching station
111         technic.switching_station_timeout_count(pos, "LV")
112         local inv    = meta:get_inventory()
113         local empty  = inv:is_empty("src")
114         local srcstack  = inv:get_stack("src", 1)
115         local src_item, recipe, result = nil, nil, nil
116
117         if srcstack then
118             src_item = srcstack:to_table()
119         end
120         if src_item then
121             recipe = technic.get_compressor_recipe(src_item)
122         end
123         if recipe then
124             result = {name=recipe.dst_name, count=recipe.dst_count}
125         end 
126         if empty or (not result) or
127            (not inv:room_for_item("dst", result)) then
f3d8b4 128             technic.swap_node(pos, machine_node)
be2f30 129             meta:set_string("infotext", S("%s Idle"):format(machine_name))
ee0765 130             meta:set_int("LV_EU_demand", 0)
S 131             meta:set_int("src_time", 0)
132             return
133         end
134
135         if eu_input < demand then
f3d8b4 136             technic.swap_node(pos, machine_node)
be2f30 137             meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
ee0765 138         elseif eu_input >= demand then
f3d8b4 139             technic.swap_node(pos, machine_node.."_active")
be2f30 140             meta:set_string("infotext", S("%s Active"):format(machine_name))
ee0765 141
S 142             meta:set_int("src_time", meta:get_int("src_time") + 1)
143             if meta:get_int("src_time") >= 4 then 
144                 meta:set_int("src_time", 0)
145                 srcstack:take_item(recipe.src_count)
146                 inv:set_stack("src", 1, srcstack)
147                 inv:add_item("dst", result)
148             end
149         end
150         meta:set_int("LV_EU_demand", demand)
151     end
152 })
153
154 technic.register_machine("LV", "technic:compressor",        technic.receiver)
155 technic.register_machine("LV", "technic:compressor_active", technic.receiver)
156