forked from mtcontrib/hangglider
[WIP] cleanup, remove old 0.4 code (#6)
This commit is contained in:
parent
cd67eb2d19
commit
3c2618437a
@ -9,7 +9,5 @@ read_globals = {
|
|||||||
"vector", "ItemStack",
|
"vector", "ItemStack",
|
||||||
|
|
||||||
-- Mod deps
|
-- Mod deps
|
||||||
"wardzones",
|
|
||||||
"minetestd",
|
|
||||||
"player_monoids"
|
"player_monoids"
|
||||||
}
|
}
|
||||||
|
90
init.lua
90
init.lua
@ -55,54 +55,18 @@
|
|||||||
|
|
||||||
local HUD_Overlay = true -- show glider struts as overlay on HUD
|
local HUD_Overlay = true -- show glider struts as overlay on HUD
|
||||||
local debug = false -- show debug info in top-center of hud
|
local debug = false -- show debug info in top-center of hud
|
||||||
local moveModelUp = false
|
|
||||||
if tonumber(string.sub(minetest.get_version().string, 1, 1)) and
|
|
||||||
tonumber(string.sub(minetest.get_version().string, 1, 1)) > 4 then
|
|
||||||
moveModelUp = true
|
|
||||||
end
|
|
||||||
hangglider = {} -- Make this global, so other mods can tell if hangglider exists.
|
hangglider = {} -- Make this global, so other mods can tell if hangglider exists.
|
||||||
hangglider.use = {}
|
hangglider.use = {}
|
||||||
|
|
||||||
if HUD_Overlay then
|
if HUD_Overlay then
|
||||||
hangglider.id = {} -- hud id for displaying overlay with struts
|
hangglider.id = {} -- hud id for displaying overlay with struts
|
||||||
end
|
end
|
||||||
if debug then hangglider.debug = {} end -- hud id for debug data
|
|
||||||
--hangglider.airbreak = {} -- true if falling fast when equip
|
|
||||||
--[[
|
|
||||||
minetest.register_entity("hangglider:airstopper", { --A one-instant entity that catches the player and stops them.
|
|
||||||
is_visible = false,
|
|
||||||
physical = false,
|
|
||||||
immortal = true,
|
|
||||||
attach = nil,
|
|
||||||
on_step = function(self, _)
|
|
||||||
local canExist = false
|
|
||||||
if self.attach then
|
|
||||||
local player = self.attach
|
|
||||||
if player:is_player() then
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
canExist = true
|
|
||||||
if player:get_player_velocity().y < 0.5 and player:get_player_velocity().y > -0.5 then
|
|
||||||
--Let go when the player actually stops, as that's the whole point.
|
|
||||||
if hangglider.use[pname] then
|
|
||||||
if moveModelUp then
|
|
||||||
minetest.add_entity(player:get_pos(), "hangglider:glider"):set_attach(player, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
|
||||||
else
|
|
||||||
minetest.add_entity(player:get_pos(), "hangglider:glider"):set_attach(player, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
canExist = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not canExist then
|
|
||||||
player:set_detach()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not canExist then
|
|
||||||
self.object:remove()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})]]
|
|
||||||
|
|
||||||
if minetest.global_exists("areas") then
|
if debug then -- hud id for debug data
|
||||||
|
hangglider.debug = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
if minetest.get_modpath("areas") then
|
||||||
hangglider.flak = true
|
hangglider.flak = true
|
||||||
-- chat command definition essentially copied from areas mod.
|
-- chat command definition essentially copied from areas mod.
|
||||||
minetest.register_chatcommand("area_flak",{
|
minetest.register_chatcommand("area_flak",{
|
||||||
@ -115,8 +79,7 @@ if minetest.global_exists("areas") then
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not areas:isAreaOwner(id, name) then
|
if not areas:isAreaOwner(id, name) then
|
||||||
return false, "Area "..id.." does not exist"
|
return false, "Area "..id.." does not exist or is not owned by you."
|
||||||
.." or is not owned by you."
|
|
||||||
end
|
end
|
||||||
local open = not areas.areas[id].flak
|
local open = not areas.areas[id].flak
|
||||||
-- Save false as nil to avoid inflating the DB.
|
-- Save false as nil to avoid inflating the DB.
|
||||||
@ -150,12 +113,14 @@ hangglider.shot_sound = function (pos)
|
|||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 30,
|
max_hear_distance = 30,
|
||||||
gain = 10.0,
|
gain = 10.0,
|
||||||
})
|
}, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local has_player_monoids = minetest.get_modpath("player_monoids")
|
||||||
|
|
||||||
local physics_attrs = {"jump", "speed", "gravity"}
|
local physics_attrs = {"jump", "speed", "gravity"}
|
||||||
local function apply_physics_override(player, overrides)
|
local function apply_physics_override(player, overrides)
|
||||||
if minetest.get_modpath("player_monoids") then
|
if has_player_monoids then
|
||||||
for _, attr in pairs(physics_attrs) do
|
for _, attr in pairs(physics_attrs) do
|
||||||
if overrides[attr] then
|
if overrides[attr] then
|
||||||
player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
|
player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
|
||||||
@ -169,7 +134,7 @@ end
|
|||||||
local function remove_physics_override(player, overrides)
|
local function remove_physics_override(player, overrides)
|
||||||
for _, attr in pairs(physics_attrs) do
|
for _, attr in pairs(physics_attrs) do
|
||||||
if overrides[attr] then
|
if overrides[attr] then
|
||||||
if minetest.global_exists("player_monoids") then
|
if has_player_monoids then
|
||||||
player_monoids[attr]:del_change(player, "hangglider:glider")
|
player_monoids[attr]:del_change(player, "hangglider:glider")
|
||||||
else
|
else
|
||||||
player:set_physics_override({[attr] = 1})
|
player:set_physics_override({[attr] = 1})
|
||||||
@ -199,7 +164,6 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
if mrn_name then
|
if mrn_name then
|
||||||
if not (mrn_name.walkable or mrn_name.liquidtype ~= "none") then
|
if not (mrn_name.walkable or mrn_name.liquidtype ~= "none") then
|
||||||
canExist = true
|
canExist = true
|
||||||
|
|
||||||
step_v = player:get_velocity().y
|
step_v = player:get_velocity().y
|
||||||
if step_v < 0 and step_v > -3 then
|
if step_v < 0 and step_v > -3 then
|
||||||
apply_physics_override(player, {speed = math.abs(step_v/2) + 0.75})
|
apply_physics_override(player, {speed = math.abs(step_v/2) + 0.75})
|
||||||
@ -231,13 +195,11 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not canExist then
|
if not canExist then
|
||||||
|
remove_physics_override(player, {gravity = 1, jump = 1, speed = 1})
|
||||||
remove_physics_override(player, { gravity=1, jump = 1, speed = 1,})
|
|
||||||
hangglider.use[pname] = false
|
hangglider.use[pname] = false
|
||||||
if HUD_Overlay then
|
if HUD_Overlay then
|
||||||
player:hud_change(hangglider.id[pname], "text", "blank.png")
|
player:hud_change(hangglider.id[pname], "text", "blank.png")
|
||||||
end
|
end
|
||||||
--hangglider.airbreak[pname] = false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -256,7 +218,6 @@ minetest.register_on_dieplayer(function(player)
|
|||||||
hangglider.use[player:get_player_name()] = false
|
hangglider.use[player:get_player_name()] = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
remove_physics_override(player, {
|
remove_physics_override(player, {
|
||||||
@ -283,7 +244,6 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
-- ht = {50,50,50},
|
-- ht = {50,50,50},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
--hangglider.airbreak[pname] = false
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
@ -291,7 +251,6 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
hangglider.use[pname] = nil
|
hangglider.use[pname] = nil
|
||||||
if HUD_Overlay then hangglider.id[pname] = nil end
|
if HUD_Overlay then hangglider.id[pname] = nil end
|
||||||
if debug then hangglider.debug[pname] = nil end
|
if debug then hangglider.debug[pname] = nil end
|
||||||
--hangglider.airbreak[pname] = nil
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_tool("hangglider:hangglider", {
|
minetest.register_tool("hangglider:hangglider", {
|
||||||
@ -306,32 +265,11 @@ minetest.register_tool("hangglider:hangglider", {
|
|||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if not hangglider.use[pname] then -- Equip
|
if not hangglider.use[pname] then -- Equip
|
||||||
minetest.sound_play("bedsheet", {pos=pos, max_hear_distance = 8, gain = 1.0})
|
minetest.sound_play("bedsheet", {pos = pos, max_hear_distance = 8, gain = 1.0}, true)
|
||||||
if HUD_Overlay then player:hud_change(hangglider.id[pname], "text", "glider_struts.png") end
|
if HUD_Overlay then player:hud_change(hangglider.id[pname], "text", "glider_struts.png") end
|
||||||
local airbreak = false
|
|
||||||
--[[if vel < -1.5 then -- engage mid-air, falling fast, so stop but ramp velocity more quickly
|
|
||||||
--hangglider.airbreak[pname] = true
|
|
||||||
airbreak = true
|
|
||||||
local stopper = minetest.add_entity(pos, "hangglider:airstopper")
|
|
||||||
minetest.after(0, function(stopper, player) --"Extreme Measures"
|
|
||||||
stopper:set_pos(player:get_pos())
|
|
||||||
stopper:get_luaentity().attach = player
|
|
||||||
player:set_attach( stopper, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
|
||||||
end, stopper, player)
|
|
||||||
end]]
|
|
||||||
if not airbreak then
|
|
||||||
if moveModelUp then
|
|
||||||
minetest.add_entity(pos, "hangglider:glider"):set_attach(player, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
minetest.add_entity(pos, "hangglider:glider"):set_attach(player, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
||||||
else
|
|
||||||
minetest.add_entity(pos, "hangglider:glider"):set_attach(player, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
hangglider.use[pname] = true
|
hangglider.use[pname] = true
|
||||||
apply_physics_override(player, {jump = 0})
|
apply_physics_override(player, {jump = 0})
|
||||||
-- if minetest 0.4.x use this:
|
|
||||||
|
|
||||||
-- if minetest 5.x use this:
|
|
||||||
-- minetest.add_entity(player:get_pos(), "hangglider:glider"):set_attach(player, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
|
||||||
itemstack:set_wear(itemstack:get_wear() + 255)
|
itemstack:set_wear(itemstack:get_wear() + 255)
|
||||||
return itemstack
|
return itemstack
|
||||||
elseif hangglider.use[pname] then -- Unequip
|
elseif hangglider.use[pname] then -- Unequip
|
||||||
|
Loading…
Reference in New Issue
Block a user