From c394864546e3108b79bf14ee37e9bd6949a39ca8 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 29 Oct 2024 07:58:52 -0500 Subject: [PATCH] Allow functions for _rail_acceleration, make powered rail only accelerate carts when one side of the rail is a solid block or stairs --- mods/ENTITIES/mcl_minecarts/movement.lua | 7 ++++++- mods/ENTITIES/mcl_minecarts/rails/powered.lua | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index 8e8132996..b6ee1f12f 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -287,7 +287,12 @@ local function calculate_acceleration(staticdata) elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or SPEED_MAX ) then -- Standard friction 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 -- Factor in gravity after everything else diff --git a/mods/ENTITIES/mcl_minecarts/rails/powered.lua b/mods/ENTITIES/mcl_minecarts/rails/powered.lua index dcad6a197..94bb4f1d9 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/powered.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/powered.lua @@ -43,7 +43,21 @@ mod.register_straight_rail("mcl_minecarts:golden_rail_v2",{ "mcl_minecarts_rail_ -- Powered rail (on = acceleration mode) mod.register_straight_rail("mcl_minecarts:golden_rail_v2_on",{ "mcl_minecarts_rail_golden_powered.png" },{ _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, groups = { not_in_creative_inventory = 1,