Fix elytra code style

This commit is contained in:
Lizzy Fleckenstein 2021-04-17 19:34:23 +02:00
parent f8b54db392
commit 205572cc69
2 changed files with 57 additions and 111 deletions

View File

@ -1,69 +1,28 @@
local S = minetest.get_translator("mcl_fireworks")
player_rocketing = {}
local player_rocketing = {}
local help = S("Flight Duration:")
local tt_help = S("Flight Duration:")
local description = S("Firework Rocket")
local rocket_sound = function()
minetest.sound_play("mcl_fireworks_rocket")
local function register_rocket(n, duration, force)
minetest.register_craftitem("mcl_fireworks:rocket_" .. n, {
description = description,
_tt_help = tt_help .. " " .. duration,
inventory_image = "mcl_fireworks_rocket.png",
stack_max = 64,
on_use = function(itemstack, user, pointed_thing)
local elytra = mcl_playerplus.elytra[user]
if elytra.active and elytra.rocketing <= 0 then
elytra.rocketing = duration
itemstack:take_item()
minetest.sound_play("mcl_fireworks_rocket", {pos = user:get_pos()})
end
return itemstack
end,
})
end
minetest.register_craftitem("mcl_fireworks:rocket_1", {
description = description,
_tt_help = help.." 1",
inventory_image = "mcl_fireworks_rocket.png",
stack_max = 64,
on_use = function(itemstack, user, pointed_thing)
local torso = user:get_inventory():get_stack("armor", 3)
if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then
player_rocketing[user] = true
minetest.after(2.2, function()
player_rocketing[user] = false
end)
itemstack:take_item()
--user:add_player_velocity(vector.multiply(user:get_look_dir(), 20))
rocket_sound()
end
return itemstack
end,
})
minetest.register_craftitem("mcl_fireworks:rocket_2", {
description = description,
_tt_help = help.." 2",
inventory_image = "mcl_fireworks_rocket.png",
stack_max = 64,
on_use = function(itemstack, user, pointed_thing)
local torso = user:get_inventory():get_stack("armor", 3)
if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then
player_rocketing[user] = true
minetest.after(4.5, function()
player_rocketing[user] = false
end)
itemstack:take_item()
--user:add_player_velocity(vector.multiply(user:get_look_dir(), 20))
rocket_sound()
end
return itemstack
end,
})
minetest.register_craftitem("mcl_fireworks:rocket_3", {
description = description,
_tt_help = help.." 3",
inventory_image = "mcl_fireworks_rocket.png",
stack_max = 64,
on_use = function(itemstack, user, pointed_thing)
local torso = user:get_inventory():get_stack("armor", 3)
if torso and torso:get_name() == "mcl_armor:elytra" and player_rocketing[user] ~= true then
player_rocketing[user] = true
minetest.after(6, function()
player_rocketing[user] = false
end)
itemstack:take_item()
--user:add_player_velocity(vector.multiply(user:get_look_dir(), 20))
rocket_sound()
end
return itemstack
end,
})
register_rocket(1, 2.2, 10)
register_rocket(2, 4.5, 20)
register_rocket(3, 6, 30)

View File

@ -1,8 +1,9 @@
local S = minetest.get_translator("mcl_playerplus")
elytra = {}
mcl_playerplus = {
elytra = {},
}
local node_stand_return = ":air"
local get_connected_players = minetest.get_connected_players
local dir_to_yaw = minetest.dir_to_yaw
local get_item_group = minetest.get_item_group
@ -183,40 +184,17 @@ minetest.register_globalstep(function(dtime)
player_vel_yaw = limit_vel_yaw(player_vel_yaw, yaw)
player_vel_yaws[name] = player_vel_yaw
local pos = player:get_pos()
local node = minetest.get_node_or_nil({x = pos.x, y = pos.y - 0.5, z = pos.z})
local fly_pos = player:get_pos()
local fly_node = minetest.get_node({x = fly_pos.x, y = fly_pos.y - 0.5, z = fly_pos.z}).name
local elytra = mcl_playerplus.elytra[player]
if node then
node_stand_return = node.name
end
elytra.active = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra"
and not player:get_attach()
and (elytra.active or control.jump and player_velocity.y < -6)
and (fly_node == "air" or fly_node == "ignore")
local chestplate = player:get_inventory():get_stack("armor", 3)
if player_rocketing[player] and player_rocketing[player] == true and chestplate:get_name() == "mcl_armor:elytra" then
if math.abs(player_velocity.x) + math.abs(player_velocity.y) + math.abs(player_velocity.z) < 40 then
player:add_player_velocity(vector.multiply(player:get_look_dir(), 4))
elytra[player] = true
end
end
if elytra[player] == true and ~= nil then
elytra[player] = false
end
--[[
if player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra" and player_velocity.y < -6 and elytra[player] ~= true and is_sprinting(name) then
elytra[player] = true
elseif elytra[player] == true and node_stand_return ~= "air" or elytra[player] == true and player:get_inventory():get_stack("armor", 3):get_name() ~= "mcl_armor:elytra" or player:get_attach() ~= nil then
elytra[player] = false
end]]
local wearing_elytra = player:get_inventory():get_stack("armor", 3):get_name() == "mcl_armor:elytra"
if elytra[player] then
if node_stand_return ~= "air" or not wearing_elytra or player:get_attach() then
elytra[player] = false
else
if elytra.active then
mcl_player.player_set_animation(player, "fly")
playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1)
if player_velocity.y < -1.5 then
player:add_velocity({x=0, y=0.17, z=0})
end
@ -229,10 +207,17 @@ minetest.register_globalstep(function(dtime)
end
player:add_velocity({x=dir.x, y=look_pitch, z=dir.z})
end
playerphysics.add_physics_factor(player, "gravity", "mcl_playerplus:elytra", 0.1)
if elytra.rocketing > 0 then
elytra.rocketing = elytra.rocketing - dtime
if vector.length(player_velocity) < 40 then
local add_velocity = player.add_velocity or player.add_player_velocity
add_velocity(player, vector.multiply(player:get_look_dir(), 4))
end
end
elseif wearing_elytra and player_velocity.y < -6 and controls.jump then
elytra[player] = true
else
elytra.rocketing = 0
playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra")
end
@ -254,12 +239,12 @@ minetest.register_globalstep(function(dtime)
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
end
if elytra[player] == true then
-- set head pitch and yaw when swimming
if elytra.active then
-- set head pitch and yaw when flying
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90-degrees(dir_to_pitch(player_velocity)),player_vel_yaw - yaw,0))
-- sets eye height, and nametag color accordingly
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.5, nametag_color = { r = 225, b = 225, a = 0, g = 225 }})
-- control body bone when swimming
-- control body bone when flying
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(degrees(dir_to_pitch(player_velocity)) - 90,-player_vel_yaw + yaw + 180,0))
elseif parent then
local parent_yaw = degrees(parent:get_yaw())
@ -523,6 +508,7 @@ minetest.register_on_joinplayer(function(player)
swimDistance = 0,
jump_cooldown = -1, -- Cooldown timer for jumping, we need this to prevent the jump exhaustion to increase rapidly
}
mcl_playerplus.elytra[player] = {active = false, rocketing = 0}
end)
-- clear when player leaves
@ -530,4 +516,5 @@ minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
mcl_playerplus_internal[name] = nil
mcl_playerplus.elytra[player] = nil
end)