Allow functions for _rail_acceleration, make powered rail only accelerate carts when one side of the rail is a solid block or stairs
This commit is contained in:
parent
21ce4e877c
commit
09d1056a1b
|
@ -287,7 +287,12 @@ local function calculate_acceleration(staticdata)
|
||||||
elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or SPEED_MAX ) then
|
elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or SPEED_MAX ) then
|
||||||
-- Standard friction
|
-- Standard friction
|
||||||
elseif node_def and node_def._rail_acceleration then
|
elseif node_def and node_def._rail_acceleration then
|
||||||
acceleration = node_def._rail_acceleration * 4
|
local rail_accel = node_def._rail_acceleration
|
||||||
|
if type(rail_accel) == "function" then
|
||||||
|
acceleration = (rail_accel(pos, staticdata) or 0) * 4
|
||||||
|
else
|
||||||
|
acceleration = rail_accel * 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Factor in gravity after everything else
|
-- Factor in gravity after everything else
|
||||||
|
|
|
@ -43,7 +43,21 @@ mod.register_straight_rail("mcl_minecarts:golden_rail_v2",{ "mcl_minecarts_rail_
|
||||||
-- Powered rail (on = acceleration mode)
|
-- Powered rail (on = acceleration mode)
|
||||||
mod.register_straight_rail("mcl_minecarts:golden_rail_v2_on",{ "mcl_minecarts_rail_golden_powered.png" },{
|
mod.register_straight_rail("mcl_minecarts:golden_rail_v2_on",{ "mcl_minecarts_rail_golden_powered.png" },{
|
||||||
_doc_items_create_entry = false,
|
_doc_items_create_entry = false,
|
||||||
_rail_acceleration = 4,
|
_rail_acceleration = function(pos, staticdata)
|
||||||
|
local dir = mod.get_rail_direction(pos, staticdata.dir, nil, nil, staticdata.railtype)
|
||||||
|
local node_a = minetest.get_node(vector.add(pos, dir))
|
||||||
|
local node_b = minetest.get_node(vector.add(pos, -dir))
|
||||||
|
local has_adjacent_solid = minetest.get_item_group(node_a.name, "solid") ~= 0 or
|
||||||
|
minetest.get_item_group(node_b.name, "solid") ~= 0 or
|
||||||
|
minetest.get_item_group(node_a.name, "stair") ~= 0 or
|
||||||
|
minetest.get_item_group(node_b.name, "stair") ~= 0
|
||||||
|
|
||||||
|
if has_adjacent_solid then
|
||||||
|
return 4
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end,
|
||||||
_max_acceleration_velocity = 8,
|
_max_acceleration_velocity = 8,
|
||||||
groups = {
|
groups = {
|
||||||
not_in_creative_inventory = 1,
|
not_in_creative_inventory = 1,
|
||||||
|
|
Loading…
Reference in New Issue