1
0
mirror of https://github.com/SmallJoker/boost_cart.git synced 2025-07-16 07:10:23 +02:00

Compare commits

...

9 Commits

Author SHA1 Message Date
e458734cc5 Import two my MTG commits for better driving experience
Takes the changes from MTG commit 38307da and 71ea0c6
2022-06-03 20:41:33 +02:00
3bd7d6f8ca Fix item pickups not working sometimes 2021-08-14 16:51:37 +02:00
b05a49afb5 Fix 0/0 condition on faulty tool capabilities 2021-05-02 15:01:58 +02:00
5b53183381 Descend from cart using sneak (#31) 2020-05-30 09:08:54 +02:00
56f5b18dae Fix item collection
Broken since 5.3.0-dev

Co-authored-by: SmallJoker <mk939@ymail.com>
2020-05-29 19:14:16 +02:00
c8f7cae2c8 Set driver to nil (like before)
The driver variable is not handled by boost_cart:manage_attachment
2020-05-16 19:13:26 +02:00
30f870e88c Reset player view and attachment table on death 2020-05-15 19:02:38 +02:00
cc293e95fe Fix model animations after detach, remove README.txt 2019-11-26 19:41:18 +01:00
f7a649e596 Convert README to Markdown (#30)
Based on work by @Panquesito7
2019-11-20 19:22:02 +01:00
6 changed files with 107 additions and 102 deletions

3
.gitignore vendored Normal file
View File

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

50
README.md Normal file
View File

@ -0,0 +1,50 @@
# Boost Cart
Based on (and fully compatible with) the mod "carts" by PilzAdam
and the one contained in the subgame "minetest_game".
Target: Run smoothly as possible, even on laggy servers.
## Features
- A fast cart for your railway or roller coaster
- Easily configurable cart speed using the Advanced Settings
- Boost and brake rails
- By mesecons controlled Start-Stop rails
- Detector rails that send a mesecons signal when the cart drives over them
- Rail junction switching with the 'right/left' walking keys
- Handbrake with the 'back' key
- Support for non-minetest_game subgames
- Descend from cart using the `sneak` key
## Settings
This mod can be adjusted to fit the preference of a player or server. Use the `Settings -> All Settings` dialog in the main menu or tune your
minetest.conf file manually:
#### `boost_cart.speed_max = 10`
* Maximal speed of the cart in m/s
* Possible values: 1 ... 100
#### `boost_cart.punch_speed_max = 7`
* Maximal speed to which the driving player can accelerate the cart by punching from inside the cart.
* Possible values: -1 ... 100
* Value `-1` will disable this feature.
## License for everything
CC-0, if not specified otherwise below
Authors
---------
Various authors
- carts_rail_*.png
kddekadenz
- cart_bottom.png
- cart_side.png
- cart_top.png
klankbeeld (CC-BY 3.0)
- http://freesound.org/people/klankbeeld/sounds/174042/
- cart_rail.*.ogg
Zeg9
- cart.x
- cart.png

View File

@ -1,57 +0,0 @@
Minetest mod: boost_cart
==========================
Based on (and fully compatible with) the mod "carts" by PilzAdam
and the one contained in the subgame "minetest_game".
Target: Run smoothly as possible, even on laggy servers.
Features
----------
- A fast cart for your railway or roller coaster
- Easily configurable cart speed using the Advanced Settings
- Boost and brake rails
- By mesecons controlled Start-Stop rails
- Detector rails that send a mesecons signal when the cart drives over them
- Rail junction switching with the 'right/left' walking keys
- Handbrake with the 'back' key
- Support for non-minetest_game subgames
Settings
----------
This mod can be adjusted to fit the conditions of a player or server.
Use the Advanced Settings dialog in the main menu or tune your
minetest.conf file manually:
boost_cart.speed_max = 10
^ Possible values: 1 ... 100
^ Maximal speed of the cart in m/s
boost_cart.punch_speed_max = 7
^ Possible values: -1 ... 100
^ Maximal speed to which the driving player can accelerate the cart
by punching from inside the cart. -1 will disable this feature.
License for everything
------------------------
CC-0, if not specified otherwise below
Authors
---------
Various authors
carts_rail_*.png
kddekadenz
cart_bottom.png
cart_side.png
cart_top.png
klankbeeld (CC-BY 3.0)
http://freesound.org/people/klankbeeld/sounds/174042/
cart_rail.*.ogg
Zeg9
cart.x
cart.png

View File

@ -49,17 +49,10 @@ 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
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
self.driver = player_name
end
end
@ -94,6 +87,7 @@ 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
end
end
@ -126,8 +120,13 @@ 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
if obj_ then
local ent = obj_ and obj_:get_luaentity()
if ent then
obj_:set_detach()
-- Attention! Internal item API
if ent.enable_physics then
ent:enable_physics()
end
end
end
@ -155,7 +154,8 @@ function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities,
end
local punch_interval = 1
if tool_capabilities and tool_capabilities.full_punch_interval then
-- 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
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 +178,11 @@ function cart_entity:on_step(dtime)
end
local pos = self.object:get_pos()
local cart_dir = boost_cart:velocity_to_dir(vel)
local same_dir = vector.equals(cart_dir, self.old_dir)
local dir = boost_cart:velocity_to_dir(vel)
local dir_changed = not vector.equals(dir, self.old_dir)
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_old = vector.round(self.old_pos)
if vector.equals(flo_pos, flo_old) then
@ -203,7 +203,7 @@ function cart_entity:on_step(dtime)
end
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?)
-- It's sophisticated enough to take the acceleration in account
local acc = self.object:get_acceleration()
@ -218,7 +218,7 @@ function cart_entity:on_step(dtime)
-- No rail found: set to the expected position
pos = new_pos
update.pos = true
cart_dir = new_dir
dir = new_dir
end
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
-- Stop wiggle
@ -228,20 +228,25 @@ 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 dir, switch_keys = boost_cart:get_rail_direction(
pos, cart_dir, ctrl, self.old_switch, self.railtype
local switch_keys
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
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
@ -303,10 +308,16 @@ function cart_entity:on_step(dtime)
acc = -0.4
end
end
if ctrl and ctrl.sneak then
-- Descend when sneak is pressed
boost_cart:manage_attachment(player, nil)
player = nil
ctrl = nil
end
if acc then
-- Slow down or speed up, depending on Y direction
acc = acc + dir.y * -2.1
acc = acc + dir.y * -4
else
acc = 0
end
@ -325,13 +336,8 @@ 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
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
local old_y_dir = self.old_dir.y -- For player tilt
self.old_dir = vector.new(dir)
self.old_switch = switch_keys
boost_cart:on_rail_step(self, self.old_pos, distance)
@ -339,10 +345,13 @@ function cart_entity:on_step(dtime)
if self.punched then
-- Collect dropped items
for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if not obj_:is_player() and
obj_:get_luaentity() and
not obj_:get_luaentity().physical_state and
obj_:get_luaentity().name == "__builtin:item" then
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
-- Check API to support 5.2.0 and older
if ent.disable_physics then
ent:disable_physics()
end
obj_:set_attach(self.object, "", {x=0, y=0, z=0}, {x=0, y=0, z=0})
self.attached_items[#self.attached_items + 1] = obj_
@ -355,8 +364,6 @@ 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,18 +10,26 @@ function boost_cart:manage_attachment(player, obj)
if not player then
return
end
local wants_attach = obj ~= nil
local attached = player:get_attach() ~= nil
local do_attach = obj ~= nil
local player_name = player:get_player_name()
boost_cart.player_attached[player_name] = attached or wants_attach
if attached == wants_attach then
if obj and player:get_attach() == obj then
return
end
if wants_attach then
if boost_cart.PLAYER_API then
local player_name = player:get_player_name()
player_api.player_attached[player_name] = do_attach
end
if do_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,7 +9,6 @@ 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))
@ -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
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 = 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.."/rails.lua")