From 72e90b91d20942ab3c09bf5a9e92c48685bd80e1 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 7 Aug 2024 21:25:38 -0500 Subject: [PATCH] Address additional review comments --- mods/CORE/mcl_util/init.lua | 2 +- mods/ENTITIES/mcl_minecarts/carts.lua | 8 ++++---- mods/ENTITIES/mcl_minecarts/functions.lua | 16 ++++++++-------- mods/ENTITIES/mcl_minecarts/movement.lua | 8 ++++---- mods/ENTITIES/mcl_minecarts/rails.lua | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index e401aa11c..5a4ccc405 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -398,7 +398,7 @@ end ---@param pos Vector ---@param src_pos Vector function mcl_util.hopper_pull(pos, src_pos) - return mcl_util.hopper_pull_to_inventory(minetest.get_meta(pos):get_inventory(), 'main', src_pos, pos) + return mcl_util.hopper_pull_to_inventory(minetest.get_meta(pos):get_inventory(), "main", src_pos, pos) end local function drop_item_stack(pos, stack) diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index f6d221c58..c59bf6755 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -280,7 +280,7 @@ function DEFAULT_CART_DEF:on_step(dtime) end function mod.kill_cart(staticdata, killer) local pos - minetest.log("action", "cart #"..staticdata.uuid.." was killed") + mcl_log("cart #"..staticdata.uuid.." was killed") -- Leave nodes if staticdata.attached_at then @@ -372,15 +372,15 @@ function mod.place_minecart(itemstack, pointed_thing, placer) local cart_dir = vector.new(1,0,0) local railpos, node - if mcl_minecarts:is_rail(pointed_thing.under) then + if mcl_minecarts.is_rail(pointed_thing.under) then railpos = pointed_thing.under - elseif mcl_minecarts:is_rail(pointed_thing.above) then + elseif mcl_minecarts.is_rail(pointed_thing.above) then railpos = pointed_thing.above end if railpos then spawn_pos = railpos node = minetest.get_node(railpos) - cart_dir = mcl_minecarts:get_rail_direction(railpos, vector.new(1,0,0)) + cart_dir = mcl_minecarts.get_rail_direction(railpos, vector.new(1,0,0)) end local entity_id = entity_mapping[itemstack:get_name()] diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 88a03a4c8..d7cf8b99d 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -74,7 +74,7 @@ end -- Directional constants local north = vector.new( 0, 0, 1); local N = 1 -- 4dir = 0 local east = vector.new( 1, 0, 0); local E = 4 -- 4dir = 1 -local south = vector.new( 0, 0,-1); local S = 2 -- 4dir = 2 Note: S is overwritten below with the translator +local south = vector.new( 0, 0,-1); local S = 2 -- 4dir = 2 local west = vector.new(-1, 0, 0); local W = 8 -- 4dir = 3 -- Share. Consider moving this to some shared location @@ -200,7 +200,7 @@ local function get_rail_connections(pos, opt) local nodedef = minetest.registered_nodes[node.name] -- Only allow connections to the open ends of rails, as decribed by get_next_dir - if mcl_minecarts:is_rail(neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then + if mcl_minecarts.is_rail(neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then local rev_dir = vector.direction(dir,vector.zero()) if ignore_neighbor_connections or is_connection(neighbor, rev_dir) then connections = bit.bor(connections, bit.lshift(1,i - 1)) @@ -211,7 +211,7 @@ local function get_rail_connections(pos, opt) local below_neighbor = vector.offset(neighbor, 0, -1, 0) local node = force_get_node(below_neighbor) local nodedef = minetest.registered_nodes[node.name] - if mcl_minecarts:is_rail(below_neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then + if mcl_minecarts.is_rail(below_neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then local rev_dir = vector.direction(dir, vector.zero()) if ignore_neighbor_connections or is_connection(below_neighbor, rev_dir) then connections = bit.bor(connections, bit.lshift(1,i - 1)) @@ -280,7 +280,7 @@ local function update_rail_connections(pos, opt) local dir = CONNECTIONS[i] local higher_rail_pos = vector.offset(pos,dir.x,1,dir.z) local rev_dir = vector.direction(dir,vector.zero()) - if mcl_minecarts:is_rail(higher_rail_pos) and is_connection(higher_rail_pos, rev_dir) then + if mcl_minecarts.is_rail(higher_rail_pos) and is_connection(higher_rail_pos, rev_dir) then make_sloped_if_straight(pos, rev_dir) end end @@ -296,10 +296,10 @@ local west = vector.new(-1,0,0) local function is_ahead_slope(pos, dir) local ahead = vector.add(pos,dir) - if mcl_minecarts:is_rail(ahead) then return false end + if mcl_minecarts.is_rail(ahead) then return false end local below = vector.offset(ahead,0,-1,0) - if not mcl_minecarts:is_rail(below) then return false end + if not mcl_minecarts.is_rail(below) then return false end local node_name = force_get_node(below).name return minetest.get_item_group(node_name, "rail_slope") ~= 0 @@ -344,8 +344,8 @@ function mcl_minecarts.get_rail_direction(self, pos_, dir) -- Check both possible diagonal movements local dir_a = vector.new(dir.x,0,0) local dir_b = vector.new(0,0,dir.z) - local new_dir_a = mcl_minecarts:get_rail_direction(pos, dir_a) - local new_dir_b = mcl_minecarts:get_rail_direction(pos, dir_b) + local new_dir_a = mcl_minecarts.get_rail_direction(pos, dir_a) + local new_dir_b = mcl_minecarts.get_rail_direction(pos, dir_b) -- If either is the same diagonal direction, continue as you were if vector.equals(dir,new_dir_a) or vector.equals(dir,new_dir_b) then diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index 74c8313ec..0ad9e2331 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -179,7 +179,7 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir) --print("u1="..tostring(u1)..",u2="..tostring(u2)) if u2 == 0 and u1 < 4 and train_length(cart1_staticdata) < MAX_TRAIN_LENGTH then link_cart_ahead(cart1_staticdata, cart2_staticdata) - cart2_staticdata.dir = mcl_minecarts:get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir) + cart2_staticdata.dir = mcl_minecarts.get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir) cart2_staticdata.velocity = cart1_staticdata.velocity return end @@ -194,7 +194,7 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir) cart2_staticdata.velocity = v2 -- Force the other cart to move the same direction this one was - cart2_staticdata.dir = mcl_minecarts:get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir) + cart2_staticdata.dir = mcl_minecarts.get_rail_direction(cart2_staticdata.connected_at, cart1_staticdata.dir) end local function vector_away_from_players(cart, staticdata) @@ -238,7 +238,7 @@ local function direction_away_from_players(staticdata) if force > 0 then dir = -dir end - if mcl_minecarts:is_rail( staticdata.connected_at + dir ) then + if mcl_minecarts.is_rail( staticdata.connected_at + dir ) then if force > 0.5 then return -length * 4 elseif force < -0.5 then @@ -403,7 +403,7 @@ local function do_movement_step(staticdata, dtime) staticdata.connected_at = pos -- Get the next direction - local next_dir,_ = mcl_minecarts:get_rail_direction(pos, staticdata.dir, nil, nil, staticdata.railtype) + local next_dir,_ = mcl_minecarts.get_rail_direction(pos, staticdata.dir, nil, nil, staticdata.railtype) if DEBUG and next_dir ~= staticdata.dir then mcl_debug( "Changing direction from "..tostring(staticdata.dir).." to "..tostring(next_dir)) end diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index b76b7bf03..bb76cdc36 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -386,6 +386,7 @@ end minetest.register_lbm({ name = "mcl_minecarts:update_legacy_curvy_rails", nodenames = mcl_util.table_keys(CURVY_RAILS_MAP), + run_at_every_load = true, action = function(pos, node) node.name = CURVY_RAILS_MAP[node.name] if node.name then