diff --git a/.luacheckrc b/.luacheckrc index 353e7cc..7c427e2 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -15,6 +15,7 @@ read_globals = { "VoxelManip", -- Minetest + "core", "minetest", "vector", "ItemStack", "dump", "VoxelArea", diff --git a/compat/beds.lua b/compat/beds.lua index ec09691..73caf32 100644 --- a/compat/beds.lua +++ b/compat/beds.lua @@ -1,13 +1,13 @@ -local bed_bottoms = {"beds:bed_bottom", "beds:fancy_bed_bottom"} +local bed_bottoms = { "beds:bed_bottom", "beds:fancy_bed_bottom" } --- sanity checks +-- Sanity checks assert(beds, "global `beds` not found") assert(beds.spawn, "field `spawn` doesn't exist in `beds`") assert(beds.save_spawns, "field `save_spawns` doesn't exist in `beds`") -- Calculate a bed's middle position (where players would spawn) local function calc_bed_middle(bed_pos, facedir) - local dir = minetest.facedir_to_dir(facedir) + local dir = core.facedir_to_dir(facedir) local bed_middle = { x = bed_pos.x + dir.x / 2, y = bed_pos.y, @@ -18,37 +18,37 @@ end local bed_from_positions = {} - for _, nodename in ipairs(bed_bottoms) do - -- override bed definitions - minetest.override_item(nodename, { + -- Override bed definitions + core.override_item(nodename, { on_movenode = function(from_pos) - -- collect bed positions while jumping + -- Collect bed positions while jumping table.insert(bed_from_positions, from_pos) end }) end --- executed after jump +-- Executed after jump jumpdrive.register_after_jump(function(from_area, to_area) local delta_vector = vector.subtract(to_area.pos1, from_area.pos1) local modified = false - -- go over all collected bed positions + -- Go over all collected bed positions for _, bed_pos in ipairs(bed_from_positions) do - local facedir = minetest.get_node(bed_pos).param2 + local facedir = core.get_node(bed_pos).param2 local sleep_pos = calc_bed_middle(bed_pos, facedir) - -- sleep position in target area + -- Sleep position in target area local new_sleep_pos = vector.add(sleep_pos, delta_vector) local sleep_pos_floor = vector.floor(sleep_pos) for player_name, player_pos in pairs(beds.spawn) do if vector.equals(sleep_pos_floor, vector.floor(player_pos)) then - -- player sleeps here, move position + -- Player sleeps here, move position beds.spawn[player_name] = new_sleep_pos - minetest.log("action", "[jumpdrive] Updated bed spawn for player " .. player_name) + core.log("action", + "[jumpdrive] Updated bed spawn for player " .. player_name) - -- set modified flag to save afterwards + -- Set modified flag to save afterwards modified = true end end @@ -59,6 +59,6 @@ jumpdrive.register_after_jump(function(from_area, to_area) beds.save_spawns() end - -- clear collected bed positions + -- Clear collected bed positions bed_from_positions = {} end)