Move addYVelocityClamped to common API
This commit is contained in:
@@ -41,6 +41,15 @@ function industrialtest.internal.clamp(num,min,max)
|
|||||||
return math.max(math.min(num,max),min)
|
return math.max(math.min(num,max),min)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function industrialtest.internal.addYVelocityClamped(player,vel,max)
|
||||||
|
local playerVel=player:get_velocity()
|
||||||
|
if playerVel.y+vel>max then
|
||||||
|
player:add_velocity(vector.new(0,math.max(max-playerVel.y,0),0))
|
||||||
|
else
|
||||||
|
player:add_velocity(vector.new(0,vel,0))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function industrialtest.internal.unpackTableInto(first,second)
|
function industrialtest.internal.unpackTableInto(first,second)
|
||||||
for k,v in pairs(second) do
|
for k,v in pairs(second) do
|
||||||
first[k]=v
|
first[k]=v
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function industrialtest.JetpackBase.update(self, player, inv, itemstack, dtime)
|
|||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
local control = player:get_player_control()
|
local control = player:get_player_control()
|
||||||
if control.jump and self:tryFly(itemstack) then
|
if control.jump and self:tryFly(itemstack) then
|
||||||
self.addYVelocityClamped(player,1,10)
|
industrialtest.internal.addYVelocityClamped(player,1,10)
|
||||||
if not soundHandles[playerName] then
|
if not soundHandles[playerName] then
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local handle = minetest.sound_play("industrialtest_jetpack_loop", {
|
local handle = minetest.sound_play("industrialtest_jetpack_loop", {
|
||||||
@@ -47,15 +47,6 @@ function industrialtest.JetpackBase.update(self, player, inv, itemstack, dtime)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function industrialtest.JetpackBase.addYVelocityClamped(player,vel,max)
|
|
||||||
local playerVel=player:get_velocity()
|
|
||||||
if playerVel.y+vel>max then
|
|
||||||
player:add_velocity(vector.new(0,math.max(max-playerVel.y,0),0))
|
|
||||||
else
|
|
||||||
player:add_velocity(vector.new(0,vel,0))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
industrialtest.Jetpack=table.copy(industrialtest.JetpackBase)
|
industrialtest.Jetpack=table.copy(industrialtest.JetpackBase)
|
||||||
industrialtest.internal.unpackTableInto(industrialtest.Jetpack,{
|
industrialtest.internal.unpackTableInto(industrialtest.Jetpack,{
|
||||||
-- _v is hack to suppress "Registered armor doesn't have material at the end of registration name" warning from 3D Armor.
|
-- _v is hack to suppress "Registered armor doesn't have material at the end of registration name" warning from 3D Armor.
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ industrialtest.internal.unpackTableInto(industrialtest.QuantumBodyarmor,{
|
|||||||
part="torso",
|
part="torso",
|
||||||
modelImage="industrialtest_quantum_bodyarmor.png",
|
modelImage="industrialtest_quantum_bodyarmor.png",
|
||||||
update=industrialtest.JetpackBase.update,
|
update=industrialtest.JetpackBase.update,
|
||||||
addYVelocityClamped=industrialtest.JetpackBase.addYVelocityClamped,
|
addYVelocityClamped=industrialtest.internal.addYVelocityClamped,
|
||||||
tryFly=industrialtest.ElectricJetpack.tryFly
|
tryFly=industrialtest.ElectricJetpack.tryFly
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user