Compare commits

..

No commits in common. "master" and "nalc-1.2.0" have entirely different histories.

4 changed files with 44 additions and 45 deletions

3
.gitignore vendored
View File

@ -1,3 +0,0 @@
*.bak
*.diff
*.patch

View File

@ -49,10 +49,17 @@ function cart_entity:on_rightclick(clicker)
end
local player_name = clicker:get_player_name()
if self.driver and player_name == self.driver then
self.driver = nil
boost_cart:manage_attachment(clicker, nil)
elseif not self.driver then
boost_cart:manage_attachment(clicker, self.object)
self.driver = player_name
boost_cart:manage_attachment(clicker, self.object)
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
@ -87,8 +94,8 @@ end
-- 0.5.x and later: When the driver leaves
function cart_entity:on_detach_child(child)
if child and child:get_player_name() == self.driver then
boost_cart:manage_attachment(child, nil)
self.driver = nil
boost_cart:manage_attachment(child, nil)
end
end
@ -120,13 +127,8 @@ function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities,
boost_cart:manage_attachment(player, nil)
end
for _, obj_ in pairs(self.attached_items) do
local ent = obj_ and obj_:get_luaentity()
if ent then
if obj_ then
obj_:set_detach()
-- Attention! Internal item API
if ent.enable_physics then
ent:enable_physics()
end
end
end
@ -154,8 +156,7 @@ function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities,
end
local punch_interval = 1
-- Faulty tool registrations may cause the interval to be set to 0 !
if tool_capabilities and (tool_capabilities.full_punch_interval or 0) > 0 then
if tool_capabilities and tool_capabilities.full_punch_interval then
punch_interval = tool_capabilities.full_punch_interval
end
time_from_last_punch = math.min(time_from_last_punch or punch_interval, punch_interval)
@ -178,11 +179,11 @@ function cart_entity:on_step(dtime)
end
local pos = self.object:get_pos()
local dir = boost_cart:velocity_to_dir(vel)
local dir_changed = not vector.equals(dir, self.old_dir)
local cart_dir = boost_cart:velocity_to_dir(vel)
local same_dir = vector.equals(cart_dir, self.old_dir)
local update = {}
if self.old_pos and not self.punched and not dir_changed then
if self.old_pos and not self.punched and same_dir then
local flo_pos = vector.round(pos)
local flo_old = vector.round(self.old_pos)
if vector.equals(flo_pos, flo_old) then
@ -203,7 +204,7 @@ function cart_entity:on_step(dtime)
end
local stop_wiggle = false
if self.old_pos and not dir_changed then
if self.old_pos and same_dir then
-- Detection for "skipping" nodes (perhaps use average dtime?)
-- It's sophisticated enough to take the acceleration in account
local acc = self.object:get_acceleration()
@ -218,7 +219,7 @@ function cart_entity:on_step(dtime)
-- No rail found: set to the expected position
pos = new_pos
update.pos = true
dir = new_dir
cart_dir = new_dir
end
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
-- Stop wiggle
@ -228,25 +229,20 @@ function cart_entity:on_step(dtime)
-- dir: New moving direction of the cart
-- switch_keys: Currently pressed L(1) or R(2) key,
-- used to ignore the key on the next rail node
local switch_keys
dir, switch_keys = boost_cart:get_rail_direction(
pos, dir, ctrl, self.old_switch, self.railtype
local dir, switch_keys = boost_cart:get_rail_direction(
pos, cart_dir, ctrl, self.old_switch, self.railtype
)
dir_changed = not vector.equals(dir, self.old_dir)
local dir_changed = not vector.equals(dir, self.old_dir)
local acc = 0
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}
local pos_r = vector.round(pos)
if not boost_cart:is_rail(pos_r, self.railtype)
and self.old_pos then
pos = self.old_pos
elseif not stop_wiggle then
-- End of rail: Smooth out.
pos = pos_r
dir_changed = false
dir.y = 0
else
pos.y = math.floor(pos.y + 0.5)
end
@ -317,7 +313,7 @@ function cart_entity:on_step(dtime)
if acc then
-- Slow down or speed up, depending on Y direction
acc = acc + dir.y * -4
acc = acc + dir.y * -2.1
else
acc = 0
end
@ -336,8 +332,13 @@ function cart_entity:on_step(dtime)
self.object:set_acceleration(vector.multiply(dir, acc))
self.old_pos = vector.round(pos)
local old_y_dir = self.old_dir.y -- For player tilt
self.old_dir = vector.new(dir)
local old_y_dir = self.old_dir.y
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then
self.old_dir = dir
else
-- Cart stopped, set the animation to 0
self.old_dir.y = 0
end
self.old_switch = switch_keys
boost_cart:on_rail_step(self, self.old_pos, distance)
@ -346,8 +347,8 @@ function cart_entity:on_step(dtime)
-- Collect dropped items
for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local ent = obj_:get_luaentity()
-- Attention! Physics must be disabled prior to attach
if ent and ent.name == "__builtin:item" and not obj_:get_attach() then
-- Careful here: physical_state and disable_physics are item-internal APIs
if ent and ent.name == "__builtin:item" and ent.physical_state then
-- Check API to support 5.2.0 and older
if ent.disable_physics then
ent:disable_physics()
@ -364,6 +365,8 @@ function cart_entity:on_step(dtime)
if not (update.vel or update.pos) then
return
end
-- Re-use "dir", localize self.old_dir
dir = self.old_dir
local yaw = 0
if dir.x < 0 then

View File

@ -10,26 +10,19 @@ function boost_cart:manage_attachment(player, obj)
if not player then
return
end
local do_attach = obj ~= nil
local wants_attach = obj ~= nil
local attached = player:get_attach() ~= nil
if obj and player:get_attach() == obj then
if attached == wants_attach then
return
end
if boost_cart.PLAYER_API then
local player_name = player:get_player_name()
player_api.player_attached[player_name] = do_attach
end
local player_name = player:get_player_name()
boost_cart.player_attached[player_name] = wants_attach
if do_attach then
if wants_attach then
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})
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
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})

View File

@ -9,6 +9,7 @@ boost_cart.modpath = minetest.get_modpath("boost_cart")
boost_cart.MESECONS = minetest.global_exists("mesecon")
boost_cart.MTG_CARTS = minetest.global_exists("carts") and carts.pathfinder
boost_cart.PLAYER_API = minetest.global_exists("player_api")
boost_cart.player_attached = {}
local function getNum(setting)
return tonumber(minetest.settings:get(setting))
@ -19,9 +20,14 @@ boost_cart.speed_max = getNum("boost_cart.speed_max") or 10
-- Set to -1 to disable punching the cart from inside
boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7
-- Maximal distance for the path correction (for dtime peaks)
boost_cart.path_distance_max = 4
boost_cart.path_distance_max = 3
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.."/rails.lua")