[WIP] cleanup, remove old 0.4 code (#6)

This commit is contained in:
Niklp 2023-01-06 21:50:44 +01:00 committed by GitHub
parent cd67eb2d19
commit 3c2618437a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 105 deletions

View File

@ -9,7 +9,5 @@ read_globals = {
"vector", "ItemStack",
-- Mod deps
"wardzones",
"minetestd",
"player_monoids"
}

View File

@ -55,54 +55,18 @@
local HUD_Overlay = true -- show glider struts as overlay on 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.use = {}
if HUD_Overlay then
hangglider.id = {} -- hud id for displaying overlay with struts
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
-- chat command definition essentially copied from areas mod.
minetest.register_chatcommand("area_flak",{
@ -115,8 +79,7 @@ if minetest.global_exists("areas") then
end
if not areas:isAreaOwner(id, name) then
return false, "Area "..id.." does not exist"
.." or is not owned by you."
return false, "Area "..id.." does not exist or is not owned by you."
end
local open = not areas.areas[id].flak
-- Save false as nil to avoid inflating the DB.
@ -150,12 +113,14 @@ hangglider.shot_sound = function (pos)
pos = pos,
max_hear_distance = 30,
gain = 10.0,
})
}, true)
end
local has_player_monoids = minetest.get_modpath("player_monoids")
local physics_attrs = {"jump", "speed", "gravity"}
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
if overrides[attr] then
player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
@ -169,7 +134,7 @@ end
local function remove_physics_override(player, overrides)
for _, attr in pairs(physics_attrs) do
if overrides[attr] then
if minetest.global_exists("player_monoids") then
if has_player_monoids then
player_monoids[attr]:del_change(player, "hangglider:glider")
else
player:set_physics_override({[attr] = 1})
@ -199,7 +164,6 @@ minetest.register_entity("hangglider:glider", {
if mrn_name then
if not (mrn_name.walkable or mrn_name.liquidtype ~= "none") then
canExist = true
step_v = player:get_velocity().y
if step_v < 0 and step_v > -3 then
apply_physics_override(player, {speed = math.abs(step_v/2) + 0.75})
@ -231,13 +195,11 @@ minetest.register_entity("hangglider:glider", {
end
end
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
if HUD_Overlay then
player:hud_change(hangglider.id[pname], "text", "blank.png")
end
--hangglider.airbreak[pname] = false
end
end
end
@ -256,7 +218,6 @@ minetest.register_on_dieplayer(function(player)
hangglider.use[player:get_player_name()] = false
end)
minetest.register_on_joinplayer(function(player)
local pname = player:get_player_name()
remove_physics_override(player, {
@ -283,7 +244,6 @@ minetest.register_on_joinplayer(function(player)
-- ht = {50,50,50},
}
end
--hangglider.airbreak[pname] = false
end)
minetest.register_on_leaveplayer(function(player)
@ -291,7 +251,6 @@ minetest.register_on_leaveplayer(function(player)
hangglider.use[pname] = nil
if HUD_Overlay then hangglider.id[pname] = nil end
if debug then hangglider.debug[pname] = nil end
--hangglider.airbreak[pname] = nil
end)
minetest.register_tool("hangglider:hangglider", {
@ -306,32 +265,11 @@ minetest.register_tool("hangglider:hangglider", {
local pos = player:get_pos()
local pname = player:get_player_name()
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
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})
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
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)
return itemstack
elseif hangglider.use[pname] then -- Unequip