From 1054d38b4e71c7bc25a6f6ee1194d926982e34ff Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 12 Apr 2024 21:25:40 +0000 Subject: [PATCH] Fix placed rail conversion, start automatic inventory rail conversion --- mods/ENTITIES/mcl_minecarts/carts.lua | 3 ++- mods/ENTITIES/mcl_minecarts/rails.lua | 28 +++++++++++++++++++++++++-- mods/HUD/mcl_inventory/creative.lua | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index 9e6593d06..1db3c0150 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -3,7 +3,7 @@ local modpath = minetest.get_modpath(modname) local mod = mcl_minecarts local S = minetest.get_translator(modname) -local mcl_log = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts") +local mcl_log,DEBUG = mcl_util.make_mcl_logger("mcl_logging_minecarts", "Minecarts") -- Imports local CART_BLOCK_SIZE = mod.CART_BLOCK_SIZE @@ -612,6 +612,7 @@ minetest.register_globalstep(function(dtime) end) minetest.register_on_joinplayer(function(player) + -- Try cart reattachment local player_name = player:get_player_name() local player_meta = mcl_playerinfo.get_mod_meta(player_name, modname) local cart_uuid = player_meta.attached_to diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index f09a702ad..fff59fe88 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -652,7 +652,10 @@ local CURVY_RAILS_MAP = { ["mcl_minecarts:rail"] = "mcl_minecarts:rail_v2", } for old,new in pairs(CURVY_RAILS_MAP) do - minetest.register_alias(old, new) + minetest.register_node(old, { + inventory_image = minetest.registered_nodes[new].inventory_image, + groups = { rail = 1 } + }) end minetest.register_lbm({ name = "mcl_minecarts:update_legacy_curvy_rails", @@ -674,8 +677,14 @@ local STRAIGHT_RAILS_MAP ={ ["mcl_minecarts:detector_rail_on"] = "mcl_minecarts:detector_rail_v2_on", } for old,new in pairs(STRAIGHT_RAILS_MAP) do - minetest.register_alias(old, new) + minetest.register_node(old, { + inventory_image = minetest.registered_nodes[new].inventory_image, + groups = { rail = 1 } + }) end +local TRANSLATE_RAILS_MAP = table.copy(STRAIGHT_RAILS_MAP) +table_merge(TRANSLATE_RAILS_MAP, CURVY_RAILS_MAP) + minetest.register_lbm({ name = "mcl_minecarts:update_legacy_straight_rails", nodenames = mcl_util.table_keys(STRAIGHT_RAILS_MAP), @@ -699,3 +708,18 @@ minetest.register_lbm({ end end }) + +-- Convert old rail in the player's inventory to new rail +minetest.register_on_joinplayer(function(player) + local inv = player:get_inventory() + local size = inv:get_size("main") + for i=1,size do + local stack = inv:get_stack("main", i) + + local new_name = TRANSLATE_RAILS_MAP[stack:get_name()] + if new_name then + stack:set_name(new_name) + inv:set_stack("main", i, stack) + end + end +end) diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 4ddbd0823..c34204269 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -386,7 +386,7 @@ local tab_icon = { blocks = "mcl_core:brick_block", deco = "mcl_flowers:peony", redstone = "mesecons:redstone", - rail = "mcl_minecarts:golden_rail", + rail = "mcl_minecarts:golden_rail_v2", misc = "mcl_buckets:bucket_lava", nix = "mcl_compass:compass", food = "mcl_core:apple",