Skip to content

Commit

Permalink
cleanup whitespace, comments and MT -> core
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS committed Dec 22, 2024
1 parent 41e9c6d commit 1b82cc1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ read_globals = {
"VoxelManip",

-- Minetest
"core",
"minetest",
"vector", "ItemStack",
"dump", "VoxelArea",
Expand Down
30 changes: 15 additions & 15 deletions compat/beds.lua
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand All @@ -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)

0 comments on commit 1b82cc1

Please sign in to comment.