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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
local phash = elevator.phash
local get_node = elevator.get_node
local homedecor_path = minetest.get_modpath("homedecor")
local mineclone_path = core.get_modpath("mcl_core") and mcl_core
local default_path = core.get_modpath("default") and default
local aurum_path = core.get_modpath("aurum") and aurum
local moditems = {} -- local table to hold substitutes
-- Use homedecor's placeholder if possible.
if homedecor_path then
minetest.register_alias("elevator:placeholder", "homedecor:expansion_placeholder")
else
-- Placeholder node, in the style of homedecor.
minetest.register_node("elevator:placeholder", {
description = "Expansion Placeholder",
selection_box = {
type = "fixed",
fixed = {0, 0, 0, 0, 0, 0},
},
groups = {
not_in_creative_inventory=1
},
drawtype = "airlike",
paramtype = "light",
sunlight_propagates = true,
walkable = false,
buildable_to = false,
is_ground_content = false,
on_dig = function(pos, node, player)
minetest.remove_node(pos)
minetest.set_node(pos, {name="elevator:placeholder"})
end
})
end
if mineclone_path then
moditems.el_shaft_groups = {pickaxey=1,axey=1,handy=1,swordy=1,transport=1,dig_by_piston=1}
moditems.el_motor_groups = {pickaxey=1,axey=1,handy=1,swordy=1,transport=1,dig_by_piston=1}
moditems.elevator_groups = {pickaxey=1,axey=1,handy=1,swordy=1,transport=1,dig_by_piston=1}
moditems.elevator_special_groups = {not_in_creative_inventory=1,pickaxey=1,axey=1,handy=1,swordy=1,transport=1,dig_by_piston=1}
moditems.sounds_stone = mcl_sounds.node_sound_stone_defaults
moditems.el_motor_gfx = "elevator_motor_mcl.png"
moditems.el_shaft_gfx = "elevator_shaft_mcl.png"
moditems.el_box_gfx = "elevator_box_mcl.png"
moditems.steel_block_image = "default_steel_block.png"
elseif default_path then
moditems.el_shaft_groups = {cracky=2,oddly_breakable_by_hand=0} -- removing ability to destroy by hand to prevent accidental breakage of whole elevators
moditems.el_motor_groups = {cracky=1}
moditems.elevator_groups = {cracky=1,choppy=1,snappy=1}
moditems.elevator_special_groups = {not_in_creative_inventory=1}
moditems.sounds_stone = default.node_sound_stone_defaults
moditems.el_motor_gfx = "elevator_motor.png"
moditems.el_shaft_gfx = "elevator_shaft.png"
moditems.el_box_gfx = "elevator_box.png"
moditems.steel_block_image = "default_steel_block.png"
elseif aurum_path then
moditems.el_shaft_groups = {dig_pick = 2}
moditems.el_motor_groups = {dig_pick = 1}
moditems.elevator_groups = {dig_pick = 1}
moditems.elevator_special_groups = {not_in_creative_inventory=1}
moditems.sounds_stone = aurum.sounds.stone
moditems.el_motor_gfx = "elevator_motor.png"
moditems.el_shaft_gfx = "elevator_shaft.png"
moditems.el_box_gfx = "elevator_box.png"
moditems.steel_block_image = "aurum_ore_white.png^[colorize:#cbcdcd:255^aurum_ore_bumps.png^aurum_ore_block.png"
end
if minetest.global_exists("screwdriver") then
moditems.on_rotate_disallow = screwdriver.disallow
end
minetest.register_node("elevator:shaft", {
description = "Elevator Shaft",
tiles = { moditems.el_shaft_gfx },
drawtype = "nodebox",
paramtype = "light",
on_rotate = moditems.on_rotate_disallow,
sunlight_propagates = true,
groups = moditems.el_shaft_groups,
sounds = moditems.sounds_stone(),
climbable = true,
node_box = {
type = "fixed",
fixed = {
{-8/16,-8/16,-8/16,-7/16,8/16,8/16},
{7/16,-8/16,-8/16,8/16,8/16,8/16},
{-7/16,-8/16,-8/16,7/16,8/16,-7/16},
{-7/16,-8/16,8/16,7/16,8/16,7/16},
},
},
collisionbox = {
type = "fixed",
fixed = {
{-8/16,-8/16,-8/16,-7/16,8/16,8/16},
{7/16,-8/16,-8/16,8/16,8/16,8/16},
{-7/16,-8/16,-8/16,7/16,8/16,-7/16},
{-7/16,-8/16,8/16,7/16,8/16,7/16},
},
},
after_place_node = function(pos)
-- We might have connected a motor above to an elevator below.
elevator.build_motor(elevator.locate_motor(pos))
end,
on_destruct = function(pos)
-- Remove boxes and deactivate elevators below us.
elevator.unbuild(pos, 1)
end,
_mcl_blast_resistance = 15, -- mineclone2 specific
_mcl_hardness = 5, -- mineclone2 specific
})
minetest.register_node("elevator:motor", {
description = "Elevator Motor",
tiles = {
moditems.steel_block_image,
moditems.steel_block_image,
moditems.el_motor_gfx,
moditems.el_motor_gfx,
moditems.el_motor_gfx,
moditems.el_motor_gfx,
},
groups = moditems.el_motor_groups,
sounds = moditems.sounds_stone(),
after_place_node = function(pos, placer, itemstack)
-- Set up the motor table.
elevator.motors[phash(pos)] = {
elevators = {},
pnames = {},
labels = {},
}
elevator.save_elevator()
elevator.build_motor(phash(pos))
end,
on_destruct = function(pos)
-- Destroy everything related to this motor.
elevator.boxes[phash(pos)] = nil
elevator.motors[phash(pos)] = nil
elevator.save_elevator()
end,
_mcl_blast_resistance = 15, -- mineclone2 specific
_mcl_hardness = 5, -- mineclone2 specific
})
-- Box of the active entitity.
local box_box = {
{ 0.48, -0.5,-0.5, 0.5, 1.5, 0.5},
{-0.5 , -0.5, 0.48, 0.48, 1.5, 0.5},
{-0.5, -0.5,-0.5 ,-0.48, 1.5, 0.5},
{-0.5 , -0.5, -0.48, 0.5, 1.5, -0.5},
{ -0.5,-0.5,-0.5,0.5,-0.48, 0.5},
{ -0.5, 1.45,-0.5,0.5, 1.5, 0.5},
}
-- Elevator box node. Not intended to be placeable.
minetest.register_node("elevator:elevator_box", {
description = "Elevator",
drawtype = "nodebox",
paramtype = 'light',
paramtype2 = "facedir",
wield_scale = {x=0.6, y=0.6, z=0.6},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 }
},
collision_box = {
type = "fixed",
fixed = box_box,
},
node_box = {
type = "fixed",
fixed = box_box,
},
tiles = {
moditems.steel_block_image,
moditems.steel_block_image,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
},
groups = moditems.elevator_special_groups,
light_source = 4,
_mcl_blast_resistance = 15, -- mineclone2 specific
_mcl_hardness = 5, -- mineclone2 specific
})
for _,mode in ipairs({"on", "off"}) do
local nodename = "elevator:elevator_"..mode
local on = (mode == "on")
local box
local cbox
if on then
-- Active elevators have a ceiling and floor.
box = {
{ 0.48, -0.5,-0.5, 0.5, 1.5, 0.5},
{-0.5 , -0.5, 0.48, 0.48, 1.5, 0.5},
{-0.5, -0.5,-0.5 ,-0.48, 1.5, 0.5},
{ -0.5,-0.5,-0.5,0.5,-0.48, 0.5},
{ -0.5, 1.45,-0.5,0.5, 1.5, 0.5},
}
cbox = table.copy(box)
-- But you can enter them from the top.
cbox[5] = nil
else
-- Inactive elevators are almost like shafts.
box = {
{ 0.48, -0.5,-0.5, 0.5, 1.5, 0.5},
{-0.5 , -0.5, 0.48, 0.48, 1.5, 0.5},
{-0.5, -0.5,-0.5 ,-0.48, 1.5, 0.5},
{-0.5 , -0.5, -0.48, 0.5, 1.5, -0.5},
}
cbox = box
end
minetest.register_node(nodename, {
description = "Elevator",
drawtype = "nodebox",
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
on_rotate = moditems.on_rotate_disallow,
climbable = true,
selection_box = {
type = "fixed",
fixed = box,
},
collision_box = {
type = "fixed",
fixed = cbox,
},
node_box = {
type = "fixed",
fixed = box,
},
tiles = on and {
moditems.steel_block_image,
moditems.steel_block_image,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
} or {
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
moditems.el_box_gfx,
},
groups = moditems.elevator_groups,
drop = "elevator:elevator_off",
-- Emit a bit of light when active.
light_source = (on and 4 or nil),
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_int("version", elevator.VERSION)
-- Add a placeholder to avoid nodes being placed in the top.
local p = vector.add(pos, {x=0, y=1, z=0})
local p2 = minetest.dir_to_facedir(placer:get_look_dir())
minetest.set_node(p, {name="elevator:placeholder", paramtype2="facedir", param2=p2})
-- Try to build a motor above.
local motor = elevator.locate_motor(pos)
if motor then
elevator.build_motor(motor)
end
end,
after_dig_node = function(pos, node, meta, digger)
elevator.unbuild(pos, 2)
end,
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local node = minetest.get_node(vector.add(pos, {x=0, y=1, z=0}))
if (node ~= nil and node.name ~= "air" and node.name ~= "elevator:placeholder") then
return
end
return minetest.item_place(itemstack, placer, pointed_thing)
end,
on_rightclick = function(pos, node, sender, itemstack, pointed_thing)
if not sender or not sender:is_player() then
return
end
-- When the player is holding elevator components, just place them instead of opening the formspec.
if ({
["elevator:elevator_off"] = true,
["elevator:shaft"] = true,
["elevator:motor"] = true,
})[sender:get_wielded_item():get_name()] then
return core.item_place_node(itemstack, sender, pointed_thing)
end
local formspec
local meta = minetest.get_meta(pos)
elevator.formspecs[sender:get_player_name()] = {pos}
local motorhash = meta:get_string("motor")
if on and elevator.motors[motorhash] then
if vector.distance(sender:get_pos(), pos) > 1 or minetest.get_node(sender:get_pos()).name ~= nodename then
minetest.chat_send_player(sender:get_player_name(), "You are not inside the booth.")
return
end
-- Build the formspec from the motor table.
local tpnames = {}
local tpnames_l = {}
local motor = elevator.motors[motorhash]
for ji,jv in ipairs(motor.pnames) do
if tonumber(jv) ~= pos.y then
table.insert(tpnames, jv)
table.insert(tpnames_l, (motor.labels[ji] and motor.labels[ji] ~= "") and (jv.." - "..minetest.formspec_escape(motor.labels[ji])) or jv)
end
end
elevator.formspecs[sender:get_player_name()] = {pos, tpnames}
if #tpnames > 0 then
if not minetest.is_protected(pos, sender:get_player_name()) then
formspec = "size[4,6]"
.."label[0,0;Click once to travel.]"
.."textlist[-0.1,0.5;4,4;target;"..table.concat(tpnames_l, ",").."]"
.."field[0.25,5.25;4,0;label;;"..minetest.formspec_escape(meta:get_string("label")).."]"
.."button_exit[-0.05,5.5;4,1;setlabel;Set label]"
else
formspec = "size[4,4.4]"
.."label[0,0;Click once to travel.]"
.."textlist[-0.1,0.5;4,4;target;"..table.concat(tpnames_l, ",").."]"
end
else
if not minetest.is_protected(pos, sender:get_player_name()) then
formspec = "size[4,2]"
.."label[0,0;No targets available.]"
.."field[0.25,1.25;4,0;label;;"..minetest.formspec_escape(meta:get_string("label")).."]"
.."button_exit[-0.05,1.5;4,1;setlabel;Set label]"
else
formspec = "size[4,0.4]"
.."label[0,0;No targets available.]"
end
end
minetest.show_formspec(sender:get_player_name(), "elevator:elevator", formspec)
elseif not elevator.motors[motorhash] then
if not minetest.is_protected(pos, sender:get_player_name()) then
formspec = "size[4,2]"
.."label[0,0;This elevator is inactive.]"
.."field[0.25,1.25;4,0;label;;"..minetest.formspec_escape(meta:get_string("label")).."]"
.."button_exit[-0.05,1.5;4,1;setlabel;Set label]"
else
formspec = "size[4,0.4]"
.."label[0,0;This elevator is inactive.]"
end
minetest.show_formspec(sender:get_player_name(), "elevator:elevator", formspec)
elseif elevator.boxes[motorhash] then
if not minetest.is_protected(pos, sender:get_player_name()) then
formspec = "size[4,2]"
.."label[0,0;This elevator is in use.]"
.."field[0.25,1.25;4,0;label;;"..minetest.formspec_escape(meta:get_string("label")).."]"
.."button_exit[-0.05,1.5;4,1;setlabel;Set label]"
else
formspec = "size[4,0.4]"
.."label[0,0;This elevator is in use.]"
end
minetest.show_formspec(sender:get_player_name(), "elevator:elevator", formspec)
end
end,
on_destruct = function(pos)
local p = vector.add(pos, {x=0, y=1, z=0})
if get_node(p).name == "elevator:placeholder" then
minetest.remove_node(p)
end
end,
_mcl_blast_resistance = 15, -- mineclone2 specific
_mcl_hardness = 5, -- mineclone2 specific
})
end
-- Compatability with an older version.
minetest.register_alias("elevator:elevator", "elevator:elevator_off")
|