-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
215 lines (186 loc) · 7.96 KB
/
init.lua
File metadata and controls
215 lines (186 loc) · 7.96 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
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
--[[
Flying Saucer vehicle ('flying_saucer') mod for Minetest
Copyright (C) 2018 Pilcrow182
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
]]--
flying_saucer = {}
flying_saucer.delay = tonumber(minetest.settings:get("flying_saucer_delay") or 0.25)
minetest.settings:set("flying_saucer_delay", flying_saucer.delay)
flying_saucer.speed = tonumber(minetest.settings:get("flying_saucer_speed") or 10)
minetest.settings:set("flying_saucer_speed", flying_saucer.speed)
flying_saucer.bubble_diameter = tonumber(minetest.settings:get("flying_saucer_bubble_diameter") or 9)
minetest.settings:set("flying_saucer_bubble_diameter", flying_saucer.bubble_diameter)
flying_saucer.passive_stop = minetest.settings:get_bool("flying_saucer_passive_stop", false)
minetest.settings:set_bool("flying_saucer_passive_stop", flying_saucer.passive_stop)
flying_saucer.smooth_stop = minetest.settings:get_bool("flying_saucer_smooth_stop", true)
minetest.settings:set_bool("flying_saucer_smooth_stop", flying_saucer.smooth_stop)
flying_saucer.storage = {}
local DEBUG = false
local debug_msg = function(message)
if DEBUG then
minetest.chat_send_all(message)
minetest.log("action", message)
end
end
local bubble_tiles = (DEBUG and {"flying_saucer_bubble.png"}) or nil
local bubble_drawtype = (DEBUG and "allfaces_optional") or "airlike"
minetest.register_node("flying_saucer:bubble", {
description = "Climbable Air",
inventory_image = "flying_saucer_bubble.png",
wield_image = "flying_saucer_bubble.png",
tiles = bubble_tiles,
drawtype = bubble_drawtype,
paramtype = "light",
sunlight_propagates = true,
walkable = false,
climbable = true,
pointable = false,
diggable = false,
buildable_to = true,
floodable = true,
air_equivalent = true,
drop = "",
groups = {not_in_creative_inventory=1},
})
local activate_flying_saucer = function(player, name)
minetest.chat_send_player(name, "Saucer mode enabled")
flying_saucer.storage[name] = {}
flying_saucer.storage[name].physics = player:get_physics_override()
flying_saucer.storage[name].properties = player:get_properties()
player:set_physics_override({speed = flying_saucer.speed/4, jump = 0, gravity = 0, sneak = false, sneak_glitch = false})
player:set_properties({
visual_size = {x = 1, y = 1},
visual = "mesh",
mesh = "flying_saucer.x",
textures = {"flying_saucer.png"},
collisionbox = {-1.49, 0.00, -1.49, 1.49, 1.98, 1.49},
})
if pp and pp.disable then pp.disable[name] = true end
end
local deactivate_flying_saucer = function(player, name)
minetest.chat_send_player(name, "Saucer mode disabled")
player:set_physics_override(flying_saucer.storage[name].physics)
player:set_properties(flying_saucer.storage[name].properties)
flying_saucer.storage[name] = nil
if pp and pp.disable then pp.disable[name] = nil end
end
local stopping_player = ""
minetest.register_entity("flying_saucer:stopper_entity", {
textures = {"flying_saucer_stopper.png"},
collisionbox = {0,0,0,0,0,0},
is_visible = true,
makes_footstep_sound = false,
on_activate = function(self, staticdata)
local player = minetest.get_player_by_name(stopping_player)
if not player then return end
player:set_attach(self.object, "", {x=0,y=0,z=0}, {x=0,y=-player:get_look_horizontal()*180/math.pi,z=0})
minetest.after(flying_saucer.delay, function(obj) obj:remove() end, self.object)
end,
})
local bubble = {size = {x = flying_saucer.bubble_diameter, y = flying_saucer.bubble_diameter, z = flying_saucer.bubble_diameter}, data = {}}
for x = 1, bubble.size.x do
for y = 1, bubble.size.y do
for z = 1, bubble.size.z do
table.insert(bubble.data, { name = "flying_saucer:bubble" })
end
end
end
local place_bubble = function(schempos, delay)
debug_msg("placing bubble at "..minetest.pos_to_string(schempos).." (to be removed after "..delay.." seconds)")
minetest.place_schematic(schempos, bubble, 0, nil, false)
for xoff = 0, bubble.size.x-1 do
for yoff = 0, bubble.size.y-1 do
for zoff = 0, bubble.size.z-1 do
minetest.after(delay*2, function(schempos, xoff, yoff, zoff)
local nodepos = {x = schempos.x + xoff, y = schempos.y + yoff, z = schempos.z + zoff}
local node = minetest.get_node(nodepos)
if node and node.name and node.name == "flying_saucer:bubble" then minetest.remove_node(nodepos) end
end, schempos, xoff, yoff, zoff)
end
end
end
end
local timer = 0
minetest.register_globalstep(function(dtime)
local delay = flying_saucer.delay
timer = timer + dtime
if timer >= delay then
timer = 0
for name,_ in pairs(flying_saucer.storage) do
local player = minetest.get_player_by_name(name)
if player then
local pos = player:get_pos()
local ctrl = player:get_player_control()
local velocity = player:get_player_velocity()
local schempos = {x = math.floor(pos.x-(bubble.size.x-1)/2+0.5), y = math.floor(pos.y-(bubble.size.y-1)/2+0.5), z = math.floor(pos.z-(bubble.size.z-1)/2+0.5)}
local state = flying_saucer.storage[name].state or "idle"
if math.abs(velocity.y) > flying_saucer.speed*0.75 then state = "stopping"
elseif ctrl.aux1 or (ctrl.sneak and ctrl.jump) then state = "stopping"
elseif (velocity.y == 0 or flying_saucer.passive_stop) and not (ctrl.jump or ctrl.sneak) then state = "idle"
elseif (velocity.y < 0 and ctrl.jump) or (velocity.y > 0 and ctrl.sneak) then state = "idle"
elseif ctrl.jump then state = "ascending"
elseif ctrl.sneak then state = "descending"
end
debug_msg("player '"..name.."' is "..state..", velocity="..minetest.pos_to_string(velocity)..")...")
if (state == "stopping" or (state == "idle" and not flying_saucer.smooth_stop)) and velocity.y ~= 0 then
stopping_player = name
minetest.add_entity(pos, "flying_saucer:stopper_entity")
elseif state == "idle" and velocity.y ~= 0 then
place_bubble(schempos, delay)
elseif state == "ascending" and velocity.y < flying_saucer.speed*0.75 then
place_bubble(schempos, delay)
elseif state == "descending" and velocity.y > -flying_saucer.speed*0.75 then
place_bubble(schempos, delay)
end
flying_saucer.storage[name].state = state
end
end
end
end)
minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
if flying_saucer.storage[name] and flying_saucer.storage[name].physics then
deactivate_flying_saucer(player, name)
end
end)
minetest.register_craftitem("flying_saucer:saucer", {
description = "Flying saucer",
inventory_image = "flying_saucer_saucer.png",
wield_image = "flying_saucer_saucer.png",
wield_scale = {x=1, y=1, z=1},
liquids_pointable = false,
on_use = function(itemstack, user, pointed_thing)
local username = user:get_player_name()
if flying_saucer.storage[username] then
deactivate_flying_saucer(user, username)
else
activate_flying_saucer(user, username)
end
end
})
minetest.register_craft({
output = "flying_saucer:saucer",
recipe = {
{"", "default:diamondblock", ""},
{"default:copperblock", "default:steelblock","default:copperblock"},
}
})
minetest.register_abm{
label = "bubble cleanup",
nodenames = {"flying_saucer:bubble"},
interval = 5,
chance = 1,
action = function(pos)
minetest.remove_node(pos)
end
}
dofile(minetest.get_modpath(minetest.get_current_modname()).."/compat.lua")