Compare commits

...

94 Commits
mff ... master

Author SHA1 Message Date
SmallJoker e4edb96d30 Use initial_properties, backup old_pos for loading 2018-09-01 14:49:16 +02:00
SmallJoker 3386942d71 Add basic documentation 2018-07-30 17:16:14 +02:00
SmallJoker d486143f42 Reset acceleration at speed limit 2018-07-07 15:23:30 +02:00
SmallJoker 34155473a9 Fix controls not working when going uphill 2018-07-04 22:04:55 +02:00
SmallJoker 7e275e1985 Disallow rail switching up/downhill 2018-07-04 21:23:06 +02:00
SmallJoker c6b9e4b672 Various improvements and bugfixes
Clear driver on leave using the detach callback (0.5.x and later)
Fix upright_sprite attachment position
Fallback to the regular node sound when metal does not exist
Set animation to "stand" on attach
2018-05-12 11:36:00 +02:00
SmallJoker 3781f6d4c0 Make moreores' copper rail connect again, add metal sounds 2018-05-04 14:38:52 +02:00
SmallJoker f4c1a2ec3b Fix edge case crash due nil old_pos, remove player_api warning 2018-01-15 18:41:40 +01:00
SmallJoker 57d09fac79 Revert velocity calculation change from e3688b5
Accelerates carts too much when going up/downhill
Caused by wrong vector length calculation. This will need to be altered again if there will be 45° rails
2017-11-28 18:33:37 +01:00
SmallJoker 49028ca123 More weight, Handbrake + Railparams, animation fix
Slightly higher (2 -> 2.1) weight impact on slopes
Sum up rail param speed and handbrake
Fix animation when driving slowly towards a slope, turning and stopping on that slope
2017-11-24 17:07:36 +01:00
SmallJoker ca55c6f3c0 Change Y rotation from 45° to 30°. Only send velocity when required.
Smoother position correction when the X,Y,Z directions weren't changed
2017-11-18 12:38:25 +01:00
SmallJoker 4498605509 Hacky bugfix: Force updating player attachment rotation after detach 2017-11-06 17:38:20 +01:00
SmallJoker e19d8701ce Reduce eye position, rotation update frequency 2017-10-28 17:22:47 +02:00
SmallJoker 9a2a2b9d69 Correct feet position for rotated model 2017-10-27 12:51:26 +02:00
SmallJoker 6ac106c1a7 Pitch-Rotate player model and unblock downwards-going view 2017-10-27 12:40:27 +02:00
SmallJoker be0c56edef Pathfinder: Fix bounce back effect at rail end 2017-10-14 11:28:05 +02:00
SmallJoker 5502952bbd Fix rail counting in on_rail_step, localize API functions for faster access 2017-10-13 15:27:06 +02:00
SmallJoker ad93d338b3 Better wiggle prevention when stopping the cart 2017-10-09 12:55:50 +02:00
SmallJoker e3688b5380 Pathfinder: Auto-correct position on failure (smoother)
Dynamic pathfinder distance, depending on speed and dtime
Replace various deprecated function names
2017-10-09 11:09:17 +02:00
SmallJoker 2229ededa5 Remove settings legacy, require 0.4.15-dev or newer 2017-10-03 08:35:20 +02:00
SmallJoker e8119a63cd README: Add the settings for server owners, minor edits.
Drop 0.4.12 compatibility
2017-08-13 10:58:04 +02:00
SmallJoker 11a1ebad74 Correct the player attachment position for the new player model
Requires the player_api mod to 'detect' the new model
2017-08-13 10:15:03 +02:00
SmallJoker 3c646ee4df Pathfinder: Also use the last computed position prediction 2017-07-29 09:51:09 +02:00
SmallJoker af25c5411b Use minetest.raillike_group, do not connect rails with other raillike 2017-07-01 10:48:14 +02:00
SmallJoker b80d3aed4c Make the maximal speed configurable using minetest.conf 2017-06-09 22:25:58 +02:00
SmallJoker 08918701b0 Add mod.conf 2017-05-28 19:42:50 +02:00
SmallJoker 66e4613432 Overwrite carts:rail instead of default:rail if existing (#17) 2017-05-26 20:43:29 +02:00
SmallJoker 61b19d77d9 Start-stop rail: Do not stop when punching
Reported/requested in: https://forum.minetest.net/viewtopic.php?p=270534#p270534
2017-05-21 20:43:42 +02:00
SmallJoker acf697cd43 Fix crash caused by stop rail and 8b4487c (#15) 2017-03-28 18:01:42 +02:00
SmallJoker 8b4487c2b8 Revert cart gravity from 2.5 to 2
Allows 50% powerrail-rail mix to transport the cart in an 45° angle
2017-03-23 21:02:52 +01:00
SmallJoker cba969903a register_rail: Fix the table overwrite behaviour 2017-02-12 11:35:54 +01:00
SmallJoker 71af46f027 Use MTG cart model and textures in compability mode 2016-12-02 20:55:13 +01:00
SmallJoker 99d0480169 Rails: Make names consistent and redo all rail textures
Add rail templates
2016-11-27 13:00:39 +01:00
SmallJoker de5fb1825a Fix jerky movement on punch 2016-11-26 21:13:33 +01:00
SmallJoker cf9b82de37 Huge rewrite
Add sounds
Change Y acceleration to -2.5
Add partwise compatibility for MTG-registered rails
2016-11-22 20:36:00 +01:00
SmallJoker 74d8b8f931 Remove unused vector.floor, check if cart is centered on rail
Fix cart wiggle/swing partwise
Simplify the curve velocity calculations
2016-11-19 19:37:13 +01:00
SmallJoker 75132269d7 Fix forgotten variable to rename 2016-10-26 19:48:05 +02:00
SmallJoker b741282843 Do not take cart from inventory in creative mode
Correct comments and move some variables
2016-10-12 17:22:49 +02:00
SmallJoker 7d6132e748 Fix mesecon variable bug caused by f3bc9d7 2016-08-12 20:44:49 +02:00
SmallJoker 4391d2356f Update the readme 2016-08-11 18:59:51 +02:00
SmallJoker 5526754e37 Add description and screenshot, run OptiPNG 2016-08-11 10:56:51 +02:00
Stefan Sauer f3bc9d795d Fix undeclared global variable "mesecon" 2016-08-09 09:30:16 +02:00
SmallJoker eb6a833b66 Break too long lines and simplify the code
- Add boost_cart:get_rail_groups to get the default rail groups
- Remove duplicated code
- Do not boost the cart backwards when the brake rail gets activated
- Attempt to fix the cart swing problem
- Trim tailings and tidy up code
- TODO: Document all the stuff
2016-07-22 11:07:00 +02:00
Christopher Head d166b7ea68
Add start-stop rail. 2016-07-21 22:46:20 -07:00
SmallJoker 947d8633ff Make a stopped cart resume in its last direction
Largely based on PR #10. Thanks to @Hawk777 for this tweak

- Fix player rotation when cart stopped (or punched the first time)
2016-07-21 13:21:54 +02:00
Christopher Head 9d059b8e31
Rename a parameter to match its purpose. 2016-07-20 00:14:54 -07:00
SmallJoker cbe0ab9770 Check for regular behavior too
- HAAAAAAAANDS
2016-07-04 20:56:49 +02:00
SmallJoker d63f8ae024 Add pathfinding function (pilot version!)
- Add more comments
2016-07-04 20:34:52 +02:00
SmallJoker 46c03dd4d1 Attempt to fix: Cart not working after re-login 2016-06-20 19:16:57 +02:00
SmallJoker d54ca696c5 Add setting 'punch_speed_min'
Allow to disable the self-acceleration from inside the cart
2016-04-15 09:45:26 +02:00
SmallJoker 3cac3d8701 Add Sneak+Click info to cart description 2016-01-05 17:04:02 +01:00
SmallJoker 73722136a0 Drop cart when inventory is filled 2015-12-23 21:08:29 +01:00
SmallJoker 307b5d1f92 Adjust 3rd person eye height 2015-12-20 23:15:40 +01:00
SmallJoker 6e01bf2bf9 Early XMAS gift for those who can not install mods correctly 2015-11-13 23:11:08 +01:00
SmallJoker 1b53ebd8e6 Fix typo 2015-11-01 20:12:16 +01:00
SmallJoker ddb6801b5c Fix detector crafting recipe 2015-09-29 18:20:46 +02:00
SmallJoker 145ca1c61d Fix nil error on tool_capabilities 2015-09-13 19:32:45 +02:00
Craig Davison afb52ba3b4 Re-add groups to the powerrail and brakerail
Accidentally removed in a7fd733819
2015-06-24 21:09:27 +01:00
SmallJoker d58f9930d1 Fix player_attached error on some subgames 2015-06-05 20:30:48 +02:00
SmallJoker a7fd733819 Add boost_cart:register_rail(name, def) 2015-06-05 20:00:53 +02:00
number Zero adfcfe0841 Detector rail added
Neated the code
2015-06-05 19:46:16 +02:00
SmallJoker 79905e47f4 Prevent from getting suck in walls while moving up 2015-03-30 20:49:56 +02:00
SmallJoker 159d4ec603 Punch cart if mesecon signal is received 2015-03-22 10:52:48 +01:00
SmallJoker df04aa2a4d Fix different railtype problem 2015-03-15 14:57:53 +01:00
SmallJoker 670f961d35 Allow different railtypes 2015-03-15 13:09:02 +01:00
SmallJoker eb610a5e9c Punch update - wat? 2015-02-03 11:00:00 +01:00
SmallJoker f88f0be7ec Run OptiPNG 2015-01-20 20:06:22 +01:00
SmallJoker 1aaa83b428 Fix item pickup 2015-01-11 12:00:17 +01:00
SmallJoker b6d17c1b34 Allow to stop cart by punching against the moving direction 2015-01-11 11:57:49 +01:00
SmallJoker 573d56de1a More use of default.player_attached 2014-11-08 20:11:51 +01:00
SmallJoker 2929d2ceb7 Confinue driving 2014-11-08 20:05:03 +01:00
SmallJoker 717721c912 Add moreores compatibility 2014-11-08 11:06:12 +01:00
SmallJoker b6f476db37 Do not update everytime 2014-10-26 12:04:05 +01:00
SmallJoker a59864dd74 Transport items; do not remove carts in walls 2014-10-25 18:49:28 +02:00
SmallJoker 5373a05c9a Cleanup. 2014-09-20 22:52:23 +02:00
SmallJoker 0fa8c88574 One '\t' more 2014-09-14 08:59:54 +02:00
SmallJoker f52e4e3641 This happens when coding to fast and without testing. 2014-08-10 17:22:46 +02:00
SmallJoker faaa422fae Add this. 2014-08-10 17:03:40 +02:00
SmallJoker c8f03513e3 Better handbrake and fix punch bug 2014-08-10 14:03:13 +02:00
SmallJoker 21e309c414 Shorter codes, allow left/right-down 2014-08-09 18:42:54 +02:00
SmallJoker c07c92a1fb Crafting is needed! 2014-08-09 17:47:58 +02:00
SmallJoker 3d0401f633 Fail demon was here. 2014-08-09 17:38:41 +02:00
SmallJoker 59b1512cc3 Allow switching with keys 2014-08-09 17:37:02 +02:00
SmallJoker 70f07f4158 less gravity, more speed up/slow down 2014-08-07 13:40:10 +02:00
SmallJoker c106499bd5 Lowered chance to get stuck 2014-08-07 09:54:25 +02:00
SmallJoker fa2f2cb71c Remove this line. 2014-08-04 19:08:01 +02:00
SmallJoker 64fa36e796 Using carts:cart, add copper/brk/pwr rails 2014-08-04 19:06:02 +02:00
SmallJoker 8280738bf6 Debug line detected 2014-08-01 17:45:51 +02:00
SmallJoker 4652679f7d I hopeit's fixed now. 2014-08-01 17:45:07 +02:00
SmallJoker 007037c633 test. 2014-08-01 16:16:57 +02:00
SmallJoker a38aa7d83b Is it really stuck-secure? 2014-08-01 15:59:11 +02:00
SmallJoker dc20f048b1 better, I don't know. 2014-08-01 15:25:48 +02:00
SmallJoker 6332c670d9 more fix? 2014-07-29 12:51:57 +02:00
SmallJoker e8a8ad4324 updates 2014-07-29 11:58:03 +02:00
47 changed files with 1060 additions and 300 deletions

View File

@ -1,23 +1,57 @@
Minetest mod: boost_cart
=======================
Based on the mod "carts" by PilzAdam
Target: Run smoothly and do not use too much CPU
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.
License of source code:
-----------------------
WTFPL
License of media (textures, sounds and models):
-----------------------------------------------
CC-0
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
Authors of media files:
-----------------------
kddekadenz:
cart_bottom.png
cart_side.png
cart_top.png
Zeg9:
cart.x
cart.png
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

452
cart_entity.lua Normal file
View File

@ -0,0 +1,452 @@
local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon")
function boost_cart:on_rail_step(entity, pos, distance)
-- Play rail sound
if entity.sound_counter <= 0 then
minetest.sound_play("cart_rail", {
pos = pos,
max_hear_distance = 40,
gain = 0.5
})
entity.sound_counter = math.random(4, 15)
end
entity.sound_counter = entity.sound_counter - distance
if HAVE_MESECONS_ENABLED then
boost_cart:signal_detector_rail(pos)
end
end
local cart_entity = {
initial_properties = {
physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "mesh",
mesh = "cart.x",
visual_size = {x=1, y=1},
textures = {"cart.png"},
},
driver = nil,
punched = false, -- used to re-send velocity and position
velocity = {x=0, y=0, z=0}, -- only used on punch
old_dir = {x=1, y=0, z=0}, -- random value to start the cart on punch
old_pos = nil,
old_switch = 0,
sound_counter = 0,
railtype = nil,
attached_items = {}
}
-- Model and textures
if boost_cart.mtg_compat then
cart_entity.initial_properties.mesh = "carts_cart.b3d"
cart_entity.initial_properties.textures = {"carts_cart.png"}
end
function cart_entity:on_rightclick(clicker)
if not clicker or not clicker:is_player() then
return
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
end
end
function cart_entity:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1})
self.sound_counter = math.random(4, 15)
if string.sub(staticdata, 1, string.len("return")) ~= "return" then
return
end
local data = minetest.deserialize(staticdata)
if type(data) ~= "table" then
return
end
self.railtype = data.railtype
self.old_dir = data.old_dir or self.old_dir
self.old_pos = data.old_pos or self.old_pos
-- Correct the position when the cart drives further after the last 'step()'
if self.old_pos and boost_cart:is_rail(self.old_pos, self.railtype) then
self.object:set_pos(self.old_pos)
end
end
function cart_entity:get_staticdata()
return minetest.serialize({
railtype = self.railtype,
old_dir = self.old_dir,
old_pos = self.old_pos
})
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
self.driver = nil
end
end
function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
local pos = self.object:get_pos()
local vel = self.object:get_velocity()
if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) then
local node = minetest.get_node(pos).name
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
end
if not puncher or not puncher:is_player() then
local cart_dir = boost_cart:get_rail_direction(pos, self.old_dir, nil, nil, self.railtype)
if vector.equals(cart_dir, {x=0, y=0, z=0}) then
return
end
self.velocity = vector.multiply(cart_dir, 3)
self.punched = true
return
end
if puncher:get_player_control().sneak then
-- Pick up cart: Drop all attachments
if self.driver then
if self.old_pos then
self.object:set_pos(self.old_pos)
end
local player = minetest.get_player_by_name(self.driver)
boost_cart:manage_attachment(player, nil)
end
for _, obj_ in pairs(self.attached_items) do
if obj_ then
obj_:set_detach()
end
end
local leftover = puncher:get_inventory():add_item("main", "carts:cart")
if not leftover:is_empty() then
minetest.add_item(pos, leftover)
end
self.object:remove()
return
end
-- Driver punches to accelerate the cart
if puncher:get_player_name() == self.driver then
if math.abs(vel.x + vel.z) > boost_cart.punch_speed_max then
return
end
end
local punch_dir = boost_cart:velocity_to_dir(puncher:get_look_dir())
punch_dir.y = 0
local cart_dir = boost_cart:get_rail_direction(pos, punch_dir, nil, nil, self.railtype)
if vector.equals(cart_dir, {x=0, y=0, z=0}) then
return
end
local punch_interval = 1
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)
local f = 3 * (time_from_last_punch / punch_interval)
self.velocity = vector.multiply(cart_dir, f)
self.old_dir = cart_dir
self.punched = true
end
local v3_len = vector.length
function cart_entity:on_step(dtime)
local vel = self.object:get_velocity()
if self.punched then
vel = vector.add(vel, self.velocity)
self.object:set_velocity(vel)
self.old_dir.y = 0
elseif vector.equals(vel, {x=0, y=0, z=0}) then
return
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 update = {}
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
-- Do not check one node multiple times
return
end
end
local ctrl, player
local distance = 1
-- Get player controls
if self.driver then
player = minetest.get_player_by_name(self.driver)
if player then
ctrl = player:get_player_control()
end
end
local stop_wiggle = false
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()
distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc))
local new_pos, new_dir = boost_cart:pathfinder(
pos, self.old_pos, self.old_dir, distance, ctrl,
self.old_switch, self.railtype
)
if new_pos then
-- No rail found: set to the expected position
pos = new_pos
update.pos = true
cart_dir = new_dir
end
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
-- Stop wiggle
stop_wiggle = true
end
-- 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 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
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
pos = pos_r
else
pos.y = math.floor(pos.y + 0.5)
end
update.pos = true
update.vel = true
else
-- Direction change detected
if dir_changed then
vel = vector.multiply(dir, math.abs(vel.x + vel.z))
update.vel = true
if dir.y ~= self.old_dir.y then
pos = vector.round(pos)
update.pos = true
end
end
-- Center on the rail
if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then
pos.x = math.floor(pos.x + 0.5)
update.pos = true
end
if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then
pos.z = math.floor(pos.z + 0.5)
update.pos = true
end
-- Calculate current cart acceleration
acc = nil
local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration")
if acc_meta == "halt" and not self.punched then
-- Stop rail
vel = {x=0, y=0, z=0}
acc = false
pos = vector.round(pos)
update.pos = true
update.vel = true
end
if acc == nil then
-- Meta speed modifier
local speed_mod = tonumber(acc_meta)
if speed_mod and speed_mod ~= 0 then
-- Try to make it similar to the original carts mod
acc = speed_mod * 10
end
end
if acc == nil and boost_cart.mtg_compat then
-- MTG Cart API adaption
local rail_node = minetest.get_node(vector.round(pos))
local railparam = carts.railparams[rail_node.name]
if railparam and railparam.acceleration then
acc = railparam.acceleration
end
end
if acc ~= false then
-- Handbrake
if ctrl and ctrl.down then
acc = (acc or 0) - 2
elseif acc == nil then
acc = -0.4
end
end
if acc then
-- Slow down or speed up, depending on Y direction
acc = acc + dir.y * -2.1
else
acc = 0
end
end
-- Limit cart speed
local vel_len = vector.length(vel)
if vel_len > boost_cart.speed_max then
vel = vector.multiply(vel, boost_cart.speed_max / vel_len)
update.vel = true
end
if vel_len >= boost_cart.speed_max and acc > 0 then
acc = 0
end
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
self.old_switch = switch_keys
boost_cart:on_rail_step(self, self.old_pos, distance)
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
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_
end
end
self.punched = false
update.vel = true
end
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
yaw = 0.5
elseif dir.x > 0 then
yaw = 1.5
elseif dir.z < 0 then
yaw = 1
end
self.object:set_yaw(yaw * math.pi)
local anim = {x=0, y=0}
if dir.y == -1 then
anim = {x=1, y=1}
elseif dir.y == 1 then
anim = {x=2, y=2}
end
self.object:set_animation(anim, 1, 0)
-- Change player model rotation, depending on the Y direction
if player and dir.y ~= old_y_dir then
local feet = {x=0, y=0, z=0}
local eye = {x=0, y=-4, z=0}
feet.y = boost_cart.old_player_model and 6 or -4
if dir.y ~= 0 then
-- TODO: Find a better way to calculate this
if boost_cart.old_player_model then
feet.y = feet.y + 2
feet.z = -dir.y * 6
else
feet.y = feet.y + 4
feet.z = -dir.y * 2
end
eye.z = -dir.y * 8
end
player:set_attach(self.object, "", feet,
{x=dir.y * -30, y=0, z=0})
player:set_eye_offset(eye, eye)
end
if update.vel then
self.object:set_velocity(vel)
end
if update.pos then
if dir_changed then
self.object:set_pos(pos)
else
self.object:move_to(pos)
end
end
end
minetest.register_entity(":carts:cart", cart_entity)
-- Register item to place the entity
if not boost_cart.mtg_compat then
minetest.register_craftitem(":carts:cart", {
description = "Cart (Sneak+Click to pick up)",
inventory_image = minetest.inventorycube(
"cart_top.png",
"cart_side.png",
"cart_side.png"
),
wield_image = "cart_side.png",
on_place = function(itemstack, placer, pointed_thing)
if not pointed_thing.type == "node" then
return
end
if boost_cart:is_rail(pointed_thing.under) then
minetest.add_entity(pointed_thing.under, "carts:cart")
elseif boost_cart:is_rail(pointed_thing.above) then
minetest.add_entity(pointed_thing.above, "carts:cart")
else
return
end
if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
})
minetest.register_craft({
output = "carts:cart",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
},
})
end

View File

@ -1 +1,4 @@
default
default
mesecons?
moreores?
carts?

1
description.txt Normal file
View File

@ -0,0 +1 @@
This mod offers improved minecarts and a few more rail types.

58
detector.lua Normal file
View File

@ -0,0 +1,58 @@
local mesecons_rules = mesecon.rules.flat
function boost_cart:turnoff_detector_rail(pos)
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name, "detector_rail") == 1 then
if node.name == "boost_cart:detectorrail_on" then --has not been dug
minetest.swap_node(pos, {name = "boost_cart:detectorrail", param2=node.param2})
end
mesecon.receptor_off(pos, mesecons_rules)
end
end
function boost_cart:signal_detector_rail(pos)
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name, "detector_rail") ~= 1 then
return
end
if node.name == "boost_cart:detectorrail" then
minetest.swap_node(pos, {name = "boost_cart:detectorrail_on", param2=node.param2})
end
mesecon.receptor_on(pos, mesecons_rules)
minetest.after(0.5, boost_cart.turnoff_detector_rail, boost_cart, pos)
end
boost_cart:register_rail("boost_cart:detectorrail", {
description = "Detector rail",
tiles = {
"carts_rail_straight_dtc.png", "carts_rail_curved_dtc.png",
"carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png"
},
groups = boost_cart:get_rail_groups({detector_rail = 1}),
mesecons = {receptor = {state = "off", rules = mesecons_rules}},
})
boost_cart:register_rail("boost_cart:detectorrail_on", {
description = "Detector rail ON (you hacker you)",
tiles = {
"carts_rail_straight_dtc_on.png", "carts_rail_curved_dtc_on.png",
"carts_rail_t_junction_dtc_on.png", "carts_rail_crossing_dtc_on.png"
},
groups = boost_cart:get_rail_groups({
detector_rail = 1, not_in_creative_inventory = 1
}),
drop = "boost_cart:detectorrail",
mesecons = {receptor = {state = "on", rules = mesecons_rules}},
})
minetest.register_craft({
output = "boost_cart:detectorrail 6",
recipe = {
{"default:steel_ingot", "mesecons:wire_00000000_off", "default:steel_ingot"},
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
{"default:steel_ingot", "mesecons:wire_00000000_off", "default:steel_ingot"},
},
})

71
doc/mod_api.txt Normal file
View File

@ -0,0 +1,71 @@
boost_cart API
==============
This file provides information about the API of boost_cart for the use in
mods. The API might change slightly when the development goes on, so avoid
using internal tables or functions which are not documented here.
Types
-----
* `SwitchIgnore` -> `number/nil`
* Specifies which player control was pressed. This value is used to prefer
straight rails instead of preferring left and right rail checks.
* `1`: Ignore left rail
* `2`: Ignore right rail
* `nil`: Ignore no rail
Entity movement
---------------
These functions are grouped so that they make sense and then sorted alphabetically.
* `boost_cart:manage_attachment(player, obj)`
* Attaches or detaches the player to/from an object, depending on what is
supplied to `obj`.
* `player`: `ObjectRef` of the player
* `obj`: `ObjectRef` (to attach) or `nil` (to detach)
* `boost_cart:get_sign(n)` -> `number`
* Returns the sign for the given number. Values: `-1`, `0`, `1`
* `n`: any `number`
* `boost_cart:velocity_to_dir(vel)` -> `vector`
* Returns the cart direction depending on `vel`. Each coordinate can have
one of the `get_sign()` return values.
* `vel`: velocity as `vector`
* `boost_cart:boost_rail(pos, amount)`
* Sets the rail acceleration for the given position to `amount` and punches
carts which are at the given position.
* `pos`: `vector`, rail position
* `amount`: `number`, negative to brake, positive to boost
* `boost_cart:get_rail_direction(pos, dir, ctrl, old_switch, railtype)`
-> `vector, SwitchIgnore`
* Returns the direction to where the next rail is, and which player control that
should be ignored in the next call.
* `pos`: `vector`, position of the cart
* `dir`: `vector`, movement direction of the cart (see `velocity_to_dir()`)
* `ctrl`: Player controls table or `nil` (no player)
* `old_switch`: `SwitchIgnore`
* `railtype`: (optional) `number`, gets passed indirectly to `is_rail()`
Rail helper functions
---------------------
* `boost_cart:get_rail_groups(groups)` -> `table`
* Returns a group table with preset values for a common rail node
* `groups`: (optional) `table`, additional groups append (or overwrite)
* Hint: To register an incompatible rail type, set the group
`connect_to_raillike` to the value returned by
`minetest.raillike_group(new_rail_type)`
* `boost_cart:is_rail(pos, [railtype])` -> `boolean`
* Returns whether the node at `pos` is a rail. When `railtype` is specified,
`true` is only returned when the node is in the same rail group.
* `pos`: `vector` of the node to check
* `railtype`: (optional) `number`, rail group number
* `boost_cart:register_rail(name, def)`
* Registers a new rail with preset node definition defaults as fallback
* `name`: `string`, node name of the new rail
* `def`: Node definition table, containing at least the following keys:
* `description`
* `groups`
* `tiles`

View File

@ -6,98 +6,264 @@ function boost_cart:get_sign(z)
end
end
function boost_cart:velocity_to_dir(v)
if math.abs(v.x) > math.abs(v.z) then
return {x=boost_cart:get_sign(v.x), y=boost_cart:get_sign(v.y), z=0}
function boost_cart:manage_attachment(player, obj)
if not player then
return
end
local status = obj ~= nil
local player_name = player:get_player_name()
if default.player_attached[player_name] == status then
return
end
default.player_attached[player_name] = status
if status then
local y_pos = self.old_player_model and 6 or -4
if player:get_properties().visual == "upright_sprite" then
y_pos = -4
end
player:set_attach(obj, "", {x=0, y=y_pos, z=0}, {x=0, y=0, z=0})
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
else
return {x=0, y=boost_cart:get_sign(v.y), z=boost_cart:get_sign(v.z)}
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
-- HACK in effect! Force updating the attachment rotation
player:set_properties({})
end
end
function boost_cart:is_rail(pos)
local node = minetest.get_node(pos).name
return minetest.get_item_group(node, "rail") ~= 0
function boost_cart:velocity_to_dir(v)
if math.abs(v.x) > math.abs(v.z) then
return {x=self:get_sign(v.x), y=self:get_sign(v.y), z=0}
else
return {x=0, y=self:get_sign(v.y), z=self:get_sign(v.z)}
end
end
function boost_cart:get_rail_direction(pos_, dir_)
local pos = vector.round(pos_)
local get_node = minetest.get_node
local get_item_group = minetest.get_item_group
function boost_cart:is_rail(pos, railtype)
local node = get_node(pos).name
if node == "ignore" then
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(pos, pos)
local area = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax,
}
local data = vm:get_data()
local vi = area:indexp(pos)
node = minetest.get_name_from_content_id(data[vi])
end
if get_item_group(node, "rail") == 0 then
return false
end
if not railtype then
return true
end
return get_item_group(node, "connect_to_raillike") == railtype
end
function boost_cart:check_front_up_down(pos, dir_, check_up, railtype)
local dir = vector.new(dir_)
local cur = nil
-- Front
dir.y = 0
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
if self:is_rail(cur, railtype) then
return dir
end
-- Down
dir.y = -1
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
return dir
end
-- Up
dir.y = 1
if check_up then
dir.y = 1
cur = vector.add(pos, dir)
if self:is_rail(cur, railtype) then
return dir
end
end
-- Down
dir.y = -1
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
if self:is_rail(cur, railtype) then
return dir
end
-- Left, right
dir.y = 0
return nil
end
function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
local pos = vector.round(pos_)
local cur = nil
local left_check, right_check = true, true
-- Check left and right
local view, opposite, val
if dir.x == 0 and dir.z ~= 0 then
view = "z"
other = "x"
if dir.z < 0 then
val = {1, -1}
else
val = {-1, 1}
local left = {x=0, y=0, z=0}
local right = {x=0, y=0, z=0}
if dir.z ~= 0 and dir.x == 0 then
left.x = -dir.z
right.x = dir.z
elseif dir.x ~= 0 and dir.z == 0 then
left.z = dir.x
right.z = -dir.x
end
local straight_priority = ctrl and dir.y ~= 0
-- Normal, to disallow rail switching up- & downhill
if straight_priority then
cur = self:check_front_up_down(pos, dir, true, railtype)
if cur then
return cur
end
elseif dir.z == 0 and dir.x ~= 0 then
view = "x"
other = "z"
if dir.x > 0 then
val = {1, -1}
else
val = {-1, 1}
end
if ctrl then
if old_switch == 1 then
left_check = false
elseif old_switch == 2 then
right_check = false
end
if ctrl.left and left_check then
cur = self:check_front_up_down(pos, left, false, railtype)
if cur then
return cur, 1
end
left_check = false
end
if ctrl.right and right_check then
cur = self:check_front_up_down(pos, right, false, railtype)
if cur then
return cur, 2
end
right_check = true
end
else
return {x=0, y=0, z=0}
end
dir[view] = 0
dir[other] = val[1]
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
return dir
-- Normal
if not straight_priority then
cur = self:check_front_up_down(pos, dir, true, railtype)
if cur then
return cur
end
end
-- Down
dir.y = -1
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
return dir
-- Left, if not already checked
if left_check then
cur = self:check_front_up_down(pos, left, false, railtype)
if cur then
return cur
end
end
dir.y = 0
dir[other] = val[2]
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
return dir
-- Right, if not already checked
if right_check then
cur = self:check_front_up_down(pos, right, false, railtype)
if cur then
return cur
end
end
-- Down
dir.y = -1
cur = vector.add(pos, dir)
if boost_cart:is_rail(cur) then
return dir
-- Backwards
if not old_switch then
cur = self:check_front_up_down(pos, {
x = -dir.x,
y = dir.y,
z = -dir.z
}, true, railtype)
if cur then
return cur
end
end
return {x=0, y=0, z=0}
end
function boost_cart:pathfinder(pos_, old_pos, old_dir, distance, ctrl,
pf_switch, railtype)
local pos = vector.round(pos_)
if vector.equals(old_pos, pos) then
return
end
local pf_pos = vector.round(old_pos)
local pf_dir = vector.new(old_dir)
distance = math.min(boost_cart.path_distance_max,
math.floor(distance + 1))
for i = 1, distance do
pf_dir, pf_switch = self:get_rail_direction(
pf_pos, pf_dir, ctrl, pf_switch or 0, railtype)
if vector.equals(pf_dir, {x=0, y=0, z=0}) then
-- No way forwards
return pf_pos, pf_dir
end
pf_pos = vector.add(pf_pos, pf_dir)
if vector.equals(pf_pos, pos) then
-- Success! Cart moved on correctly
return
end
end
-- Not found. Put cart to predicted position
return pf_pos, pf_dir
end
function boost_cart:boost_rail(pos, amount)
minetest.get_meta(pos):set_string("cart_acceleration", tostring(amount))
for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
if not obj_:is_player() and
obj_:get_luaentity() and
obj_:get_luaentity().name == "carts:cart" then
obj_:get_luaentity():on_punch()
end
end
end
function boost_cart:register_rail(name, def_overwrite)
local sound_func = default.node_sound_metal_defaults
or default.node_sound_defaults
local def = {
drawtype = "raillike",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
sounds = sound_func()
}
for k, v in pairs(def_overwrite) do
def[k] = v
end
if not def.inventory_image then
def.wield_image = def.tiles[1]
def.inventory_image = def.tiles[1]
end
minetest.register_node(name, def)
end
function boost_cart:get_rail_groups(additional_groups)
-- Get the default rail groups and add more when a table is given
local groups = {
dig_immediate = 2,
attached_node = 1,
rail = 1,
connect_to_raillike = 1
}
if minetest.raillike_group then
groups.connect_to_raillike = minetest.raillike_group("rail")
end
if type(additional_groups) == "table" then
for k, v in pairs(additional_groups) do
groups[k] = v
end
end
return groups
end

234
init.lua
View File

@ -1,208 +1,46 @@
-- TODO:
-- Fix way-up
-- Add rail-cross switching
-- Prevent from floating carts
-- Speed up and brake rails
boost_cart = {}
boost_cart.modpath = minetest.get_modpath("boost_cart")
boost_cart.speed_max = 8
if not minetest.settings then
error("[boost_cart] Your Minetest version is no longer supported."
.. " (Version <= 0.4.15)")
end
local function getNum(setting)
return tonumber(minetest.settings:get(setting))
end
-- Maximal speed of the cart in m/s
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
-- Support for non-default games
if not default.player_attached then
default.player_attached = {}
end
minetest.after(0, function()
boost_cart.old_player_model = not minetest.global_exists("player_api")
end)
dofile(boost_cart.modpath.."/functions.lua")
dofile(boost_cart.modpath.."/rails.lua")
boost_cart.cart = {
physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "mesh",
mesh = "cart.x",
visual_size = {x=1, y=1},
textures = {"cart.png"},
driver = nil,
punch = false, -- used to re-send velocity and position
velocity = {x=0, y=0, z=0}, -- only used on punch
old_dir = {x=0, y=0, z=0},
old_pos = nil
}
function boost_cart.cart:on_rightclick(clicker)
if not clicker or not clicker:is_player() then
return
end
local player_name = clicker:get_player_name()
if self.driver and player_name == self.driver then
self.driver = nil
clicker:set_detach()
elseif not self.driver then
self.driver = player_name
clicker:set_attach(self.object, "", {x=0,y=5,z=0}, {x=0,y=0,z=0})
end
if minetest.global_exists("mesecon") then
dofile(boost_cart.modpath.."/detector.lua")
--else
-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail")
-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail_on")
end
function boost_cart.cart:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1})
self.old_pos = self.object:getpos()
boost_cart.mtg_compat = minetest.global_exists("carts") and carts.pathfinder
if boost_cart.mtg_compat then
minetest.log("action", "[boost_cart] Overwriting definitions of similar carts mod")
end
function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
if not puncher or not puncher:is_player() then
return
end
if puncher:get_player_control().sneak then
if self.driver then
local player = minetest.get_player_by_name(self.driver)
if player then
player:set_detach()
end
end
self.object:remove()
puncher:get_inventory():add_item("main", "boost_cart:cart")
return
end
local vel = self.velocity
if puncher:get_player_name() == self.driver then
if math.abs(vel.x) > 2 or math.abs(vel.z) > 2 then
return
end
end
local cart_dir = boost_cart:velocity_to_dir(direction)
if cart_dir.x == 0 and cart_dir.z == 0 then
local fd = minetest.dir_to_facedir(puncher:get_look_dir())
if fd == 0 then
cart_dir.x = 1
elseif fd == 1 then
cart_dir.z = -1
elseif fd == 2 then
cart_dir.x = -1
elseif fd == 3 then
cart_dir.z = 1
end
end
if time_from_last_punch > tool_capabilities.full_punch_interval then
time_from_last_punch = tool_capabilities.full_punch_interval
end
local dir = boost_cart:get_rail_direction(self.object:getpos(), cart_dir)
local f = 3 * (time_from_last_punch / tool_capabilities.full_punch_interval)
vel.x = dir.x * f
vel.z = dir.y * f
vel.z = dir.z * f
self.velocity = vel
self.punch = true
end
function boost_cart.cart:on_step(dtime)
local vel = self.object:getvelocity()
if self.punch then
vel = vector.add(vel, self.velocity)
self.velocity = {x=0,y=0,z=0}
elseif vector.equals(vel, {x=0,y=0,z=0}) then
return
end
local pos = self.object:getpos()
local fpos, fold_pos = vector.round(pos), vector.round(self.old_pos)
if vector.equals(fpos, fold_pos) and not self.punch then
return
end
self.old_pos = vector.new(pos)
local cart_dir = {
x = boost_cart:get_sign(vel.x),
y = boost_cart:get_sign(vel.y),
z = boost_cart:get_sign(vel.z)
}
local dir = boost_cart:get_rail_direction(pos, cart_dir)
if vector.equals(dir, {x=0, y=0, z=0}) then
vel = {x=0, y=0, z=0}
self.object:setacceleration({x=0, y=0, z=0})
self.punch = true
else
-- If the direction changed
if dir.x ~= 0 and self.old_dir.z ~= 0 then
vel.x = dir.x * math.abs(vel.z)
vel.z = 0
pos.z = math.floor(pos.z + 0.5)
self.punch = true
end
if dir.z ~= 0 and self.old_dir.x ~= 0 then
vel.z = dir.z * math.abs(vel.x)
vel.x = 0
pos.x = math.floor(pos.x + 0.5)
self.punch = true
end
-- Up, down?
if dir.y ~= self.old_dir.y then
vel.y = dir.y * (math.abs(vel.x) + math.abs(vel.z))
pos.y = math.floor(pos.y + 0.5)
self.punch = true
end
-- Slow down or speed up..
local acc = -2 * dir.y - 0.4
self.object:setacceleration({
x = dir.x * acc,
y = dir.y * (math.abs(dir.x) + math.abs(dir.z)) * acc,
z = dir.z * acc
})
end
self.old_dir = vector.new(dir)
-- Limits
for _,v in ipairs({"x","y","z"}) do
if math.abs(vel[v]) > boost_cart.speed_max then
vel[v] = boost_cart:get_sign(vel[v]) * boost_cart.speed_max
self.punch = true
end
end
if dir.x < 0 then
self.object:setyaw(math.pi / 2)
elseif dir.x > 0 then
self.object:setyaw(3 * math.pi / 2)
elseif dir.z < 0 then
self.object:setyaw(math.pi)
elseif dir.z > 0 then
self.object:setyaw(0)
end
if dir.y == -1 then
self.object:set_animation({x=1, y=1}, 1, 0)
elseif dir.y == 1 then
self.object:set_animation({x=2, y=2}, 1, 0)
else
self.object:set_animation({x=0, y=0}, 1, 0)
end
if self.punch then
self.object:setvelocity(vel)
self.object:setpos(pos)
self.old_pos = {x=0, y=0, z=0}
end
self.punch = false
end
minetest.register_entity("boost_cart:cart", boost_cart.cart)
minetest.register_craftitem("boost_cart:cart", {
description = "Cart",
inventory_image = minetest.inventorycube("cart_top.png", "cart_side.png", "cart_side.png"),
wield_image = "cart_side.png",
on_place = function(itemstack, placer, pointed_thing)
if not pointed_thing.type == "node" then
return
end
if boost_cart:is_rail(pointed_thing.under) then
minetest.add_entity(pointed_thing.under, "boost_cart:cart")
elseif boost_cart:is_rail(pointed_thing.above) then
minetest.add_entity(pointed_thing.above, "boost_cart:cart")
else return end
itemstack:take_item()
return itemstack
end,
})
dofile(boost_cart.modpath.."/cart_entity.lua")

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = boost_cart

158
rails.lua
View File

@ -1,16 +1,146 @@
minetest.register_node(":default:rail", {
-- Common rail registrations
local regular_rail_itemname = "default:rail"
if minetest.registered_nodes["carts:rail"] then
-- MTG Compatibility
regular_rail_itemname = "carts:rail"
end
boost_cart:register_rail(":"..regular_rail_itemname, {
description = "Rail",
drawtype = "raillike",
tiles = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
inventory_image = "default_rail.png",
wield_image = "default_rail.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
tiles = {
"carts_rail_straight.png", "carts_rail_curved.png",
"carts_rail_t_junction.png", "carts_rail_crossing.png"
},
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1},
})
groups = boost_cart:get_rail_groups()
})
-- Moreores' copper rail
if minetest.get_modpath("moreores") then
minetest.register_alias("carts:copperrail", "moreores:copper_rail")
if minetest.raillike_group then
-- Ensure that this rail uses the same connect_to_raillike
local new_groups = minetest.registered_nodes["moreores:copper_rail"].groups
new_groups.connect_to_raillike = minetest.raillike_group("rail")
minetest.override_item("moreores:copper_rail", {
groups = new_groups
})
end
else
boost_cart:register_rail(":carts:copperrail", {
description = "Copper rail",
tiles = {
"carts_rail_straight_cp.png", "carts_rail_curved_cp.png",
"carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png"
},
groups = boost_cart:get_rail_groups()
})
minetest.register_craft({
output = "carts:copperrail 12",
recipe = {
{"default:copper_ingot", "", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "", "default:copper_ingot"},
}
})
end
-- Power rail
boost_cart:register_rail(":carts:powerrail", {
description = "Powered rail",
tiles = {
"carts_rail_straight_pwr.png", "carts_rail_curved_pwr.png",
"carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"
},
groups = boost_cart:get_rail_groups(),
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
boost_cart:boost_rail(pos, 0.5)
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},
})
minetest.register_craft({
output = "carts:powerrail 6",
recipe = {
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
}
})
-- Brake rail
boost_cart:register_rail(":carts:brakerail", {
description = "Brake rail",
tiles = {
"carts_rail_straight_brk.png", "carts_rail_curved_brk.png",
"carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"
},
groups = boost_cart:get_rail_groups(),
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "-0.3")
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "-0.3")
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},
})
minetest.register_craft({
output = "carts:brakerail 6",
recipe = {
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
}
})
boost_cart:register_rail("boost_cart:startstoprail", {
description = "Start-stop rail",
tiles = {
"carts_rail_straight_ss.png", "carts_rail_curved_ss.png",
"carts_rail_t_junction_ss.png", "carts_rail_crossing_ss.png"
},
groups = boost_cart:get_rail_groups(),
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "halt")
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
boost_cart:boost_rail(pos, 0.5)
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "halt")
end,
},
},
})
minetest.register_craft({
type = "shapeless",
output = "boost_cart:startstoprail 2",
recipe = {"carts:powerrail", "carts:brakerail"},
})

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

6
settingtypes.txt Normal file
View File

@ -0,0 +1,6 @@
# Maximal speed of the cart in m/s (min=1, max=100)
boost_cart.speed_max (Maximal speed) int 10 1 100
# Maximal speed to which the driving player can accelerate the cart by punching
# from inside the cart. -1 will disable this feature. (min=-1, max=100)
boost_cart.punch_speed_max (Maximal punch speed) int 7 -1 100

BIN
sounds/cart_rail.1.ogg Normal file

Binary file not shown.

BIN
sounds/cart_rail.2.ogg Normal file

Binary file not shown.

BIN
sounds/cart_rail.3.ogg Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 691 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B