From 37d00061792e0fb6255afc7f4a205130e0a70025 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 11 Apr 2024 09:17:06 +0000 Subject: [PATCH] Fix crashes, fix link in documentation --- mods/ENTITIES/mcl_minecarts/DOC.md | 2 +- mods/ENTITIES/mcl_minecarts/init.lua | 2 +- mods/ENTITIES/mcl_minecarts/movement.lua | 3 +-- mods/ENTITIES/mcl_minecarts/storage.lua | 7 ++++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/DOC.md b/mods/ENTITIES/mcl_minecarts/DOC.md index 1e18e7b63..09b2e608c 100644 --- a/mods/ENTITIES/mcl_minecarts/DOC.md +++ b/mods/ENTITIES/mcl_minecarts/DOC.md @@ -33,7 +33,7 @@ Processing for minecart movement is as follows: 4. The cart checks for nearby carts and collides elastically with these. The calculations for these collisions are in the function `handle_cart_collision` 5. If the cart enters a new block, determine the new direction the cart will - move with `mcl_minecarts:get_rail_direction` in [functions.lua](./functions.lua]. + move with `mcl_minecarts:get_rail_direction` in [functions.lua](./functions.lua). The rail nodes provide a hook `_mcl_minecarts.get_next_direction` that provides this information based on the previous movement direction. 3. If an entity exists for a given cart, the entity will update its position diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index dbc5897a4..081e78314 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -5,7 +5,7 @@ local mod = mcl_minecarts mcl_minecarts.modpath = modpath -- Constants -mod.speed_max = 10 +mod.SPEED_MAX = 10 mod.FRICTION = 0.4 mod.MAX_TRAIN_LENGTH = 4 mod.CART_BLOCK_SIZE = 64 diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index 3c4ba5e83..2f5acdf71 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -240,7 +240,6 @@ local function calculate_acceleration(staticdata) local pos = staticdata.connected_at local node_name = minetest.get_node(pos).name local node_def = minetest.registered_nodes[node_name] - local max_vel = SPEED_MAX local ctrl = staticdata.controls or {} local time_active = minetest.get_gametime() - 0.25 @@ -251,7 +250,7 @@ local function calculate_acceleration(staticdata) acceleration = -1.5 elseif (staticdata.fueltime or 0) > 0 and staticdata.velocity <= 4 then acceleration = 0.6 - elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or max_vel ) then + 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 diff --git a/mods/ENTITIES/mcl_minecarts/storage.lua b/mods/ENTITIES/mcl_minecarts/storage.lua index 91926835d..7f242b7f8 100644 --- a/mods/ENTITIES/mcl_minecarts/storage.lua +++ b/mods/ENTITIES/mcl_minecarts/storage.lua @@ -3,6 +3,7 @@ local mod = mcl_minecarts -- Imports local CART_BLOCK_SIZE = mod.CART_BLOCK_SIZE +assert(CART_BLOCK_SIZE) local cart_data = {} local cart_data_fail_cache = {} @@ -72,9 +73,9 @@ function mod.find_carts_by_block_map(block_map) return cart_list end -function mod.add_block_map(block_map, min_pos, max_pos) - local min = vector.floor(vector.divide(min_pos), CART_BLOCK_SIZE) - local max = vector.floor(vector.divide(max_pos), CART_BLOCK_SIZE) + vector.new(1,1,1) +function mod.add_blocks_to_map(block_map, min_pos, max_pos) + local min = vector.floor(vector.divide(min_pos, CART_BLOCK_SIZE)) + local max = vector.floor(vector.divide(max_pos, CART_BLOCK_SIZE)) + vector.new(1,1,1) for z = min.z,max.z do for y = min.y,max.y do for x = min.x,max.x do