-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathairpump.lua
189 lines (150 loc) · 4.42 KB
/
airpump.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
local has_pipeworks = minetest.get_modpath("pipeworks")
local tube_entry = ""
if has_pipeworks then
tube_entry = "^pipeworks_tube_connection_wooden.png"
end
local update_infotext = function(meta)
local str = "Airpump: "
if vacuum.airpump_enabled(meta) then
str = str .. " (Enabled)"
else
str = str .. " (Disabled)"
end
meta:set_string("infotext", str)
end
-- update airpump formspec
local update_formspec = function(meta)
local btnName = "State: "
if meta:get_int("enabled") == 1 then
btnName = btnName .. "<Enabled>"
else
btnName = btnName .. "<Disabled>"
end
meta:set_string("formspec", "size[8,7.2;]" ..
"image[3,0;1,1;" .. vacuum.air_bottle_image .. "]" ..
"image[4,0;1,1;vessels_steel_bottle.png]" ..
"button[0,1;4,1;toggle;" .. btnName .. "]" ..
"button[4,1;4,1;flush;Flush room]" ..
"list[context;main;0,2;8,1;]" ..
"list[current_player;main;0,3.2;8,4;]" ..
"listring[]" ..
"")
update_infotext(meta)
end
minetest.register_node("vacuum:airpump", {
description = "Air pump",--tube_entry
tiles = { -- top, bottom
"vacuum_airpump_top.png",
"vacuum_airpump_side.png" .. tube_entry,
"vacuum_airpump_side.png" .. tube_entry,
"vacuum_airpump_side.png" .. tube_entry,
"vacuum_airpump_side.png" .. tube_entry,
"vacuum_airpump_front.png"
},
paramtype = "light",
paramtype2 = "facedir",
legacy_facedir_simple = true,
groups = {cracky=3, oddly_breakable_by_hand=3, tubedevice=1, tubedevice_receiver=1},
is_ground_content = false,
sounds = default.node_sound_glass_defaults(),
mesecons = {effector = {
action_on = function (pos, node)
local meta = minetest.get_meta(pos)
meta:set_int("enabled", 1)
update_infotext(meta)
end,
action_off = function (pos, node)
local meta = minetest.get_meta(pos)
meta:set_int("enabled", 0)
update_infotext(meta)
end
}},
digiline = {
receptor = {action = function() end},
effector = {
action = vacuum.airpump_digiline_effector
},
},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("enabled", 0)
local inv = meta:get_inventory()
inv:set_size("main", 8)
update_formspec(meta)
end,
can_dig = function(pos,player)
if player and player:is_player() and minetest.is_protected(pos, player:get_player_name()) then
-- protected
return false
end
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if player and player:is_player() and minetest.is_protected(pos, player:get_player_name()) then
-- protected
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if player and player:is_player() and minetest.is_protected(pos, player:get_player_name()) then
-- protected
return 0
end
return stack:get_count()
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if minetest.is_protected(pos, sender:get_player_name()) then
-- not allowed
return
end
if fields.flush then
if not vacuum.can_flush_airpump(pos) then
minetest.chat_send_player(
sender:get_player_name(),
"[airpump] Flush mode needs " .. vacuum.flush_bottle_usage .. " full air bottles, aborting!"
)
else
vacuum.flush_airpump(pos)
end
end
if fields.toggle then
if meta:get_int("enabled") == 1 then
meta:set_int("enabled", 0)
else
meta:set_int("enabled", 1)
end
end
update_formspec(meta)
end,
tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("main", stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
stack = stack:peek_item(1)
return inv:room_for_item("main", stack)
end,
input_inventory = "main",
connect_sides = {left = 1, right = 1, back = 1, bottom = 1, top = 1}
}
})
minetest.register_craft({
output = "vacuum:airpump",
recipe = {
{"default:steel_ingot", "default:mese_block", "default:steel_ingot"},
{"default:diamond", "default:glass", "default:steel_ingot"},
{"default:steel_ingot", "default:steelblock", "default:steel_ingot"},
},
})