Add legacy node conversion to vl_legacy and update rails.lua to use it
This commit is contained in:
parent
f9136730ad
commit
11ce4ad18f
|
@ -17,3 +17,19 @@ Arguments:
|
|||
* `old`: Itemstring to be converted
|
||||
* `new`: New item string
|
||||
|
||||
## `vl_legacy.convert_node(pos, node)`
|
||||
|
||||
Converts legacy nodes to newer versions.
|
||||
|
||||
Arguments:
|
||||
* `pos`: Position of the node to attempt conversion
|
||||
* `node`: Node definition to convert. The node will be loaded from map data if `nil`.
|
||||
|
||||
The node definition for the old node must contain the field `_vl_legacy_convert` with
|
||||
a value that is either a `function(pos, node)` or `string` for this call to have any
|
||||
affect. If a function is provided, the function is called with `pos` and `node` as
|
||||
arguments. If a string is provided, a node name conversion will occur.
|
||||
|
||||
This mod provides an LBM and ABM that will automatically call this function for nodes
|
||||
with `group:legacy` set.
|
||||
|
||||
|
|
|
@ -35,6 +35,17 @@ function mod.convert_inventory(inv)
|
|||
mod.convert_inventory_lists(lists)
|
||||
inv:set_lists(lists)
|
||||
end
|
||||
function mod.convert_node(pos, node)
|
||||
local node = node or minetest.get_node(pos)
|
||||
local node_def = minetest.registered_nodes[node.name]
|
||||
local convert = node_def._vl_legacy_convert_node
|
||||
if type(convert) == "function" then
|
||||
convert(pos, node)
|
||||
elseif type(convert) == "string" then
|
||||
node.name = convert
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
mod.convert_inventory(player:get_inventory())
|
||||
|
@ -49,4 +60,16 @@ minetest.register_lbm({
|
|||
mod.convert_inventory(meta:get_inventory())
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
name = "vl_legacy:convert_nodes",
|
||||
nodenames = "group:legacy",
|
||||
run_at_every_load = true,
|
||||
action = mod.convert_node,
|
||||
})
|
||||
minetest.register_abm({
|
||||
label = "Convert Legacy Nodes",
|
||||
nodenames = "group:legacy",
|
||||
interval = 5,
|
||||
chance = 1,
|
||||
action = mod.convert_node,
|
||||
})
|
||||
|
|
|
@ -373,28 +373,24 @@ end
|
|||
local CURVY_RAILS_MAP = {
|
||||
["mcl_minecarts:rail"] = "mcl_minecarts:rail_v2",
|
||||
}
|
||||
for old,new in pairs(CURVY_RAILS_MAP) do
|
||||
local new_def = minetest.registered_nodes[new]
|
||||
minetest.register_node(old, {
|
||||
drawtype = "raillike",
|
||||
inventory_image = new_def.inventory_image,
|
||||
groups = { rail = 1 },
|
||||
tiles = { new_def.tiles[1], new_def.tiles[1], new_def.tiles[1], new_def.tiles[1] },
|
||||
})
|
||||
vl_legacy.register_item_conversion(old, new)
|
||||
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)
|
||||
local function convert_legacy_curvy_rails(pos, node)
|
||||
node.name = CURVY_RAILS_MAP[node.name]
|
||||
if node.name then
|
||||
minetest.swap_node(pos, node)
|
||||
mod.update_rail_connections(pos, { legacy = true, ignore_neighbor_connections = true })
|
||||
end
|
||||
end
|
||||
for old,new in pairs(CURVY_RAILS_MAP) do
|
||||
local new_def = minetest.registered_nodes[new]
|
||||
minetest.register_node(old, {
|
||||
drawtype = "raillike",
|
||||
inventory_image = new_def.inventory_image,
|
||||
groups = { rail = 1, legacy = 1 },
|
||||
tiles = { new_def.tiles[1], new_def.tiles[1], new_def.tiles[1], new_def.tiles[1] },
|
||||
_vl_legacy_convert_node = convert_legacy_curvy_rails
|
||||
})
|
||||
vl_legacy.register_item_conversion(old, new)
|
||||
end
|
||||
local STRAIGHT_RAILS_MAP ={
|
||||
["mcl_minecarts:golden_rail"] = "mcl_minecarts:golden_rail_v2",
|
||||
["mcl_minecarts:golden_rail_on"] = "mcl_minecarts:golden_rail_v2_on",
|
||||
|
@ -403,22 +399,7 @@ local STRAIGHT_RAILS_MAP ={
|
|||
["mcl_minecarts:detector_rail"] = "mcl_minecarts:detector_rail_v2",
|
||||
["mcl_minecarts:detector_rail_on"] = "mcl_minecarts:detector_rail_v2_on",
|
||||
}
|
||||
for old,new in pairs(STRAIGHT_RAILS_MAP) do
|
||||
local new_def = minetest.registered_nodes[new]
|
||||
minetest.register_node(old, {
|
||||
drawtype = "raillike",
|
||||
inventory_image = new_def.inventory_image,
|
||||
groups = { rail = 1 },
|
||||
tiles = { new_def.tiles[1], new_def.tiles[1], new_def.tiles[1], new_def.tiles[1] },
|
||||
})
|
||||
vl_legacy.register_item_conversion(old, new)
|
||||
end
|
||||
|
||||
minetest.register_lbm({
|
||||
name = "mcl_minecarts:update_legacy_straight_rails",
|
||||
nodenames = mcl_util.table_keys(STRAIGHT_RAILS_MAP),
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
local function convert_legacy_straight_rail(pos, node)
|
||||
node.name = STRAIGHT_RAILS_MAP[node.name]
|
||||
if node.name then
|
||||
local connections = mod.get_rail_connections(pos, { legacy = true, ignore_neighbor_connections = true })
|
||||
|
@ -437,5 +418,15 @@ minetest.register_lbm({
|
|||
mod.update_rail_connections(pos, { legacy = true, ignore_neighbor_connections = true })
|
||||
end
|
||||
end
|
||||
for old,new in pairs(STRAIGHT_RAILS_MAP) do
|
||||
local new_def = minetest.registered_nodes[new]
|
||||
minetest.register_node(old, {
|
||||
drawtype = "raillike",
|
||||
inventory_image = new_def.inventory_image,
|
||||
groups = { rail = 1, legacy = 1 },
|
||||
tiles = { new_def.tiles[1], new_def.tiles[1], new_def.tiles[1], new_def.tiles[1] },
|
||||
_vl_legacy_convert_node = convert_legacy_straight_rail,
|
||||
})
|
||||
vl_legacy.register_item_conversion(old, new)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue