~ Code Cleanup
~ Move ladder node above/below check to inside ladder check
master
Sirrobzeroone 2022-08-18 17:10:02 +10:00
parent 586d4501c0
commit 98dbe16550
3 changed files with 312 additions and 291 deletions

View File

@ -1,6 +1,13 @@
-------------------------------------------
------------------------------------------------------------
-- ___ _ __ ___ _ --
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
-- |__/ --
-- Crouch and Climb --
------------------------------------------------------------
-- Example Cape --
-------------------------------------------
------------------------------------------------------------
armor:register_armor("3d_armor_flyswim:demo_cape", {
description = "Someones Cape",
inventory_image = "3d_armor_flyswim_demo_cape_inv.png",

View File

@ -1,43 +1,49 @@
------------------------------------------------------------------
-- ___________ __ .__ --
-- \_ _____/_ __ ____ _____/ |_|__| ____ ____ ______ --
-- | __)| | \/ \_/ ___\ __\ |/ _ \ / \ / ___/ --
-- | \ | | / | \ \___| | | ( <_> ) | \\___ \ --
-- \___ / |____/|___| /\___ >__| |__|\____/|___| /____ > --
-- \/ \/ \/ \/ \/ --
------------------------------------------------------------------
------------------------------------------------------------
-- ___ _ __ ___ _ --
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
-- |__/ --
-- Crouch and Climb --
------------------------------------------------------------
-- Functions --
------------------------------------------------------------
----------------------------------------
-- Get Player model and textures
function armor_fly_swim.get_player_model()
local player_mod = "character_sf.b3d" -- Swim, Fly
-- player_api only (simple_skins uses)
local player_mod = "character_sf.b3d"
local texture = {"character.png",
"3d_armor_trans.png"}
-- 3d_armor only nil capes (simple_skins uses)
if armor_fly_swim.is_3d_armor and
not armor_fly_swim.add_capes and
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",
"3d_armor_trans.png",
"3d_armor_trans.png"}
end
-- 3d_armor only with capes (simple_skins uses)
if armor_fly_swim.is_3d_armor and
armor_fly_swim.add_capes and
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",
"3d_armor_trans.png",
"3d_armor_trans.png"}
end
-- skins_db with 3d_armor or without
if armor_fly_swim.is_skinsdb then
player_mod = "skinsdb_3d_armor_character_5.b3d" -- Swim Fly Capes
player_mod = "skinsdb_3d_armor_character_5.b3d"
texture = {"blank.png",
"blank.png",
"blank.png",
@ -66,10 +72,10 @@ function armor_fly_swim.get_wasd_state(controls)
end
----------------------------------------
-- Check specific node fly/swim --
-- 1=player feet, 2=one below feet, --
-- Thanks Gundul --
----------------------------------------
-- Check specific node fly/swim
-- 1=player feet, 2=one below feet,
-- Thanks Gundul
function node_fsable(pos,num,type)
local draw_ta = {"airlike"}
@ -97,8 +103,8 @@ function node_fsable(pos,num,type)
end
-----------------------------------------------
-- Check X number nodes down fly/Swimmable --
-----------------------------------------------
-- Check X number nodes down fly/Swimmable
function node_down_fsable(pos,num,type)
local draw_ta = {"airlike"}
@ -141,43 +147,40 @@ local compare = draw_ta
end
------------------------------------------
-- Workaround for odd crouch behaviour --
------------------------------------------
-- Workaround for slab edge crouch
function crouch_wa(player,pos)
local is_slab = 0 -- is_slab var holder 0=not_slab, 1=slab
local pos_w = {} -- Empty table
local is_slab = 0
local pos_w = {}
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}
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}
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}
elseif angle > 225 and angle < 315 then -- +X East
-- +X East
elseif angle > 225 and angle < 315 then
pos_w={x=pos.x+1,y=pos.y+1,z=pos.z}
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
local check_g = minetest.registered_nodes[check.name].groups -- Get the groups assigned to node
for k,v in pairs(check_g) do
if k == "slab" then -- Any of the keys == slab then slab
is_slab = 1 -- is_slab set to 1
end
local check_g = minetest.get_item_group(check.name, "slab")
if check_g ~= 0 then
is_slab = 1
end
end
return is_slab -- return 1 or 0
-- return 1 or 0, need to update to bool
return is_slab
end

167
init.lua
View File

@ -1,29 +1,21 @@
--------------------------------------------------------------------------------------
-- ________ .___ _____ --
-- \_____ \ __| _/ / _ \_______ _____ ___________ --
-- _(__ < / __ | / /_\ \_ __ \/ \ / _ \_ __ \ --
-- / \/ /_/ | / | \ | \/ Y Y ( <_> ) | \/ --
-- /______ /\____ | \____|__ /__| |__|_| /\____/|__| --
-- \/ \/ \/ \/ --
-- ___________.__ .___ _________ .__ --
-- \_ _____/| | ___.__. _____ ____ __| _/ / _____/_ _ _|__| _____ --
-- | __) | |< | | \__ \ / \ / __ | \_____ \\ \/ \/ / |/ \ --
-- | \ | |_\___ | / __ \| | \/ /_/ | / \\ /| | Y Y \ --
-- \___ / |____/ ____| (____ /___| /\____ | /_______ / \/\_/ |__|__|_| / --
-- \/ \/ \/ \/ \/ \/ \/ --
-- --
-- Also makes Capes a 3d Armor, armor item --
--------------------------------------------------------------------------------------
-- by Sirrobzeroone --
------------------------------------------------------------
-- ___ _ __ ___ _ --
-- | __| |_ _ / _|___ / __|_ __ _(_)_ __ --
-- | _|| | || | > _|_ _| \__ \ V V / | ' \ --
-- |_| |_|\_, | \_____| |___/\_/\_/|_|_|_|_| --
-- |__/ --
-- Crouch and Climb --
------------------------------------------------------------
-- 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 = {}
local modname = minetest.get_current_modname()
@ -35,7 +27,8 @@ armor_fly_swim.example_cape = minetest.settings:get_bool("example_cape" ,false)
local fly_anim = minetest.settings:get_bool("fly_anim" ,true)
local fall_anim = minetest.settings:get_bool("fall_anim" ,true)
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_sneak = minetest.settings:get_bool("swim_sneak" ,true)
local climb_anim = minetest.settings:get_bool("climb_anim" ,true)
@ -43,14 +36,14 @@ local crouch_anim = minetest.settings:get_bool("crouch_anim" ,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_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 minetest.global_exists("armor") and armor.elements then
table.insert(armor.elements, "capes")
@ -58,24 +51,24 @@ if armor_fly_swim.add_capes == true then
end
----------------------------
-- Initiate files --
----------------------------
dofile(modpath .. "/i_functions.lua") -- Functions
-- Initiate files
dofile(modpath .. "/i_functions.lua")
if armor_fly_swim.example_cape and
armor_fly_swim.add_capes and
armor_fly_swim.is_3d_armor then
dofile(modpath .. "/i_example_cape.lua") -- Example Cape
dofile(modpath .. "/i_example_cape.lua")
end
-------------------------------------
-- Get Player model to use --
-------------------------------------
-- Get Player model to use
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, {
animation_speed = 30,
textures = texture,
@ -98,9 +91,9 @@ player_api.register_model(player_mod, {
},
})
----------------------------------------
-- Setting model on join and clearing --
-- local_animations --
----------------------------------------
-- Setting model on join and clearing
-- local_animations
minetest.register_on_joinplayer(function(player)
player_api.set_model(player,player_mod)
player_api.player_attached[player:get_player_name()] = false
@ -150,10 +143,13 @@ minetest.register_globalstep(function()
math.pow(math.abs(vel.y),2) +
math.pow(math.abs(vel.z),2) ))*3.6
-- Sets terminal velocity to about 100Km/hr beyond --
-- this speed chunk load issues become more noticable --
-- Sets terminal velocity to about 100Km/hr beyond
-- this speed chunk load issues become more noticable
--(-1*(vel.y+1)) - catch those holding shift and over
-- acceleratering when falling so dynamic end point
-- 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) --(-1*(vel.y+1)) - catch those holding shift and over acceleratering when falling so dynamic end point so we dont bounce back up
local tv_offset_y = -1*((-1*(vel.y+1)) + vel.y)
player:add_player_velocity({x=0, y=tv_offset_y, z=0})
end
@ -162,20 +158,21 @@ minetest.register_globalstep(function()
attack = "_atk"
end
-- get ladder nodes
for k,def in pairs(ladder) do
local node = minetest.registered_nodes[minetest.get_node(def.pos).name]
if node and node.climbable then
def.is = true
end
-- get ladder pos node
local t_node = minetest.registered_nodes[minetest.get_node(ladder.n.pos).name]
if t_node and t_node.climbable then
ladder.n.is = true
end
---------------------------------------------------------
-- 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 nc_draw = "normal"
local nc_slab = 0
@ -233,58 +230,66 @@ minetest.register_globalstep(function()
if tdebug then minetest.debug("swim through catch") end
-----------------------------
-- Climb Cases --
-----------------------------
elseif climb_anim and -- Climb animation setting must be true
ladder.n.is and -- Player standing in node that is climable and
(controls.jump or controls.sneak) then -- Moving up or Moving down
-- Climb
elseif climb_anim and
ladder.n.is and
(controls.jump or controls.sneak) then
-- 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
(controls.jump and ladder.n_a.is) then
minetest.debug(dump(ladder.n_b.is))
player_api.set_animation(player, "climb",ani_spd) -- Do climbing animation
player_api.set_animation(player, "climb",ani_spd)
if tdebug then minetest.debug("climb") end
end
-----------------------------
-- Swim Cases --
-----------------------------
-- Swim
elseif swim_anim == true 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
player_api.set_animation(player,"swim"..attack ,ani_spd) -- Set to swimming attack animation
offset = 90 -- Offset for Headanim
player_api.set_animation(player,"swim"..attack ,ani_spd)
offset = 90
if tdebug then minetest.debug("swim") end
elseif swim_sneak == true and
swim_anim == true 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
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({eye_height = 0.7})
offset = 90 -- Offset for Headanim
offset = 90
if tdebug then minetest.debug("swim through") end
-----------------------------
-- Sneak Cases --
-----------------------------
----------------------------------------------------------
-- 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
-- Sneak
-- first elseif Crouch-walk workaround.
-- 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 node_fsable(pos,2,"a") and
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
play_s <= 1 and is_slab == 1 then
if crouch_anim == true then
player_api.set_animation(player, "duck",ani_spd/2)
@ -314,8 +319,8 @@ minetest.register_globalstep(function()
if tdebug then minetest.debug("crouch_2") end
-----------------------------
-- Flying Cases --
-----------------------------
-- Flying
elseif fly_anim == true and
privs.fly == true and
node_down_fsable(pos,3,"a") and
@ -336,8 +341,8 @@ minetest.register_globalstep(function()
end
-----------------------------
-- Falling Cases --
-----------------------------
-- Falling
elseif fall_anim == true and
node_down_fsable(pos,5,"a") and
vel.y < -0.5 and
@ -351,10 +356,16 @@ minetest.register_globalstep(function()
---------------------------------------------------------
-- 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)
-- I'm not too sure how to directly test for the bone fix so I simply check for this function.
if check_v ~= nil then -- If creative_enabled function is nil we are pre-5.3
local look_degree = -math.deg(player:get_look_vertical())-- Kept this near code
-- this function was added in 5.3 which has the bone position
-- change break animations fix - i think (MT #9807)
-- I'm not too sure how to directly test for the bone fix/ MT version
-- 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
offset = offset - (look_degree-30)