commit | author | age
|
be2f30
|
1 |
|
ee0765
|
2 |
technic.extractor_recipes ={} |
be2f30
|
3 |
|
S |
4 |
local S = technic.getter |
ee0765
|
5 |
|
S |
6 |
technic.register_extractor_recipe = function(src, src_count, dst, dst_count) |
|
7 |
technic.extractor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count} |
|
8 |
if unified_inventory then |
|
9 |
unified_inventory.register_craft({ |
|
10 |
type = "extracting", |
|
11 |
output = dst.." "..dst_count, |
|
12 |
items = {src.." "..src_count}, |
|
13 |
width = 0, |
|
14 |
}) |
|
15 |
end |
|
16 |
end |
|
17 |
|
|
18 |
-- Receive an ItemStack of result by an ItemStack input |
|
19 |
technic.get_extractor_recipe = function(item) |
|
20 |
if technic.extractor_recipes[item.name] and |
|
21 |
item.count >= technic.extractor_recipes[item.name].src_count then |
|
22 |
return technic.extractor_recipes[item.name] |
|
23 |
else |
|
24 |
return nil |
|
25 |
end |
|
26 |
end |
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
technic.register_extractor_recipe("technic:coal_dust", 1, "dye:black", 2) |
|
31 |
technic.register_extractor_recipe("default:cactus", 1, "dye:green", 2) |
|
32 |
technic.register_extractor_recipe("default:dry_shrub", 1, "dye:brown", 2) |
|
33 |
technic.register_extractor_recipe("flowers:geranium", 1, "dye:blue", 2) |
|
34 |
technic.register_extractor_recipe("flowers:dandelion_white", 1, "dye:white", 2) |
|
35 |
technic.register_extractor_recipe("flowers:dandelion_yellow", 1, "dye:yellow", 2) |
|
36 |
technic.register_extractor_recipe("flowers:tulip", 1, "dye:orange", 2) |
|
37 |
technic.register_extractor_recipe("flowers:rose", 1, "dye:red", 2) |
|
38 |
technic.register_extractor_recipe("flowers:viola", 1, "dye:violet", 2) |
|
39 |
technic.register_extractor_recipe("technic:raw_latex", 1, "technic:rubber", 3) |
|
40 |
technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty", 1, "technic:rubber", 1) |
|
41 |
technic.register_extractor_recipe("moretrees:rubber_tree_trunk", 1, "technic:rubber", 1) |
|
42 |
technic.register_extractor_recipe("technic:uranium", 5, "technic:enriched_uranium", 1) |
|
43 |
|
|
44 |
minetest.register_alias("extractor", "technic:extractor") |
|
45 |
minetest.register_craft({ |
|
46 |
output = 'technic:extractor', |
|
47 |
recipe = { |
|
48 |
{'technic:treetap', 'technic:motor', 'technic:treetap'}, |
|
49 |
{'technic:treetap', 'technic:lv_cable0', 'technic:treetap'}, |
|
50 |
{'', '', ''}, |
|
51 |
} |
|
52 |
}) |
|
53 |
|
|
54 |
local extractor_formspec = |
|
55 |
"invsize[8,9;]".. |
be2f30
|
56 |
"label[0,0;"..S("Extractor").."]".. |
ee0765
|
57 |
"list[current_name;src;3,1;1,1;]".. |
S |
58 |
"list[current_name;dst;5,1;2,2;]".. |
|
59 |
"list[current_player;main;0,5;8,4;]" |
|
60 |
|
|
61 |
minetest.register_node("technic:extractor", { |
be2f30
|
62 |
description = S("Extractor"), |
ee0765
|
63 |
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", |
S |
64 |
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"}, |
|
65 |
paramtype2 = "facedir", |
|
66 |
groups = {cracky=2}, |
|
67 |
legacy_facedir_simple = true, |
|
68 |
sounds = default.node_sound_wood_defaults(), |
|
69 |
on_construct = function(pos) |
|
70 |
local meta = minetest.get_meta(pos) |
be2f30
|
71 |
meta:set_string("infotext", S("Extractor")) |
ee0765
|
72 |
meta:set_string("formspec", extractor_formspec) |
S |
73 |
local inv = meta:get_inventory() |
|
74 |
inv:set_size("src", 1) |
|
75 |
inv:set_size("dst", 4) |
|
76 |
end, |
0809dd
|
77 |
can_dig = technic.machine_can_dig, |
S |
78 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
79 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
80 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
81 |
}) |
S |
82 |
|
|
83 |
minetest.register_node("technic:extractor_active", { |
be2f30
|
84 |
description = S("Extractor"), |
ee0765
|
85 |
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", |
S |
86 |
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", |
|
87 |
"technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"}, |
|
88 |
paramtype2 = "facedir", |
|
89 |
groups = {cracky=2, not_in_creative_inventory=1}, |
|
90 |
legacy_facedir_simple = true, |
|
91 |
sounds = default.node_sound_wood_defaults(), |
0809dd
|
92 |
can_dig = technic.machine_can_dig, |
S |
93 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
94 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
95 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
ee0765
|
96 |
}) |
S |
97 |
|
|
98 |
minetest.register_abm({ |
|
99 |
nodenames = {"technic:extractor", "technic:extractor_active"}, |
|
100 |
interval = 1, |
|
101 |
chance = 1, |
|
102 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
103 |
-- The machine will automatically shut down if disconnected from power in some fashion. |
|
104 |
local meta = minetest.get_meta(pos) |
|
105 |
local inv = meta:get_inventory() |
|
106 |
local srcstack = inv:get_stack("src", 1) |
|
107 |
local eu_input = meta:get_int("LV_EU_input") |
|
108 |
|
|
109 |
-- Machine information |
be2f30
|
110 |
local machine_name = S("Extractor") |
ee0765
|
111 |
local machine_node = "technic:extractor" |
S |
112 |
local demand = 300 |
|
113 |
|
|
114 |
-- Setup meta data if it does not exist. |
|
115 |
if not eu_input then |
|
116 |
meta:set_int("LV_EU_demand", demand) |
|
117 |
meta:set_int("LV_EU_input", 0) |
|
118 |
return |
|
119 |
end |
|
120 |
|
|
121 |
-- Power off automatically if no longer connected to a switching station |
|
122 |
technic.switching_station_timeout_count(pos, "LV") |
|
123 |
|
d8437f
|
124 |
local src_item = nil |
ee0765
|
125 |
if srcstack then |
S |
126 |
src_item = srcstack:to_table() |
|
127 |
end |
|
128 |
if src_item then |
|
129 |
recipe = technic.get_extractor_recipe(src_item) |
|
130 |
end |
|
131 |
if recipe then |
|
132 |
result = {name=recipe.dst_name, count=recipe.dst_count} |
|
133 |
end |
|
134 |
if inv:is_empty("src") or (not recipe) or (not result) or |
|
135 |
(not inv:room_for_item("dst", result)) then |
f3d8b4
|
136 |
technic.swap_node(pos, machine_node) |
be2f30
|
137 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
ee0765
|
138 |
meta:set_int("LV_EU_demand", 0) |
S |
139 |
return |
|
140 |
end |
|
141 |
|
|
142 |
if eu_input < demand then |
|
143 |
-- unpowered - go idle |
f3d8b4
|
144 |
technic.swap_node(pos, machine_node) |
be2f30
|
145 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) |
ee0765
|
146 |
elseif eu_input >= demand then |
S |
147 |
-- Powered |
f3d8b4
|
148 |
technic.swap_node(pos, machine_node.."_active") |
be2f30
|
149 |
meta:set_string("infotext", S("%s Active"):format(machine_name)) |
ee0765
|
150 |
|
S |
151 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
|
152 |
if meta:get_int("src_time") >= 4 then -- 4 ticks per output |
|
153 |
meta:set_int("src_time", 0) |
|
154 |
srcstack:take_item(recipe.src_count) |
|
155 |
inv:set_stack("src", 1, srcstack) |
|
156 |
inv:add_item("dst", result) |
|
157 |
end |
|
158 |
end |
|
159 |
meta:set_int("LV_EU_demand", demand) |
|
160 |
end |
|
161 |
}) |
|
162 |
|
|
163 |
technic.register_machine("LV", "technic:extractor", technic.receiver) |
|
164 |
technic.register_machine("LV", "technic:extractor_active", technic.receiver) |
|
165 |
|