commit | author | age
|
ee0765
|
1 |
|
S |
2 |
function technic.handle_machine_upgrades(meta) |
|
3 |
-- Get the names of the upgrades |
|
4 |
local inv = meta:get_inventory() |
|
5 |
local upg_item1 |
|
6 |
local upg_item2 |
|
7 |
local srcstack = inv:get_stack("upgrade1", 1) |
|
8 |
if srcstack then |
|
9 |
upg_item1 = srcstack:to_table() |
|
10 |
end |
|
11 |
srcstack = inv:get_stack("upgrade2", 1) |
|
12 |
if srcstack then |
|
13 |
upg_item2 = srcstack:to_table() |
|
14 |
end |
|
15 |
|
|
16 |
-- Save some power by installing battery upgrades. |
|
17 |
-- Tube loading speed can be upgraded using control logic units. |
|
18 |
local EU_upgrade = 0 |
|
19 |
local tube_upgrade = 0 |
|
20 |
if upg_item1 then |
|
21 |
if upg_item1.name == "technic:battery" then |
|
22 |
EU_upgrade = EU_upgrade + 1 |
|
23 |
elseif upg_item1.name == "technic:control_logic_unit" then |
|
24 |
tube_upgrade = tube_upgrade + 1 |
|
25 |
end |
|
26 |
end |
|
27 |
if upg_item2 then |
|
28 |
if upg_item2.name == "technic:battery" then |
|
29 |
EU_upgrade = EU_upgrade + 1 |
|
30 |
elseif upg_item2.name == "technic:control_logic_unit" then |
|
31 |
tube_upgrade = tube_upgrade + 1 |
|
32 |
end |
|
33 |
end |
|
34 |
return EU_upgrade, tube_upgrade |
|
35 |
end |
|
36 |
|
|
37 |
|
|
38 |
function technic.send_items(pos, x_velocity, z_velocity) |
|
39 |
-- Send items on their way in the pipe system. |
|
40 |
local meta = minetest.get_meta(pos) |
|
41 |
local inv = meta:get_inventory() |
|
42 |
local i = 0 |
|
43 |
for _, stack in ipairs(inv:get_list("dst")) do |
|
44 |
i = i + 1 |
|
45 |
if stack then |
|
46 |
local item0 = stack:to_table() |
|
47 |
if item0 then |
|
48 |
item0["count"] = "1" |
|
49 |
local item1 = tube_item({x=pos.x, y=pos.y, z=pos.z}, item0) |
|
50 |
item1:get_luaentity().start_pos = {x=pos.x, y=pos.y, z=pos.z} |
|
51 |
item1:setvelocity({x=x_velocity, y=0, z=z_velocity}) |
|
52 |
item1:setacceleration({x=0, y=0, z=0}) |
|
53 |
stack:take_item(1) |
|
54 |
inv:set_stack("dst", i, stack) |
|
55 |
return |
|
56 |
end |
|
57 |
end |
|
58 |
end |
|
59 |
end |
|
60 |
|
|
61 |
|
|
62 |
function technic.smelt_item(meta, result, speed) |
|
63 |
local inv = meta:get_inventory() |
|
64 |
meta:set_int("cook_time", meta:get_int("cook_time") + 1) |
|
65 |
if meta:get_int("cook_time") < result.time / speed then |
|
66 |
return |
|
67 |
end |
|
68 |
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")}) |
|
69 |
|
|
70 |
if result and result.item then |
|
71 |
meta:set_int("cook_time", 0) |
|
72 |
-- check if there's room for output in "dst" list |
bd3cc7
|
73 |
if inv:room_for_item("dst", result.item) then |
ee0765
|
74 |
srcstack = inv:get_stack("src", 1) |
S |
75 |
srcstack:take_item() |
|
76 |
inv:set_stack("src", 1, srcstack) |
|
77 |
inv:add_item("dst", result.item) |
|
78 |
end |
|
79 |
end |
|
80 |
end |
|
81 |
|
|
82 |
function technic.handle_machine_pipeworks(pos, tube_upgrade) |
|
83 |
local node = minetest.get_node(pos) |
|
84 |
local meta = minetest.get_meta(pos) |
|
85 |
local inv = meta:get_inventory() |
|
86 |
local pos1 = vector.new(pos) |
|
87 |
local x_velocity = 0 |
|
88 |
local z_velocity = 0 |
|
89 |
|
|
90 |
-- Output is on the left side of the furnace |
|
91 |
if node.param2 == 3 then pos1.z = pos1.z - 1 z_velocity = -1 end |
|
92 |
if node.param2 == 2 then pos1.x = pos1.x - 1 x_velocity = -1 end |
|
93 |
if node.param2 == 1 then pos1.z = pos1.z + 1 z_velocity = 1 end |
|
94 |
if node.param2 == 0 then pos1.x = pos1.x + 1 x_velocity = 1 end |
|
95 |
|
|
96 |
local output_tube_connected = false |
|
97 |
local meta1 = minetest.get_meta(pos1) |
|
98 |
if meta1:get_int("tubelike") == 1 then |
|
99 |
output_tube_connected = true |
|
100 |
end |
|
101 |
tube_time = meta:get_int("tube_time") |
|
102 |
tube_time = tube_time + tube_upgrade |
|
103 |
if tube_time > 3 then |
|
104 |
tube_time = 0 |
|
105 |
if output_tube_connected then |
|
106 |
technic.send_items(pos, x_velocity, z_velocity) |
|
107 |
end |
|
108 |
end |
|
109 |
meta:set_int("tube_time", tube_time) |
|
110 |
end |
|
111 |
|