commit | author | age
|
aa8af0
|
1 |
|
N |
2 |
local S = technic.getter |
|
3 |
|
|
4 |
local tube = { |
|
5 |
insert_object = function(pos, node, stack, direction) |
|
6 |
local meta = minetest.get_meta(pos) |
|
7 |
local inv = meta:get_inventory() |
|
8 |
return inv:add_item("src", stack) |
|
9 |
end, |
|
10 |
can_insert = function(pos, node, stack, direction) |
|
11 |
local meta = minetest.get_meta(pos) |
|
12 |
local inv = meta:get_inventory() |
|
13 |
return inv:room_for_item("src", stack) |
|
14 |
end, |
|
15 |
connect_sides = {left = 1, right = 1, back = 1, top = 1, bottom = 1}, |
|
16 |
} |
|
17 |
|
|
18 |
function technic.register_base_machine(data) |
|
19 |
local typename = data.typename |
dd65a6
|
20 |
local input_size = technic.recipes[typename].input_size |
aa8af0
|
21 |
local machine_name = data.machine_name |
N |
22 |
local machine_desc = data.machine_desc |
|
23 |
local tier = data.tier |
|
24 |
local ltier = string.lower(tier) |
|
25 |
|
563a4c
|
26 |
local groups = {cracky = 2, technic_machine = 1} |
N |
27 |
local active_groups = {cracky = 2, technic_machine = 1, not_in_creative_inventory = 1} |
aa8af0
|
28 |
if data.tube then |
N |
29 |
groups.tubedevice = 1 |
|
30 |
groups.tubedevice_receiver = 1 |
|
31 |
active_groups.tubedevice = 1 |
|
32 |
active_groups.tubedevice_receiver = 1 |
|
33 |
end |
|
34 |
|
|
35 |
|
|
36 |
local formspec = |
|
37 |
"invsize[8,9;]".. |
dd65a6
|
38 |
"list[current_name;src;"..(4-input_size)..",1;"..input_size..",1;]".. |
aa8af0
|
39 |
"list[current_name;dst;5,1;2,2;]".. |
N |
40 |
"list[current_player;main;0,5;8,4;]".. |
5f2d09
|
41 |
"label[0,0;"..machine_desc:format(tier).."]" |
aa8af0
|
42 |
if data.upgrade then |
N |
43 |
formspec = formspec.. |
|
44 |
"list[current_name;upgrade1;1,3;1,1;]".. |
|
45 |
"list[current_name;upgrade2;2,3;1,1;]".. |
|
46 |
"label[1,4;"..S("Upgrade Slots").."]" |
|
47 |
end |
|
48 |
|
563a4c
|
49 |
local run = function(pos, node) |
N |
50 |
local meta = minetest.get_meta(pos) |
|
51 |
local inv = meta:get_inventory() |
|
52 |
local eu_input = meta:get_int(tier.."_EU_input") |
|
53 |
|
|
54 |
local machine_desc_tier = machine_desc:format(tier) |
|
55 |
local machine_node = "technic:"..ltier.."_"..machine_name |
|
56 |
local machine_demand = data.demand |
|
57 |
|
|
58 |
-- Setup meta data if it does not exist. |
|
59 |
if not eu_input then |
|
60 |
meta:set_int(tier.."_EU_demand", machine_demand[1]) |
|
61 |
meta:set_int(tier.."_EU_input", 0) |
|
62 |
return |
|
63 |
end |
|
64 |
|
|
65 |
local EU_upgrade, tube_upgrade = 0, 0 |
|
66 |
if data.upgrade then |
|
67 |
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta) |
|
68 |
end |
|
69 |
if data.tube then |
|
70 |
technic.handle_machine_pipeworks(pos, tube_upgrade) |
|
71 |
end |
|
72 |
|
|
73 |
local result = technic.get_recipe(typename, inv:get_list("src")) |
|
74 |
|
|
75 |
if not result then |
|
76 |
technic.swap_node(pos, machine_node) |
|
77 |
meta:set_string("infotext", S("%s Idle"):format(machine_desc_tier)) |
|
78 |
meta:set_int(tier.."_EU_demand", 0) |
|
79 |
return |
|
80 |
end |
|
81 |
|
|
82 |
if eu_input < machine_demand[EU_upgrade+1] then |
|
83 |
-- Unpowered - go idle |
|
84 |
technic.swap_node(pos, machine_node) |
|
85 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_desc_tier)) |
|
86 |
elseif eu_input >= machine_demand[EU_upgrade+1] then |
|
87 |
-- Powered |
|
88 |
technic.swap_node(pos, machine_node.."_active") |
|
89 |
meta:set_string("infotext", S("%s Active"):format(machine_desc_tier)) |
|
90 |
|
|
91 |
meta:set_int("src_time", meta:get_int("src_time") + 1) |
|
92 |
if meta:get_int("src_time") >= result.time / data.speed then |
|
93 |
meta:set_int("src_time", 0) |
dd65a6
|
94 |
local output = result.output |
Z |
95 |
if type(output) ~= "table" then output = { output } end |
|
96 |
local output_stacks = {} |
|
97 |
for _, o in ipairs(output) do |
|
98 |
table.insert(output_stacks, ItemStack(o)) |
|
99 |
end |
|
100 |
local room_for_output = true |
|
101 |
inv:set_size("dst_tmp", inv:get_size("dst")) |
|
102 |
inv:set_list("dst_tmp", inv:get_list("dst")) |
|
103 |
for _, o in ipairs(output_stacks) do |
|
104 |
if not inv:room_for_item("dst_tmp", o) then |
|
105 |
room_for_output = false |
|
106 |
break |
|
107 |
end |
|
108 |
inv:add_item("dst_tmp", o) |
|
109 |
end |
|
110 |
if room_for_output then |
563a4c
|
111 |
inv:set_list("src", result.new_input) |
dd65a6
|
112 |
inv:set_list("dst", inv:get_list("dst_tmp")) |
Z |
113 |
else |
563a4c
|
114 |
end |
N |
115 |
end |
|
116 |
end |
|
117 |
meta:set_int(tier.."_EU_demand", machine_demand[EU_upgrade+1]) |
|
118 |
end |
|
119 |
|
aa8af0
|
120 |
minetest.register_node("technic:"..ltier.."_"..machine_name, { |
N |
121 |
description = machine_desc:format(tier), |
|
122 |
tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", |
|
123 |
"technic_"..ltier.."_"..machine_name.."_bottom.png", |
|
124 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
125 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
126 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
127 |
"technic_"..ltier.."_"..machine_name.."_front.png"}, |
|
128 |
paramtype2 = "facedir", |
|
129 |
groups = groups, |
|
130 |
tube = data.tube and tube or nil, |
|
131 |
legacy_facedir_simple = true, |
|
132 |
sounds = default.node_sound_wood_defaults(), |
|
133 |
on_construct = function(pos) |
|
134 |
local node = minetest.get_node(pos) |
|
135 |
local meta = minetest.get_meta(pos) |
|
136 |
meta:set_string("infotext", machine_desc:format(tier)) |
|
137 |
meta:set_int("tube_time", 0) |
|
138 |
meta:set_string("formspec", formspec) |
|
139 |
local inv = meta:get_inventory() |
dd65a6
|
140 |
inv:set_size("src", input_size) |
aa8af0
|
141 |
inv:set_size("dst", 4) |
N |
142 |
inv:set_size("upgrade1", 1) |
|
143 |
inv:set_size("upgrade2", 1) |
|
144 |
end, |
|
145 |
can_dig = technic.machine_can_dig, |
|
146 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
147 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
148 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
563a4c
|
149 |
technic_run = run, |
aa8af0
|
150 |
}) |
N |
151 |
|
|
152 |
minetest.register_node("technic:"..ltier.."_"..machine_name.."_active",{ |
|
153 |
description = machine_desc:format(tier), |
|
154 |
tiles = {"technic_"..ltier.."_"..machine_name.."_top.png", |
|
155 |
"technic_"..ltier.."_"..machine_name.."_bottom.png", |
|
156 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
157 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
158 |
"technic_"..ltier.."_"..machine_name.."_side.png", |
|
159 |
"technic_"..ltier.."_"..machine_name.."_front_active.png"}, |
|
160 |
paramtype2 = "facedir", |
|
161 |
drop = "technic:"..ltier.."_"..machine_name, |
|
162 |
groups = active_groups, |
|
163 |
legacy_facedir_simple = true, |
|
164 |
sounds = default.node_sound_wood_defaults(), |
|
165 |
tube = data.tube and tube or nil, |
|
166 |
can_dig = technic.machine_can_dig, |
|
167 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
168 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
169 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
563a4c
|
170 |
technic_run = run, |
N |
171 |
technic_disabled_machine_name = "technic:"..ltier.."_"..machine_name, |
aa8af0
|
172 |
}) |
N |
173 |
|
|
174 |
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name, technic.receiver) |
|
175 |
technic.register_machine(tier, "technic:"..ltier.."_"..machine_name.."_active", technic.receiver) |
|
176 |
|
|
177 |
end -- End registration |
|
178 |
|