Cleanup
~ Code Cleanup ~ Move ladder node above/below check to inside ladder checkmaster
parent
586d4501c0
commit
98dbe16550
|
@ -1,6 +1,13 @@
|
||||||
-------------------------------------------
|
------------------------------------------------------------
|
||||||
-- Example Cape --
|
-- ___ _ __ ___ _ --
|
||||||
-------------------------------------------
|
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
|
||||||
|
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
|
||||||
|
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
|
||||||
|
-- |__/ --
|
||||||
|
-- Crouch and Climb --
|
||||||
|
------------------------------------------------------------
|
||||||
|
-- Example Cape --
|
||||||
|
------------------------------------------------------------
|
||||||
armor:register_armor("3d_armor_flyswim:demo_cape", {
|
armor:register_armor("3d_armor_flyswim:demo_cape", {
|
||||||
description = "Someones Cape",
|
description = "Someones Cape",
|
||||||
inventory_image = "3d_armor_flyswim_demo_cape_inv.png",
|
inventory_image = "3d_armor_flyswim_demo_cape_inv.png",
|
||||||
|
|
173
i_functions.lua
173
i_functions.lua
|
@ -1,94 +1,100 @@
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
-- ___________ __ .__ --
|
-- ___ _ __ ___ _ --
|
||||||
-- \_ _____/_ __ ____ _____/ |_|__| ____ ____ ______ --
|
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
|
||||||
-- | __)| | \/ \_/ ___\ __\ |/ _ \ / \ / ___/ --
|
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
|
||||||
-- | \ | | / | \ \___| | | ( <_> ) | \\___ \ --
|
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
|
||||||
-- \___ / |____/|___| /\___ >__| |__|\____/|___| /____ > --
|
-- |__/ --
|
||||||
-- \/ \/ \/ \/ \/ --
|
-- Crouch and Climb --
|
||||||
------------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
-- Functions --
|
||||||
|
------------------------------------------------------------
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- Get Player model and textures
|
-- Get Player model and textures
|
||||||
|
|
||||||
function armor_fly_swim.get_player_model()
|
function armor_fly_swim.get_player_model()
|
||||||
|
|
||||||
local player_mod = "character_sf.b3d" -- Swim, Fly
|
-- player_api only (simple_skins uses)
|
||||||
local texture = {"character.png",
|
local player_mod = "character_sf.b3d"
|
||||||
|
local texture = {"character.png",
|
||||||
"3d_armor_trans.png"}
|
"3d_armor_trans.png"}
|
||||||
|
|
||||||
if armor_fly_swim.is_3d_armor and
|
-- 3d_armor only nil capes (simple_skins uses)
|
||||||
not armor_fly_swim.add_capes and
|
if armor_fly_swim.is_3d_armor and
|
||||||
|
not armor_fly_swim.add_capes and
|
||||||
not armor_fly_swim.is_skinsdb then
|
not armor_fly_swim.is_skinsdb then
|
||||||
|
|
||||||
player_mod = "3d_armor_character_sf.b3d" -- Swim Fly
|
player_mod = "3d_armor_character_sf.b3d"
|
||||||
texture = {armor.default_skin..".png",
|
texture = {armor.default_skin..".png",
|
||||||
"3d_armor_trans.png",
|
"3d_armor_trans.png",
|
||||||
"3d_armor_trans.png"}
|
"3d_armor_trans.png"}
|
||||||
end
|
end
|
||||||
|
|
||||||
if armor_fly_swim.is_3d_armor and
|
-- 3d_armor only with capes (simple_skins uses)
|
||||||
armor_fly_swim.add_capes and
|
if armor_fly_swim.is_3d_armor and
|
||||||
|
armor_fly_swim.add_capes and
|
||||||
not armor_fly_swim.is_skinsdb then
|
not armor_fly_swim.is_skinsdb then
|
||||||
|
|
||||||
player_mod = "3d_armor_character_sfc.b3d" -- Swim Fly Capes
|
player_mod = "3d_armor_character_sfc.b3d"
|
||||||
texture = {armor.default_skin..".png",
|
texture = {armor.default_skin..".png",
|
||||||
"3d_armor_trans.png",
|
"3d_armor_trans.png",
|
||||||
"3d_armor_trans.png"}
|
"3d_armor_trans.png"}
|
||||||
end
|
end
|
||||||
|
|
||||||
if armor_fly_swim.is_skinsdb then
|
-- skins_db with 3d_armor or without
|
||||||
player_mod = "skinsdb_3d_armor_character_5.b3d" -- Swim Fly Capes
|
if armor_fly_swim.is_skinsdb then
|
||||||
texture = {"blank.png",
|
player_mod = "skinsdb_3d_armor_character_5.b3d"
|
||||||
"blank.png",
|
texture = {"blank.png",
|
||||||
"blank.png",
|
"blank.png",
|
||||||
|
"blank.png",
|
||||||
"blank.png"}
|
"blank.png"}
|
||||||
end
|
end
|
||||||
|
|
||||||
return player_mod,texture
|
return player_mod,texture
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- Get WASD, pressed = true
|
-- Get WASD, pressed = true
|
||||||
|
|
||||||
function armor_fly_swim.get_wasd_state(controls)
|
function armor_fly_swim.get_wasd_state(controls)
|
||||||
|
|
||||||
local rtn = false
|
local rtn = false
|
||||||
|
|
||||||
if controls.up == true or
|
if controls.up == true or
|
||||||
controls.down == true or
|
controls.down == true or
|
||||||
controls.left == true or
|
controls.left == true or
|
||||||
controls.right == true then
|
controls.right == true then
|
||||||
|
|
||||||
rtn = true
|
rtn = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return rtn
|
return rtn
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- Check specific node fly/swim --
|
-- Check specific node fly/swim
|
||||||
-- 1=player feet, 2=one below feet, --
|
-- 1=player feet, 2=one below feet,
|
||||||
-- Thanks Gundul --
|
-- Thanks Gundul
|
||||||
----------------------------------------
|
|
||||||
function node_fsable(pos,num,type)
|
function node_fsable(pos,num,type)
|
||||||
|
|
||||||
local draw_ta = {"airlike"}
|
local draw_ta = {"airlike"}
|
||||||
local draw_tl = {"liquid","flowingliquid"}
|
local draw_tl = {"liquid","flowingliquid"}
|
||||||
local compare = draw_ta
|
local compare = draw_ta
|
||||||
local node = minetest.get_node({x=pos.x,y=pos.y-(num-1),z=pos.z})
|
local node = minetest.get_node({x=pos.x,y=pos.y-(num-1),z=pos.z})
|
||||||
local n_draw
|
local n_draw
|
||||||
|
|
||||||
if minetest.registered_nodes[node.name] then
|
if minetest.registered_nodes[node.name] then
|
||||||
n_draw = minetest.registered_nodes[node.name].drawtype
|
n_draw = minetest.registered_nodes[node.name].drawtype
|
||||||
else
|
else
|
||||||
n_draw = "normal"
|
n_draw = "normal"
|
||||||
end
|
end
|
||||||
|
|
||||||
if type == "s" then
|
if type == "s" then
|
||||||
compare = draw_tl
|
compare = draw_tl
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in ipairs(compare) do
|
for k,v in ipairs(compare) do
|
||||||
if n_draw == v then
|
if n_draw == v then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -97,8 +103,8 @@ function node_fsable(pos,num,type)
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
-- Check X number nodes down fly/Swimmable --
|
-- Check X number nodes down fly/Swimmable
|
||||||
-----------------------------------------------
|
|
||||||
function node_down_fsable(pos,num,type)
|
function node_down_fsable(pos,num,type)
|
||||||
|
|
||||||
local draw_ta = {"airlike"}
|
local draw_ta = {"airlike"}
|
||||||
|
@ -114,25 +120,25 @@ local compare = draw_ta
|
||||||
|
|
||||||
if type == "s" then
|
if type == "s" then
|
||||||
compare = draw_tl
|
compare = draw_tl
|
||||||
end
|
end
|
||||||
|
|
||||||
local n_draw
|
local n_draw
|
||||||
for k,v in pairs(nodes) do
|
for k,v in pairs(nodes) do
|
||||||
local n_draw
|
local n_draw
|
||||||
|
|
||||||
if minetest.registered_nodes[v.name] then
|
if minetest.registered_nodes[v.name] then
|
||||||
n_draw = minetest.registered_nodes[v.name].drawtype
|
n_draw = minetest.registered_nodes[v.name].drawtype
|
||||||
else
|
else
|
||||||
n_draw = "normal"
|
n_draw = "normal"
|
||||||
end
|
end
|
||||||
|
|
||||||
for k2,v2 in ipairs(compare) do
|
for k2,v2 in ipairs(compare) do
|
||||||
if n_draw == v2 then
|
if n_draw == v2 then
|
||||||
table.insert(result,"t")
|
table.insert(result,"t")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #result == num then
|
if #result == num then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
@ -141,43 +147,40 @@ local compare = draw_ta
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
-- Workaround for odd crouch behaviour --
|
-- Workaround for slab edge crouch
|
||||||
------------------------------------------
|
|
||||||
function crouch_wa(player,pos)
|
function crouch_wa(player,pos)
|
||||||
local is_slab = 0 -- is_slab var holder 0=not_slab, 1=slab
|
local is_slab = 0
|
||||||
local pos_w = {} -- Empty table
|
local pos_w = {}
|
||||||
local angle = (player:get_look_horizontal())*180/math.pi -- Convert Look direction to angles
|
local angle = (player:get_look_horizontal())*180/math.pi -- Convert Look direction to angles
|
||||||
|
|
||||||
if angle <= 45 or angle >= 315 then -- +Z North
|
-- +Z North
|
||||||
|
if angle <= 45 or angle >= 315 then
|
||||||
pos_w={x=pos.x,y=pos.y+1,z=pos.z+1}
|
pos_w={x=pos.x,y=pos.y+1,z=pos.z+1}
|
||||||
|
|
||||||
elseif angle > 45 and angle < 135 then -- -X West
|
-- -X West
|
||||||
|
elseif angle > 45 and angle < 135 then
|
||||||
pos_w={x=pos.x-1,y=pos.y+1,z=pos.z}
|
pos_w={x=pos.x-1,y=pos.y+1,z=pos.z}
|
||||||
|
|
||||||
elseif angle >= 135 and angle <= 225 then -- -Z South
|
-- -Z South
|
||||||
|
elseif angle >= 135 and angle <= 225 then
|
||||||
pos_w={x=pos.x,y=pos.y+1,z=pos.z-1}
|
pos_w={x=pos.x,y=pos.y+1,z=pos.z-1}
|
||||||
|
|
||||||
elseif angle > 225 and angle < 315 then -- +X East
|
-- +X East
|
||||||
pos_w={x=pos.x+1,y=pos.y+1,z=pos.z}
|
elseif angle > 225 and angle < 315 then
|
||||||
|
pos_w={x=pos.x+1,y=pos.y+1,z=pos.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
local check = minetest.get_node(pos_w) -- Get the node that is in front of the players look direction
|
local check = minetest.get_node(pos_w)
|
||||||
|
|
||||||
if minetest.registered_nodes[check.name] then
|
if minetest.registered_nodes[check.name] then
|
||||||
local check_g = minetest.registered_nodes[check.name].groups -- Get the groups assigned to node
|
local check_g = minetest.get_item_group(check.name, "slab")
|
||||||
for k,v in pairs(check_g) do
|
|
||||||
if k == "slab" then -- Any of the keys == slab then slab
|
if check_g ~= 0 then
|
||||||
is_slab = 1 -- is_slab set to 1
|
is_slab = 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return is_slab -- return 1 or 0
|
-- return 1 or 0, need to update to bool
|
||||||
|
return is_slab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
417
init.lua
417
init.lua
|
@ -1,29 +1,21 @@
|
||||||
--------------------------------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
-- ________ .___ _____ --
|
-- ___ _ __ ___ _ --
|
||||||
-- \_____ \ __| _/ / _ \_______ _____ ___________ --
|
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
|
||||||
-- _(__ < / __ | / /_\ \_ __ \/ \ / _ \_ __ \ --
|
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
|
||||||
-- / \/ /_/ | / | \ | \/ Y Y ( <_> ) | \/ --
|
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
|
||||||
-- /______ /\____ | \____|__ /__| |__|_| /\____/|__| --
|
-- |__/ --
|
||||||
-- \/ \/ \/ \/ --
|
-- Crouch and Climb --
|
||||||
-- ___________.__ .___ _________ .__ --
|
------------------------------------------------------------
|
||||||
-- \_ _____/| | ___.__. _____ ____ __| _/ / _____/_ _ _|__| _____ --
|
-- Sirrobzeroone --
|
||||||
-- | __) | |< | | \__ \ / \ / __ | \_____ \\ \/ \/ / |/ \ --
|
-- Licence code LGPL v2.1 --
|
||||||
-- | \ | |_\___ | / __ \| | \/ /_/ | / \\ /| | Y Y \ --
|
-- Cape Textures - CC0 --
|
||||||
-- \___ / |____/ ____| (____ /___| /\____ | /_______ / \/\_/ |__|__|_| / --
|
-- Blender Model/B3Ds as per base MTG - CC BY-SA 3.0 --
|
||||||
-- \/ \/ \/ \/ \/ \/ \/ --
|
-- except "3d_armor_trans.png" CC-BY-SA 3.0 --
|
||||||
-- --
|
------------------------------------------------------------
|
||||||
-- Also makes Capes a 3d Armor, armor item --
|
|
||||||
--------------------------------------------------------------------------------------
|
|
||||||
-- by Sirrobzeroone --
|
|
||||||
-- Licence code LGPL v2.1 --
|
|
||||||
-- Cape Textures - CC0 --
|
|
||||||
-- Blender Model/B3Ds as per base MTG - CC BY-SA 3.0 --
|
|
||||||
-- except "3d_armor_trans.png" CC-BY-SA 3.0 --
|
|
||||||
--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
----------------------------
|
----------------------------
|
||||||
-- Settings --
|
-- Settings
|
||||||
----------------------------
|
|
||||||
armor_fly_swim = {}
|
armor_fly_swim = {}
|
||||||
|
|
||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
|
@ -35,22 +27,23 @@ armor_fly_swim.example_cape = minetest.settings:get_bool("example_cape" ,false)
|
||||||
local fly_anim = minetest.settings:get_bool("fly_anim" ,true)
|
local fly_anim = minetest.settings:get_bool("fly_anim" ,true)
|
||||||
local fall_anim = minetest.settings:get_bool("fall_anim" ,true)
|
local fall_anim = minetest.settings:get_bool("fall_anim" ,true)
|
||||||
local fall_tv = tonumber(minetest.settings:get("fall_tv" ,true)) or 100
|
local fall_tv = tonumber(minetest.settings:get("fall_tv" ,true)) or 100
|
||||||
fall_tv = -1*(fall_tv/3.7) -- Convert kp/h back to number of -y blocks per 0.05 of a second.
|
-- Convert kp/h back to number of -y blocks per 0.05 of a second.
|
||||||
|
fall_tv = -1*(fall_tv/3.7)
|
||||||
local swim_anim = minetest.settings:get_bool("swim_anim" ,true)
|
local swim_anim = minetest.settings:get_bool("swim_anim" ,true)
|
||||||
local swim_sneak = minetest.settings:get_bool("swim_sneak" ,true)
|
local swim_sneak = minetest.settings:get_bool("swim_sneak" ,true)
|
||||||
local climb_anim = minetest.settings:get_bool("climb_anim" ,true)
|
local climb_anim = minetest.settings:get_bool("climb_anim" ,true)
|
||||||
local crouch_anim = minetest.settings:get_bool("crouch_anim" ,true)
|
local crouch_anim = minetest.settings:get_bool("crouch_anim" ,true)
|
||||||
local crouch_sneak = minetest.settings:get_bool("crouch_sneak" ,true)
|
local crouch_sneak = minetest.settings:get_bool("crouch_sneak" ,true)
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
-- Conditional mods --
|
-- Conditional mods
|
||||||
-----------------------
|
|
||||||
armor_fly_swim.is_3d_armor = minetest.get_modpath("3d_armor")
|
armor_fly_swim.is_3d_armor = minetest.get_modpath("3d_armor")
|
||||||
armor_fly_swim.is_skinsdb = minetest.get_modpath("skinsdb")
|
armor_fly_swim.is_skinsdb = minetest.get_modpath("skinsdb")
|
||||||
|
|
||||||
-------------------------------------
|
|
||||||
-- Adding new armor item for Capes --
|
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
-- Adding new armor item for Capes
|
||||||
|
|
||||||
if armor_fly_swim.add_capes == true then
|
if armor_fly_swim.add_capes == true then
|
||||||
if minetest.global_exists("armor") and armor.elements then
|
if minetest.global_exists("armor") and armor.elements then
|
||||||
table.insert(armor.elements, "capes")
|
table.insert(armor.elements, "capes")
|
||||||
|
@ -58,27 +51,27 @@ if armor_fly_swim.add_capes == true then
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------
|
----------------------------
|
||||||
-- Initiate files --
|
-- Initiate files
|
||||||
----------------------------
|
|
||||||
dofile(modpath .. "/i_functions.lua") -- Functions
|
|
||||||
|
|
||||||
if armor_fly_swim.example_cape and
|
dofile(modpath .. "/i_functions.lua")
|
||||||
armor_fly_swim.add_capes and
|
|
||||||
|
if armor_fly_swim.example_cape and
|
||||||
|
armor_fly_swim.add_capes and
|
||||||
armor_fly_swim.is_3d_armor then
|
armor_fly_swim.is_3d_armor then
|
||||||
|
|
||||||
dofile(modpath .. "/i_example_cape.lua") -- Example Cape
|
dofile(modpath .. "/i_example_cape.lua")
|
||||||
end
|
end
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
-- Get Player model to use --
|
-- Get Player model to use
|
||||||
-------------------------------------
|
|
||||||
local player_mod, texture = armor_fly_swim.get_player_model()
|
local player_mod, texture = armor_fly_swim.get_player_model()
|
||||||
|
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
-- Player model with Swim/Fly/Capes --
|
-- Player model with Swim/Fly/Capes
|
||||||
--------------------------------------
|
|
||||||
player_api.register_model(player_mod, {
|
player_api.register_model(player_mod, {
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
textures = texture,
|
textures = texture,
|
||||||
animations = {
|
animations = {
|
||||||
stand = {x=0, y=79},
|
stand = {x=0, y=79},
|
||||||
lay = {x=162, y=166},
|
lay = {x=162, y=166},
|
||||||
|
@ -86,7 +79,7 @@ player_api.register_model(player_mod, {
|
||||||
mine = {x=189, y=198},
|
mine = {x=189, y=198},
|
||||||
walk_mine = {x=200, y=219},
|
walk_mine = {x=200, y=219},
|
||||||
sit = {x=81, y=160},
|
sit = {x=81, y=160},
|
||||||
swim = {x=246, y=279},
|
swim = {x=246, y=279},
|
||||||
swim_atk = {x=285, y=318},
|
swim_atk = {x=285, y=318},
|
||||||
fly = {x=325, y=334},
|
fly = {x=325, y=334},
|
||||||
fly_atk = {x=340, y=349},
|
fly_atk = {x=340, y=349},
|
||||||
|
@ -94,18 +87,18 @@ player_api.register_model(player_mod, {
|
||||||
fall_atk = {x=365, y=374},
|
fall_atk = {x=365, y=374},
|
||||||
duck_std = {x=380, y=380},
|
duck_std = {x=380, y=380},
|
||||||
duck = {x=381, y=399},
|
duck = {x=381, y=399},
|
||||||
climb = {x=410, y=429},
|
climb = {x=410, y=429},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- Setting model on join and clearing --
|
-- Setting model on join and clearing
|
||||||
-- local_animations --
|
-- local_animations
|
||||||
----------------------------------------
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
player_api.set_model(player,player_mod)
|
player_api.set_model(player,player_mod)
|
||||||
player_api.player_attached[player:get_player_name()] = false
|
player_api.player_attached[player:get_player_name()] = false
|
||||||
player:set_local_animation({},{},{},{},30)
|
player:set_local_animation({},{},{},{},30)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
@ -121,240 +114,258 @@ minetest.register_globalstep(function()
|
||||||
local privs = minetest.get_player_privs(player:get_player_name())
|
local privs = minetest.get_player_privs(player:get_player_name())
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local pmeta = player:get_meta()
|
local pmeta = player:get_meta()
|
||||||
local cur_anim = player_api.get_animation(player)
|
local cur_anim = player_api.get_animation(player)
|
||||||
local ladder = {}
|
local ladder = {}
|
||||||
ladder.n = {is = false, pos = pos}
|
ladder.n = {is = false, pos = pos}
|
||||||
ladder.n_a = {is = false, pos = {x=pos.x,y=pos.y +1,z=pos.z}}
|
ladder.n_a = {is = false, pos = {x=pos.x,y=pos.y +1,z=pos.z}}
|
||||||
ladder.n_b = {is = false, pos = {x=pos.x,y=pos.y -1,z=pos.z}}
|
ladder.n_b = {is = false, pos = {x=pos.x,y=pos.y -1,z=pos.z}}
|
||||||
local is_slab = crouch_wa(player,pos)
|
local is_slab = crouch_wa(player,pos)
|
||||||
local attack = ""
|
local attack = ""
|
||||||
local ani_spd = 30
|
local ani_spd = 30
|
||||||
local offset = 0
|
local offset = 0
|
||||||
local tdebug = false
|
local tdebug = false
|
||||||
|
|
||||||
-- reset player collisionbox, eye height, speed override
|
-- reset player collisionbox, eye height, speed override
|
||||||
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
|
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}})
|
||||||
player:set_properties({eye_height = 1.47})
|
player:set_properties({eye_height = 1.47})
|
||||||
|
|
||||||
-- used to store and reset the players physics.speed settings
|
-- used to store and reset the players physics.speed settings
|
||||||
-- back to what they were before fly_swim adjusted them
|
-- back to what they were before fly_swim adjusted them
|
||||||
if pmeta:get_int("flyswim_std_under_slab") == 1 then
|
if pmeta:get_int("flyswim_std_under_slab") == 1 then
|
||||||
player:set_physics_override({speed = pmeta:get_float("flyswim_org_phy_or")})
|
player:set_physics_override({speed = pmeta:get_float("flyswim_org_phy_or")})
|
||||||
pmeta:set_int("flyswim_std_under_slab", 0)
|
pmeta:set_int("flyswim_std_under_slab", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
local vel = player:get_velocity()
|
local vel = player:get_velocity()
|
||||||
|
|
||||||
-- basically 3D Pythagorean Theorem km/h
|
-- basically 3D Pythagorean Theorem km/h
|
||||||
local play_s = (math.sqrt(math.pow(math.abs(vel.x),2) +
|
local play_s = (math.sqrt(math.pow(math.abs(vel.x),2) +
|
||||||
math.pow(math.abs(vel.y),2) +
|
math.pow(math.abs(vel.y),2) +
|
||||||
math.pow(math.abs(vel.z),2) ))*3.6
|
math.pow(math.abs(vel.z),2) ))*3.6
|
||||||
|
|
||||||
-- Sets terminal velocity to about 100Km/hr beyond --
|
-- Sets terminal velocity to about 100Km/hr beyond
|
||||||
-- this speed chunk load issues become more noticable --
|
-- this speed chunk load issues become more noticable
|
||||||
if vel.y < fall_tv and controls.sneak ~= true then
|
--(-1*(vel.y+1)) - catch those holding shift and over
|
||||||
local tv_offset_y = -1*((-1*(vel.y+1)) + vel.y) --(-1*(vel.y+1)) - catch those holding shift and over acceleratering when falling so dynamic end point so we dont bounce back up
|
-- acceleratering when falling so dynamic end point
|
||||||
player:add_player_velocity({x=0, y=tv_offset_y, z=0})
|
-- so player dosent bounce back up
|
||||||
|
if vel.y < fall_tv and controls.sneak ~= true then
|
||||||
|
local tv_offset_y = -1*((-1*(vel.y+1)) + vel.y)
|
||||||
|
player:add_player_velocity({x=0, y=tv_offset_y, z=0})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for Swinging/attacking and set string
|
-- Check for Swinging/attacking and set string
|
||||||
if controls.LMB or controls.RMB then
|
if controls.LMB or controls.RMB then
|
||||||
attack = "_atk"
|
attack = "_atk"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get ladder nodes
|
-- get ladder pos node
|
||||||
for k,def in pairs(ladder) do
|
local t_node = minetest.registered_nodes[minetest.get_node(ladder.n.pos).name]
|
||||||
local node = minetest.registered_nodes[minetest.get_node(def.pos).name]
|
if t_node and t_node.climbable then
|
||||||
if node and node.climbable then
|
ladder.n.is = true
|
||||||
def.is = true
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- Start of Animation Cases --
|
-- Start of Animation Cases --
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
-- Crouch Slab/Node Exception Case --
|
-- Crouch Slab/Node Exception Case
|
||||||
-------------------------------------
|
|
||||||
|
-- If player still udner slab/swimming in tunnel
|
||||||
|
-- and they let go of shift this stops them
|
||||||
|
-- standing up
|
||||||
local node_check = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
local node_check = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||||
local nc_draw = "normal"
|
local nc_draw = "normal"
|
||||||
local nc_slab = 0
|
local nc_slab = 0
|
||||||
local nc_node = 0
|
local nc_node = 0
|
||||||
|
|
||||||
if minetest.registered_nodes[node_check.name] then
|
if minetest.registered_nodes[node_check.name] then
|
||||||
|
|
||||||
nc_slab = minetest.get_item_group(node_check.name, "slab")
|
nc_slab = minetest.get_item_group(node_check.name, "slab")
|
||||||
nc_draw = minetest.registered_nodes[node_check.name].drawtype
|
nc_draw = minetest.registered_nodes[node_check.name].drawtype
|
||||||
|
|
||||||
if nc_draw ~= "liquid" and
|
if nc_draw ~= "liquid" and
|
||||||
nc_draw ~= "flowingliquid" and
|
nc_draw ~= "flowingliquid" and
|
||||||
nc_draw ~= "airlike" then
|
nc_draw ~= "airlike" then
|
||||||
|
|
||||||
nc_node = 1
|
nc_node = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if crouch_sneak and
|
if crouch_sneak and
|
||||||
nc_slab == 1 and
|
nc_slab == 1 and
|
||||||
not attached_to and
|
not attached_to and
|
||||||
not controls.sneak and
|
not controls.sneak and
|
||||||
not node_fsable(pos,2,"a") then
|
not node_fsable(pos,2,"a") then
|
||||||
|
|
||||||
local animiation = "duck_std"
|
local animiation = "duck_std"
|
||||||
|
|
||||||
-- when player moving
|
-- when player moving
|
||||||
if controls_wasd then
|
if controls_wasd then
|
||||||
local play_or_2 =player:get_physics_override()
|
local play_or_2 =player:get_physics_override()
|
||||||
pmeta:set_int("flyswim_std_under_slab", 1)
|
pmeta:set_int("flyswim_std_under_slab", 1)
|
||||||
pmeta:set_float("flyswim_org_phy_or", play_or_2.speed)
|
pmeta:set_float("flyswim_org_phy_or", play_or_2.speed)
|
||||||
player:set_physics_override({speed = play_or_2.speed*0.2})
|
player:set_physics_override({speed = play_or_2.speed*0.2})
|
||||||
|
|
||||||
animation = "duck"
|
animation = "duck"
|
||||||
end
|
end
|
||||||
|
|
||||||
if crouch_anim == true then
|
if crouch_anim == true then
|
||||||
player_api.set_animation(player, animation ,ani_spd/2)
|
player_api.set_animation(player, animation ,ani_spd/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.45, 0.3}})
|
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.45, 0.3}})
|
||||||
player:set_properties({eye_height = 1.27})
|
player:set_properties({eye_height = 1.27})
|
||||||
if tdebug then minetest.debug("crouch catch") end
|
if tdebug then minetest.debug("crouch catch") end
|
||||||
|
|
||||||
elseif swim_sneak and
|
elseif swim_sneak and
|
||||||
nc_node == 1 and
|
nc_node == 1 and
|
||||||
node_down_fsable(pos,1,"s") and
|
node_down_fsable(pos,1,"s") and
|
||||||
not attached_to and
|
not attached_to and
|
||||||
not controls.sneak then
|
not controls.sneak then
|
||||||
|
|
||||||
player_api.set_animation(player, "swim",ani_spd)
|
player_api.set_animation(player, "swim",ani_spd)
|
||||||
player:set_properties({collisionbox = {-0.4, 0, -0.4, 0.4, 0.5, 0.4}})
|
player:set_properties({collisionbox = {-0.4, 0, -0.4, 0.4, 0.5, 0.4}})
|
||||||
player:set_properties({eye_height = 0.7})
|
player:set_properties({eye_height = 0.7})
|
||||||
offset = 90
|
offset = 90
|
||||||
if tdebug then minetest.debug("swim through catch") end
|
if tdebug then minetest.debug("swim through catch") end
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Climb Cases --
|
-- Climb
|
||||||
-----------------------------
|
elseif climb_anim and
|
||||||
elseif climb_anim and -- Climb animation setting must be true
|
ladder.n.is and
|
||||||
ladder.n.is and -- Player standing in node that is climable and
|
(controls.jump or controls.sneak) then
|
||||||
(controls.jump or controls.sneak) then -- Moving up or Moving down
|
|
||||||
|
-- Moved inside climb to save unessecary node checking
|
||||||
|
for k,def in pairs(ladder) do
|
||||||
|
if k ~= "n" then
|
||||||
|
local node = minetest.registered_nodes[minetest.get_node(def.pos).name]
|
||||||
|
if node and node.climbable then
|
||||||
|
def.is = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if (controls.sneak and ladder.n_b.is) or
|
if (controls.sneak and ladder.n_b.is) or
|
||||||
(controls.jump and ladder.n_a.is) then
|
(controls.jump and ladder.n_a.is) then
|
||||||
|
|
||||||
minetest.debug(dump(ladder.n_b.is))
|
player_api.set_animation(player, "climb",ani_spd)
|
||||||
player_api.set_animation(player, "climb",ani_spd) -- Do climbing animation
|
|
||||||
if tdebug then minetest.debug("climb") end
|
if tdebug then minetest.debug("climb") end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Swim Cases --
|
-- Swim
|
||||||
-----------------------------
|
|
||||||
elseif swim_anim == true and
|
elseif swim_anim == true and
|
||||||
controls_wasd and
|
controls_wasd and
|
||||||
node_down_fsable(pos,2,"s") and --Node player standing in and 1 below must be swimmable
|
node_down_fsable(pos,2,"s") and
|
||||||
not attached_to then
|
not attached_to then
|
||||||
|
|
||||||
player_api.set_animation(player,"swim"..attack ,ani_spd) -- Set to swimming attack animation
|
player_api.set_animation(player,"swim"..attack ,ani_spd)
|
||||||
offset = 90 -- Offset for Headanim
|
offset = 90
|
||||||
if tdebug then minetest.debug("swim") end
|
if tdebug then minetest.debug("swim") end
|
||||||
|
|
||||||
elseif swim_sneak == true and
|
elseif swim_sneak == true and
|
||||||
swim_anim == true and
|
swim_anim == true and
|
||||||
controls.sneak and
|
controls.sneak and
|
||||||
node_down_fsable(pos,1,"s") and -- Node player standing in swimmable
|
node_down_fsable(pos,1,"s") and
|
||||||
not attached_to then
|
not attached_to then
|
||||||
|
|
||||||
player_api.set_animation(player, "swim",ani_spd)
|
player_api.set_animation(player, "swim",ani_spd)
|
||||||
player:set_properties({collisionbox = {-0.4, 0, -0.4, 0.4, 0.5, 0.4}})
|
player:set_properties({collisionbox = {-0.4, 0, -0.4, 0.4, 0.5, 0.4}})
|
||||||
player:set_properties({eye_height = 0.7})
|
player:set_properties({eye_height = 0.7})
|
||||||
offset = 90 -- Offset for Headanim
|
offset = 90
|
||||||
if tdebug then minetest.debug("swim through") end
|
if tdebug then minetest.debug("swim through") end
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Sneak Cases --
|
-- Sneak
|
||||||
-----------------------------
|
|
||||||
----------------------------------------------------------
|
|
||||||
-- Crouch-walk workaround Start
|
|
||||||
-- First slab player enters counts as a true slab and has an edge.
|
|
||||||
-- As such the shift edge detection kicks in and player can't move forwards
|
|
||||||
-- This case sets the player collision box to 1 high for that first slab
|
|
||||||
|
|
||||||
elseif crouch_anim and
|
|
||||||
controls.sneak and
|
|
||||||
controls.up and
|
|
||||||
not node_fsable(pos,2,"a") and -- No air node below feet
|
|
||||||
not attached_to and
|
|
||||||
play_s <= 1 and is_slab == 1 then -- Speed < 1 kph and node infront and up 1 must be slab see functions
|
|
||||||
|
|
||||||
if crouch_anim == true then
|
-- first elseif Crouch-walk workaround.
|
||||||
player_api.set_animation(player, "duck",ani_spd/2)
|
-- First slab player enters counts as a true slab
|
||||||
player:set_properties({eye_height = 1.27})
|
-- and has an edge. As such the shift edge detection
|
||||||
end
|
-- kicks in and player can't move forwards. This
|
||||||
|
-- case sets the player collision box to 1 high for that first slab
|
||||||
if crouch_sneak == true then
|
|
||||||
-- Workaround set collision box to 1 high
|
elseif crouch_anim and
|
||||||
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}})
|
controls.sneak and
|
||||||
end
|
controls.up and
|
||||||
if tdebug then minetest.debug("crouch_1") end
|
not node_fsable(pos,2,"a") and
|
||||||
|
not attached_to and
|
||||||
elseif crouch_anim and
|
play_s <= 1 and is_slab == 1 then
|
||||||
controls.sneak and
|
|
||||||
not node_fsable(pos,2,"a") and
|
if crouch_anim == true then
|
||||||
not attached_to then
|
player_api.set_animation(player, "duck",ani_spd/2)
|
||||||
|
|
||||||
local animation = "duck_std"
|
|
||||||
if controls_wasd then animation = "duck" end
|
|
||||||
|
|
||||||
player_api.set_animation(player, animation, ani_spd/2)
|
|
||||||
player:set_properties({eye_height = 1.27})
|
player:set_properties({eye_height = 1.27})
|
||||||
|
end
|
||||||
|
|
||||||
|
if crouch_sneak == true then
|
||||||
|
-- Workaround set collision box to 1 high
|
||||||
|
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3}})
|
||||||
|
end
|
||||||
|
if tdebug then minetest.debug("crouch_1") end
|
||||||
|
|
||||||
|
elseif crouch_anim and
|
||||||
|
controls.sneak and
|
||||||
|
not node_fsable(pos,2,"a") and
|
||||||
|
not attached_to then
|
||||||
|
|
||||||
|
local animation = "duck_std"
|
||||||
|
if controls_wasd then animation = "duck" end
|
||||||
|
|
||||||
|
player_api.set_animation(player, animation, ani_spd/2)
|
||||||
|
player:set_properties({eye_height = 1.27})
|
||||||
|
|
||||||
|
if crouch_sneak == true then
|
||||||
|
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.45, 0.3}})
|
||||||
|
end
|
||||||
|
if tdebug then minetest.debug("crouch_2") end
|
||||||
|
|
||||||
if crouch_sneak == true then
|
|
||||||
player:set_properties({collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.45, 0.3}})
|
|
||||||
end
|
|
||||||
if tdebug then minetest.debug("crouch_2") end
|
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Flying Cases --
|
-- Flying
|
||||||
-----------------------------
|
|
||||||
elseif fly_anim == true and
|
elseif fly_anim == true and
|
||||||
privs.fly == true and
|
privs.fly == true and
|
||||||
node_down_fsable(pos,3,"a") and
|
node_down_fsable(pos,3,"a") and
|
||||||
not attached_to then
|
not attached_to then
|
||||||
|
|
||||||
-- Vel.y value is a compromise for code simplicity,
|
-- Vel.y value is a compromise for code simplicity,
|
||||||
-- Flyers wont get fall animation until below -18m/s
|
-- Flyers wont get fall animation until below -18m/s
|
||||||
if controls_wasd then
|
if controls_wasd then
|
||||||
player_api.set_animation(player, "fly"..attack, ani_spd)
|
player_api.set_animation(player, "fly"..attack, ani_spd)
|
||||||
offset = 90
|
offset = 90
|
||||||
if tdebug then minetest.debug("fly") end
|
if tdebug then minetest.debug("fly") end
|
||||||
|
|
||||||
elseif fall_anim == true and
|
elseif fall_anim == true and
|
||||||
vel.y < -18.0 then
|
vel.y < -18.0 then
|
||||||
player_api.set_animation(player, "fall"..attack, ani_spd)
|
player_api.set_animation(player, "fall"..attack, ani_spd)
|
||||||
offset = 90
|
offset = 90
|
||||||
if tdebug then minetest.debug("fly_fall") end
|
if tdebug then minetest.debug("fly_fall") end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- Falling Cases --
|
-- Falling
|
||||||
-----------------------------
|
|
||||||
elseif fall_anim == true and
|
elseif fall_anim == true and
|
||||||
node_down_fsable(pos,5,"a") and
|
node_down_fsable(pos,5,"a") and
|
||||||
vel.y < -0.5 and
|
vel.y < -0.5 and
|
||||||
not attached_to then
|
not attached_to then
|
||||||
|
|
||||||
player_api.set_animation(player, "fall"..attack, ani_spd)
|
player_api.set_animation(player, "fall"..attack, ani_spd)
|
||||||
offset = 90
|
offset = 90
|
||||||
if tdebug then minetest.debug("fall") end
|
if tdebug then minetest.debug("fall") end
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
-- Post MT 5.3 Head Animation --
|
-- Post MT 5.3 Head Animation --
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
local check_v = minetest.is_creative_enabled -- this function was added in 5.3 which has the bone position change break animations fix - i think (MT #9807)
|
-- this function was added in 5.3 which has the bone position
|
||||||
-- I'm not too sure how to directly test for the bone fix so I simply check for this function.
|
-- change break animations fix - i think (MT #9807)
|
||||||
if check_v ~= nil then -- If creative_enabled function is nil we are pre-5.3
|
-- I'm not too sure how to directly test for the bone fix/ MT version
|
||||||
local look_degree = -math.deg(player:get_look_vertical())-- Kept this near code
|
-- so I simply check for this function.
|
||||||
|
local check_v = minetest.is_creative_enabled
|
||||||
|
|
||||||
|
if check_v ~= nil then
|
||||||
|
|
||||||
|
local look_degree = -math.deg(player:get_look_vertical())
|
||||||
|
|
||||||
if look_degree > 29 and offset ~= 0 then
|
if look_degree > 29 and offset ~= 0 then
|
||||||
offset = offset - (look_degree-30)
|
offset = offset - (look_degree-30)
|
||||||
|
|
||||||
|
@ -362,14 +373,14 @@ minetest.register_globalstep(function()
|
||||||
offset = offset - (look_degree-60)
|
offset = offset - (look_degree-60)
|
||||||
|
|
||||||
elseif look_degree < -60 and offset == 0 then
|
elseif look_degree < -60 and offset == 0 then
|
||||||
offset = offset - (look_degree+60)
|
offset = offset - (look_degree+60)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Code by LoneWolfHT - Headanim mod MIT Licence --
|
-- Code by LoneWolfHT - Headanim mod MIT Licence --
|
||||||
player:set_bone_position("Head", vector.new(0, 6.35, 0),vector.new(look_degree + offset, 0, 0))
|
player:set_bone_position("Head", vector.new(0, 6.35, 0),vector.new(look_degree + offset, 0, 0))
|
||||||
-- Code by LoneWolfHT - Headanim mod MIT Licence --
|
-- Code by LoneWolfHT - Headanim mod MIT Licence --
|
||||||
end
|
end
|
||||||
--minetest.chat_send_all(play_s.." km/h") -- for diagnosing chunk emerge issues when falling currently unsolved
|
--minetest.chat_send_all(play_s.." km/h") -- for diagnosing chunk emerge issues when falling currently unsolved
|
||||||
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
Loading…
Reference in New Issue