commit | author | age
|
ee0765
|
1 |
|
0809dd
|
2 |
local S = technic.getter |
S |
3 |
|
ee0765
|
4 |
function technic.handle_machine_upgrades(meta) |
S |
5 |
-- Get the names of the upgrades |
|
6 |
local inv = meta:get_inventory() |
|
7 |
local upg_item1 |
|
8 |
local upg_item2 |
|
9 |
local srcstack = inv:get_stack("upgrade1", 1) |
|
10 |
if srcstack then |
|
11 |
upg_item1 = srcstack:to_table() |
|
12 |
end |
|
13 |
srcstack = inv:get_stack("upgrade2", 1) |
|
14 |
if srcstack then |
|
15 |
upg_item2 = srcstack:to_table() |
|
16 |
end |
|
17 |
|
|
18 |
-- Save some power by installing battery upgrades. |
|
19 |
-- Tube loading speed can be upgraded using control logic units. |
|
20 |
local EU_upgrade = 0 |
|
21 |
local tube_upgrade = 0 |
|
22 |
if upg_item1 then |
|
23 |
if upg_item1.name == "technic:battery" then |
|
24 |
EU_upgrade = EU_upgrade + 1 |
|
25 |
elseif upg_item1.name == "technic:control_logic_unit" then |
|
26 |
tube_upgrade = tube_upgrade + 1 |
|
27 |
end |
|
28 |
end |
|
29 |
if upg_item2 then |
|
30 |
if upg_item2.name == "technic:battery" then |
|
31 |
EU_upgrade = EU_upgrade + 1 |
|
32 |
elseif upg_item2.name == "technic:control_logic_unit" then |
|
33 |
tube_upgrade = tube_upgrade + 1 |
|
34 |
end |
|
35 |
end |
|
36 |
return EU_upgrade, tube_upgrade |
|
37 |
end |
|
38 |
|
|
39 |
|
6a0807
|
40 |
function technic.send_items(pos, x_velocity, z_velocity, output_name) |
ee0765
|
41 |
-- Send items on their way in the pipe system. |
6a0807
|
42 |
if output_name == nil then |
N |
43 |
output_name = "dst" |
|
44 |
end |
|
45 |
|
ee0765
|
46 |
local meta = minetest.get_meta(pos) |
S |
47 |
local inv = meta:get_inventory() |
|
48 |
local i = 0 |
6a0807
|
49 |
for _, stack in ipairs(inv:get_list(output_name)) do |
ee0765
|
50 |
i = i + 1 |
S |
51 |
if stack then |
|
52 |
local item0 = stack:to_table() |
|
53 |
if item0 then |
|
54 |
item0["count"] = "1" |
049129
|
55 |
technic.tube_inject_item(pos, pos, vector.new(x_velocity, 0, z_velocity), item0) |
ee0765
|
56 |
stack:take_item(1) |
6a0807
|
57 |
inv:set_stack(output_name, i, stack) |
ee0765
|
58 |
return |
S |
59 |
end |
|
60 |
end |
|
61 |
end |
|
62 |
end |
|
63 |
|
|
64 |
|
|
65 |
function technic.smelt_item(meta, result, speed) |
|
66 |
local inv = meta:get_inventory() |
|
67 |
meta:set_int("cook_time", meta:get_int("cook_time") + 1) |
|
68 |
if meta:get_int("cook_time") < result.time / speed then |
|
69 |
return |
|
70 |
end |
6ec12b
|
71 |
local result |
G |
72 |
local afterfuel |
|
73 |
result, afterfuel = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) |
ee0765
|
74 |
|
S |
75 |
if result and result.item then |
|
76 |
meta:set_int("cook_time", 0) |
|
77 |
-- check if there's room for output in "dst" list |
bd3cc7
|
78 |
if inv:room_for_item("dst", result.item) then |
6ec12b
|
79 |
inv:set_stack("src", 1, afterfuel.items[1]) |
ee0765
|
80 |
inv:add_item("dst", result.item) |
S |
81 |
end |
|
82 |
end |
|
83 |
end |
|
84 |
|
6a0807
|
85 |
function technic.handle_machine_pipeworks(pos, tube_upgrade, send_function) |
N |
86 |
if send_function == nil then |
|
87 |
send_function = technic.send_items |
|
88 |
end |
|
89 |
|
ee0765
|
90 |
local node = minetest.get_node(pos) |
S |
91 |
local meta = minetest.get_meta(pos) |
|
92 |
local inv = meta:get_inventory() |
|
93 |
local pos1 = vector.new(pos) |
|
94 |
local x_velocity = 0 |
|
95 |
local z_velocity = 0 |
|
96 |
|
|
97 |
-- Output is on the left side of the furnace |
|
98 |
if node.param2 == 3 then pos1.z = pos1.z - 1 z_velocity = -1 end |
|
99 |
if node.param2 == 2 then pos1.x = pos1.x - 1 x_velocity = -1 end |
|
100 |
if node.param2 == 1 then pos1.z = pos1.z + 1 z_velocity = 1 end |
|
101 |
if node.param2 == 0 then pos1.x = pos1.x + 1 x_velocity = 1 end |
|
102 |
|
|
103 |
local output_tube_connected = false |
35b10a
|
104 |
local node1 = minetest.get_node(pos1) |
N |
105 |
if minetest.get_item_group(node1.name, "tubedevice") > 0 then |
ee0765
|
106 |
output_tube_connected = true |
S |
107 |
end |
|
108 |
tube_time = meta:get_int("tube_time") |
|
109 |
tube_time = tube_time + tube_upgrade |
c5d287
|
110 |
if tube_time >= 2 then |
ee0765
|
111 |
tube_time = 0 |
S |
112 |
if output_tube_connected then |
6a0807
|
113 |
send_function(pos, x_velocity, z_velocity) |
ee0765
|
114 |
end |
S |
115 |
end |
|
116 |
meta:set_int("tube_time", tube_time) |
|
117 |
end |
|
118 |
|
0809dd
|
119 |
|
S |
120 |
function technic.machine_can_dig(pos, player) |
|
121 |
local meta = minetest.get_meta(pos) |
|
122 |
local inv = meta:get_inventory() |
|
123 |
if not inv:is_empty("src") or not inv:is_empty("dst") or |
|
124 |
not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then |
|
125 |
minetest.chat_send_player(player:get_player_name(), |
|
126 |
S("Machine cannot be removed because it is not empty")) |
|
127 |
return false |
|
128 |
else |
|
129 |
return true |
|
130 |
end |
|
131 |
end |
|
132 |
|
|
133 |
local function inv_change(pos, player, count) |
|
134 |
if minetest.is_protected(pos, player:get_player_name()) then |
|
135 |
minetest.chat_send_player(player:get_player_name(), |
|
136 |
S("Inventory move disallowed due to protection")) |
|
137 |
return 0 |
|
138 |
end |
|
139 |
return count |
|
140 |
end |
|
141 |
|
|
142 |
function technic.machine_inventory_put(pos, listname, index, stack, player) |
|
143 |
return inv_change(pos, player, stack:get_count()) |
|
144 |
end |
|
145 |
|
|
146 |
function technic.machine_inventory_take(pos, listname, index, stack, player) |
|
147 |
return inv_change(pos, player, stack:get_count()) |
|
148 |
end |
|
149 |
|
|
150 |
function technic.machine_inventory_move(pos, from_list, from_index, |
|
151 |
to_list, to_index, count, player) |
|
152 |
return inv_change(pos, player, count) |
|
153 |
end |
|
154 |
|