This repository was archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
85 lines (70 loc) · 1.84 KB
/
api.lua
File metadata and controls
85 lines (70 loc) · 1.84 KB
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
mtfs = {}
local planes = {}
local function verify_def(def)
def.size = def.size or 1
def.attachment_offset = def.attachment_offset or {x = 0, y = 0, z = 0}
return def
end
local function on_step(self, dtime)
end
local function on_lclick(self, puncher)
if not puncher then
return
end
puncher:set_detach()
puncher:get_inventory():add_item("main", self.name)
self.object:remove()
end
local function on_rclick(self, clicker)
local def = planes[self.name]
if not clicker:get_attach() then
clicker:set_attach(self.object, "", def.attachment_offset, {x = 0, y = 0, z = 0})
clicker:set_properties({
visual_size = {
x = 1 / def.size,
y = 1 / def.size,
z = 1 / def.size
}
})
else
clicker:set_detach()
clicker:set_properties({ visual_size = {x = 1, y = 1, z = 1} })
end
end
function mtfs.register_aircraft(name, def)
assert(not planes[name], "Attempting to register plane with an existing name!")
def = verify_def(def)
minetest.register_entity("name", {
initial_properties = {
physical = true,
visual = "mesh",
mesh = def.mesh,
textures = def.textures,
visual_size = {x = def.size, y = def.size}
},
on_step = on_step,
on_punch = on_lclick,
on_rightclick = on_rclick,
})
planes[name] = def
end
minetest.register_chatcommand("plane", {
params = "<plane>",
description = "Spawn a plane",
privs = {interact = true},
func = function(name, param)
local player = minetest.get_player_by_name(name)
if not player then
return false, "You should be online to spawn planes!"
end
if not param or param:trim() == "" then
return false, "Provide a valid aircraft name!"
end
param = param:trim()
if not planes[param] then
return false, "Provide a valid aircraft name!"
end
local pos = vector.add(player:get_pos(), {x = 0, y = 1, z = 0})
minetest.add_entity(pos, param)
end
})