commit | author | age
|
ee0765
|
1 |
|
0809dd
|
2 |
local S = technic.getter |
S |
3 |
|
967886
|
4 |
-- handles the machine upgrades every tick |
ee0765
|
5 |
function technic.handle_machine_upgrades(meta) |
S |
6 |
-- Get the names of the upgrades |
|
7 |
local inv = meta:get_inventory() |
967886
|
8 |
|
ee0765
|
9 |
local srcstack = inv:get_stack("upgrade1", 1) |
967886
|
10 |
local upg_item1 = srcstack and srcstack:get_name() |
T |
11 |
|
ee0765
|
12 |
srcstack = inv:get_stack("upgrade2", 1) |
967886
|
13 |
local upg_item2 = srcstack and srcstack:get_name() |
ee0765
|
14 |
|
S |
15 |
-- Save some power by installing battery upgrades. |
|
16 |
-- Tube loading speed can be upgraded using control logic units. |
|
17 |
local EU_upgrade = 0 |
|
18 |
local tube_upgrade = 0 |
967886
|
19 |
|
T |
20 |
if upg_item1 == "technic:control_logic_unit" then |
|
21 |
tube_upgrade = tube_upgrade + 1 |
|
22 |
elseif upg_item1 == "technic:battery" then |
|
23 |
EU_upgrade = EU_upgrade + 1 |
ee0765
|
24 |
end |
967886
|
25 |
|
T |
26 |
if upg_item2 == "technic:control_logic_unit" then |
|
27 |
tube_upgrade = tube_upgrade + 1 |
|
28 |
elseif upg_item2 == "technic:battery" then |
|
29 |
EU_upgrade = EU_upgrade + 1 |
ee0765
|
30 |
end |
967886
|
31 |
|
ee0765
|
32 |
return EU_upgrade, tube_upgrade |
967886
|
33 |
end |
T |
34 |
|
|
35 |
-- handles the machine upgrades when set or removed |
|
36 |
local function on_machine_upgrade(meta, stack) |
a13e7b
|
37 |
local stack_name = stack:get_name() |
T |
38 |
if stack_name == "default:chest" then |
|
39 |
meta:set_int("public", 1) |
|
40 |
return 1 |
|
41 |
elseif stack_name ~= "technic:control_logic_unit" |
|
42 |
and stack_name ~= "technic:battery" then |
967886
|
43 |
return 0 |
T |
44 |
end |
a13e7b
|
45 |
return 1 |
T |
46 |
end |
967886
|
47 |
|
a13e7b
|
48 |
-- something is about to be removed |
T |
49 |
local function on_machine_downgrade(meta, stack, list) |
|
50 |
if stack:get_name() == "default:chest" then |
|
51 |
local inv = meta:get_inventory() |
|
52 |
local upg1, upg2 = inv:get_stack("upgrade1", 1), inv:get_stack("upgrade2", 1) |
|
53 |
|
|
54 |
-- only set 0 if theres not a nother chest in the other list too |
|
55 |
if (not upg1 or not upg2 or upg1:get_name() ~= upg2:get_name()) then |
|
56 |
meta:set_int("public", 0) |
|
57 |
end |
|
58 |
end |
967886
|
59 |
return 1 |
ee0765
|
60 |
end |
S |
61 |
|
|
62 |
|
6a0807
|
63 |
function technic.send_items(pos, x_velocity, z_velocity, output_name) |
ee0765
|
64 |
-- Send items on their way in the pipe system. |
6a0807
|
65 |
if output_name == nil then |
N |
66 |
output_name = "dst" |
|
67 |
end |
|
68 |
|
ee0765
|
69 |
local meta = minetest.get_meta(pos) |
S |
70 |
local inv = meta:get_inventory() |
|
71 |
local i = 0 |
6a0807
|
72 |
for _, stack in ipairs(inv:get_list(output_name)) do |
ee0765
|
73 |
i = i + 1 |
S |
74 |
if stack then |
|
75 |
local item0 = stack:to_table() |
|
76 |
if item0 then |
|
77 |
item0["count"] = "1" |
049129
|
78 |
technic.tube_inject_item(pos, pos, vector.new(x_velocity, 0, z_velocity), item0) |
ee0765
|
79 |
stack:take_item(1) |
6a0807
|
80 |
inv:set_stack(output_name, i, stack) |
ee0765
|
81 |
return |
S |
82 |
end |
|
83 |
end |
|
84 |
end |
|
85 |
end |
|
86 |
|
|
87 |
|
|
88 |
function technic.smelt_item(meta, result, speed) |
|
89 |
local inv = meta:get_inventory() |
|
90 |
meta:set_int("cook_time", meta:get_int("cook_time") + 1) |
|
91 |
if meta:get_int("cook_time") < result.time / speed then |
|
92 |
return |
|
93 |
end |
6ec12b
|
94 |
local result |
G |
95 |
local afterfuel |
|
96 |
result, afterfuel = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) |
ee0765
|
97 |
|
S |
98 |
if result and result.item then |
|
99 |
meta:set_int("cook_time", 0) |
|
100 |
-- check if there's room for output in "dst" list |
bd3cc7
|
101 |
if inv:room_for_item("dst", result.item) then |
6ec12b
|
102 |
inv:set_stack("src", 1, afterfuel.items[1]) |
ee0765
|
103 |
inv:add_item("dst", result.item) |
S |
104 |
end |
|
105 |
end |
|
106 |
end |
|
107 |
|
6a0807
|
108 |
function technic.handle_machine_pipeworks(pos, tube_upgrade, send_function) |
N |
109 |
if send_function == nil then |
|
110 |
send_function = technic.send_items |
|
111 |
end |
|
112 |
|
ee0765
|
113 |
local node = minetest.get_node(pos) |
S |
114 |
local meta = minetest.get_meta(pos) |
|
115 |
local inv = meta:get_inventory() |
|
116 |
local pos1 = vector.new(pos) |
|
117 |
local x_velocity = 0 |
|
118 |
local z_velocity = 0 |
|
119 |
|
|
120 |
-- Output is on the left side of the furnace |
|
121 |
if node.param2 == 3 then pos1.z = pos1.z - 1 z_velocity = -1 end |
|
122 |
if node.param2 == 2 then pos1.x = pos1.x - 1 x_velocity = -1 end |
|
123 |
if node.param2 == 1 then pos1.z = pos1.z + 1 z_velocity = 1 end |
|
124 |
if node.param2 == 0 then pos1.x = pos1.x + 1 x_velocity = 1 end |
|
125 |
|
|
126 |
local output_tube_connected = false |
35b10a
|
127 |
local node1 = minetest.get_node(pos1) |
N |
128 |
if minetest.get_item_group(node1.name, "tubedevice") > 0 then |
ee0765
|
129 |
output_tube_connected = true |
S |
130 |
end |
5382a8
|
131 |
local tube_time = meta:get_int("tube_time") + tube_upgrade |
c5d287
|
132 |
if tube_time >= 2 then |
ee0765
|
133 |
tube_time = 0 |
S |
134 |
if output_tube_connected then |
6a0807
|
135 |
send_function(pos, x_velocity, z_velocity) |
ee0765
|
136 |
end |
S |
137 |
end |
|
138 |
meta:set_int("tube_time", tube_time) |
|
139 |
end |
|
140 |
|
0809dd
|
141 |
function technic.machine_can_dig(pos, player) |
S |
142 |
local meta = minetest.get_meta(pos) |
|
143 |
local inv = meta:get_inventory() |
48e02b
|
144 |
if not inv:is_empty("src") or not inv:is_empty("dst") then |
f205e5
|
145 |
if player then |
Z |
146 |
minetest.chat_send_player(player:get_player_name(), |
|
147 |
S("Machine cannot be removed because it is not empty")) |
|
148 |
end |
0809dd
|
149 |
return false |
S |
150 |
else |
48e02b
|
151 |
if not inv:is_empty("upgrade1") then |
T |
152 |
minetest.item_drop(inv:get_stack("upgrade1", 1), "", pos) |
|
153 |
end |
|
154 |
if not inv:is_empty("upgrade2") then |
|
155 |
minetest.item_drop(inv:get_stack("upgrade2", 1), "", pos) |
|
156 |
end |
0809dd
|
157 |
return true |
S |
158 |
end |
|
159 |
end |
|
160 |
|
967886
|
161 |
local function inv_change(pos, player, count, from_list, to_list, stack) |
T |
162 |
local playername = player:get_player_name() |
a13e7b
|
163 |
local meta = minetest.get_meta(pos); |
T |
164 |
local public = (meta:get_int("public") == 1) |
|
165 |
local to_upgrade = to_list == "upgrade1" or to_list == "upgrade2" |
|
166 |
local from_upgrade = from_list == "upgrade1" or from_list == "upgrade2" |
|
167 |
|
|
168 |
if (not public or to_upgrade or from_upgrade) and minetest.is_protected(pos, playername) then |
967886
|
169 |
minetest.chat_send_player(playername, S("Inventory move disallowed due to protection")) |
0809dd
|
170 |
return 0 |
S |
171 |
end |
a13e7b
|
172 |
if to_upgrade then |
6ef343
|
173 |
-- only place a single item into it, if it's empty |
967886
|
174 |
local empty = meta:get_inventory():is_empty(to_list) |
T |
175 |
if empty then |
|
176 |
return on_machine_upgrade(meta, stack) |
|
177 |
end |
|
178 |
return 0 |
a13e7b
|
179 |
elseif from_upgrade then |
T |
180 |
-- only called on take (not move) |
|
181 |
on_machine_downgrade(meta, stack, from_list) |
6ef343
|
182 |
end |
0809dd
|
183 |
return count |
S |
184 |
end |
|
185 |
|
|
186 |
function technic.machine_inventory_put(pos, listname, index, stack, player) |
967886
|
187 |
return inv_change(pos, player, stack:get_count(), nil, listname, stack) |
0809dd
|
188 |
end |
S |
189 |
|
|
190 |
function technic.machine_inventory_take(pos, listname, index, stack, player) |
967886
|
191 |
return inv_change(pos, player, stack:get_count(), listname, nil, stack) |
0809dd
|
192 |
end |
S |
193 |
|
|
194 |
function technic.machine_inventory_move(pos, from_list, from_index, |
|
195 |
to_list, to_index, count, player) |
967886
|
196 |
local stack = minetest.get_meta(pos):get_inventory():get_stack(from_list, from_index) |
T |
197 |
return inv_change(pos, player, count, from_list, to_list, stack) |
0809dd
|
198 |
end |
S |
199 |
|