mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-11-23 15:13:44 +01:00
Import two my MTG commits for better driving experience
Takes the changes from MTG commit 38307da and 71ea0c6
This commit is contained in:
parent
3bd7d6f8ca
commit
e458734cc5
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.bak
|
||||||
|
*.diff
|
||||||
|
*.patch
|
@ -49,17 +49,10 @@ function cart_entity:on_rightclick(clicker)
|
|||||||
end
|
end
|
||||||
local player_name = clicker:get_player_name()
|
local player_name = clicker:get_player_name()
|
||||||
if self.driver and player_name == self.driver then
|
if self.driver and player_name == self.driver then
|
||||||
self.driver = nil
|
|
||||||
boost_cart:manage_attachment(clicker, nil)
|
boost_cart:manage_attachment(clicker, nil)
|
||||||
elseif not self.driver then
|
elseif not self.driver then
|
||||||
self.driver = player_name
|
|
||||||
boost_cart:manage_attachment(clicker, self.object)
|
boost_cart:manage_attachment(clicker, self.object)
|
||||||
|
self.driver = player_name
|
||||||
if default.player_set_animation then
|
|
||||||
-- player_api(/default) does not update the animation
|
|
||||||
-- when the player is attached, reset to default animation
|
|
||||||
default.player_set_animation(clicker, "stand")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -94,8 +87,8 @@ end
|
|||||||
-- 0.5.x and later: When the driver leaves
|
-- 0.5.x and later: When the driver leaves
|
||||||
function cart_entity:on_detach_child(child)
|
function cart_entity:on_detach_child(child)
|
||||||
if child and child:get_player_name() == self.driver then
|
if child and child:get_player_name() == self.driver then
|
||||||
self.driver = nil
|
|
||||||
boost_cart:manage_attachment(child, nil)
|
boost_cart:manage_attachment(child, nil)
|
||||||
|
self.driver = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -185,11 +178,11 @@ function cart_entity:on_step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local cart_dir = boost_cart:velocity_to_dir(vel)
|
local dir = boost_cart:velocity_to_dir(vel)
|
||||||
local same_dir = vector.equals(cart_dir, self.old_dir)
|
local dir_changed = not vector.equals(dir, self.old_dir)
|
||||||
local update = {}
|
local update = {}
|
||||||
|
|
||||||
if self.old_pos and not self.punched and same_dir then
|
if self.old_pos and not self.punched and not dir_changed then
|
||||||
local flo_pos = vector.round(pos)
|
local flo_pos = vector.round(pos)
|
||||||
local flo_old = vector.round(self.old_pos)
|
local flo_old = vector.round(self.old_pos)
|
||||||
if vector.equals(flo_pos, flo_old) then
|
if vector.equals(flo_pos, flo_old) then
|
||||||
@ -210,7 +203,7 @@ function cart_entity:on_step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local stop_wiggle = false
|
local stop_wiggle = false
|
||||||
if self.old_pos and same_dir then
|
if self.old_pos and not dir_changed then
|
||||||
-- Detection for "skipping" nodes (perhaps use average dtime?)
|
-- Detection for "skipping" nodes (perhaps use average dtime?)
|
||||||
-- It's sophisticated enough to take the acceleration in account
|
-- It's sophisticated enough to take the acceleration in account
|
||||||
local acc = self.object:get_acceleration()
|
local acc = self.object:get_acceleration()
|
||||||
@ -225,7 +218,7 @@ function cart_entity:on_step(dtime)
|
|||||||
-- No rail found: set to the expected position
|
-- No rail found: set to the expected position
|
||||||
pos = new_pos
|
pos = new_pos
|
||||||
update.pos = true
|
update.pos = true
|
||||||
cart_dir = new_dir
|
dir = new_dir
|
||||||
end
|
end
|
||||||
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
||||||
-- Stop wiggle
|
-- Stop wiggle
|
||||||
@ -235,20 +228,25 @@ function cart_entity:on_step(dtime)
|
|||||||
-- dir: New moving direction of the cart
|
-- dir: New moving direction of the cart
|
||||||
-- switch_keys: Currently pressed L(1) or R(2) key,
|
-- switch_keys: Currently pressed L(1) or R(2) key,
|
||||||
-- used to ignore the key on the next rail node
|
-- used to ignore the key on the next rail node
|
||||||
local dir, switch_keys = boost_cart:get_rail_direction(
|
local switch_keys
|
||||||
pos, cart_dir, ctrl, self.old_switch, self.railtype
|
dir, switch_keys = boost_cart:get_rail_direction(
|
||||||
|
pos, dir, ctrl, self.old_switch, self.railtype
|
||||||
)
|
)
|
||||||
local dir_changed = not vector.equals(dir, self.old_dir)
|
dir_changed = not vector.equals(dir, self.old_dir)
|
||||||
|
|
||||||
local acc = 0
|
local acc = 0
|
||||||
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
||||||
|
dir = vector.new(self.old_dir)
|
||||||
vel = {x=0, y=0, z=0}
|
vel = {x=0, y=0, z=0}
|
||||||
local pos_r = vector.round(pos)
|
local pos_r = vector.round(pos)
|
||||||
if not boost_cart:is_rail(pos_r, self.railtype)
|
if not boost_cart:is_rail(pos_r, self.railtype)
|
||||||
and self.old_pos then
|
and self.old_pos then
|
||||||
pos = self.old_pos
|
pos = self.old_pos
|
||||||
elseif not stop_wiggle then
|
elseif not stop_wiggle then
|
||||||
|
-- End of rail: Smooth out.
|
||||||
pos = pos_r
|
pos = pos_r
|
||||||
|
dir_changed = false
|
||||||
|
dir.y = 0
|
||||||
else
|
else
|
||||||
pos.y = math.floor(pos.y + 0.5)
|
pos.y = math.floor(pos.y + 0.5)
|
||||||
end
|
end
|
||||||
@ -319,7 +317,7 @@ function cart_entity:on_step(dtime)
|
|||||||
|
|
||||||
if acc then
|
if acc then
|
||||||
-- Slow down or speed up, depending on Y direction
|
-- Slow down or speed up, depending on Y direction
|
||||||
acc = acc + dir.y * -2.1
|
acc = acc + dir.y * -4
|
||||||
else
|
else
|
||||||
acc = 0
|
acc = 0
|
||||||
end
|
end
|
||||||
@ -338,13 +336,8 @@ function cart_entity:on_step(dtime)
|
|||||||
self.object:set_acceleration(vector.multiply(dir, acc))
|
self.object:set_acceleration(vector.multiply(dir, acc))
|
||||||
|
|
||||||
self.old_pos = vector.round(pos)
|
self.old_pos = vector.round(pos)
|
||||||
local old_y_dir = self.old_dir.y
|
local old_y_dir = self.old_dir.y -- For player tilt
|
||||||
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then
|
self.old_dir = vector.new(dir)
|
||||||
self.old_dir = dir
|
|
||||||
else
|
|
||||||
-- Cart stopped, set the animation to 0
|
|
||||||
self.old_dir.y = 0
|
|
||||||
end
|
|
||||||
self.old_switch = switch_keys
|
self.old_switch = switch_keys
|
||||||
|
|
||||||
boost_cart:on_rail_step(self, self.old_pos, distance)
|
boost_cart:on_rail_step(self, self.old_pos, distance)
|
||||||
@ -371,8 +364,6 @@ function cart_entity:on_step(dtime)
|
|||||||
if not (update.vel or update.pos) then
|
if not (update.vel or update.pos) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Re-use "dir", localize self.old_dir
|
|
||||||
dir = self.old_dir
|
|
||||||
|
|
||||||
local yaw = 0
|
local yaw = 0
|
||||||
if dir.x < 0 then
|
if dir.x < 0 then
|
||||||
|
@ -10,19 +10,26 @@ function boost_cart:manage_attachment(player, obj)
|
|||||||
if not player then
|
if not player then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local wants_attach = obj ~= nil
|
local do_attach = obj ~= nil
|
||||||
local attached = player:get_attach() ~= nil
|
|
||||||
|
|
||||||
if attached == wants_attach then
|
if obj and player:get_attach() == obj then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
if boost_cart.PLAYER_API then
|
||||||
boost_cart.player_attached[player_name] = wants_attach
|
local player_name = player:get_player_name()
|
||||||
|
player_api.player_attached[player_name] = do_attach
|
||||||
|
end
|
||||||
|
|
||||||
if wants_attach then
|
if do_attach then
|
||||||
player:set_attach(obj, "", {x=0, y=-4, z=0}, {x=0, y=0, z=0})
|
player:set_attach(obj, "", {x=0, y=-4, z=0}, {x=0, y=0, z=0})
|
||||||
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
|
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
|
||||||
|
|
||||||
|
if boost_cart.PLAYER_API then
|
||||||
|
-- player_api does not update the animation
|
||||||
|
-- when the player is attached, reset to default animation
|
||||||
|
player_api.set_animation(player, "stand")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
||||||
|
8
init.lua
8
init.lua
@ -9,7 +9,6 @@ boost_cart.modpath = minetest.get_modpath("boost_cart")
|
|||||||
boost_cart.MESECONS = minetest.global_exists("mesecon")
|
boost_cart.MESECONS = minetest.global_exists("mesecon")
|
||||||
boost_cart.MTG_CARTS = minetest.global_exists("carts") and carts.pathfinder
|
boost_cart.MTG_CARTS = minetest.global_exists("carts") and carts.pathfinder
|
||||||
boost_cart.PLAYER_API = minetest.global_exists("player_api")
|
boost_cart.PLAYER_API = minetest.global_exists("player_api")
|
||||||
boost_cart.player_attached = {}
|
|
||||||
|
|
||||||
local function getNum(setting)
|
local function getNum(setting)
|
||||||
return tonumber(minetest.settings:get(setting))
|
return tonumber(minetest.settings:get(setting))
|
||||||
@ -20,14 +19,9 @@ boost_cart.speed_max = getNum("boost_cart.speed_max") or 10
|
|||||||
-- Set to -1 to disable punching the cart from inside
|
-- Set to -1 to disable punching the cart from inside
|
||||||
boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7
|
boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7
|
||||||
-- Maximal distance for the path correction (for dtime peaks)
|
-- Maximal distance for the path correction (for dtime peaks)
|
||||||
boost_cart.path_distance_max = 3
|
boost_cart.path_distance_max = 4
|
||||||
|
|
||||||
|
|
||||||
if boost_cart.PLAYER_API then
|
|
||||||
-- This is a table reference!
|
|
||||||
boost_cart.player_attached = player_api.player_attached
|
|
||||||
end
|
|
||||||
|
|
||||||
dofile(boost_cart.modpath.."/functions.lua")
|
dofile(boost_cart.modpath.."/functions.lua")
|
||||||
dofile(boost_cart.modpath.."/rails.lua")
|
dofile(boost_cart.modpath.."/rails.lua")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user