Skip to content

Commit

Permalink
Fix node corner bug (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panquesito7 authored Jul 16, 2023
1 parent 8e03818 commit 12b736a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ You can see a video of it in action: <https://youtu.be/VTFYnTzhvro>
## Known bugs

- Sometimes, you randomly get a jump boost that sets you very high.
- The jumps after the builtin jump might not sometimes work. This can also happen if you're standing on 3/4 of a node, where the node the player is standing on is not detected, and detecting `air` instead.

## Installation

Expand Down
46 changes: 45 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ end
-- Functions --
---------------

--- @brief Exactly the same as `find_nodes_in_area_under_air`,
--- except that the nodes do not need to be specified.
--- @param minp table The minimum position.
--- @param maxp table The maximum position.
--- @return table positions The positions of the nodes (if found).
local function find_nodes_in_area_under_air_all_nodes(minp, maxp)
local positions = { }
local i = 1

-- Adjust the positions.
minp.x = math.floor(minp.x + 0.5)
minp.z = math.floor(minp.z + 0.5)

maxp.x = math.ceil(maxp.x + 0.5)
maxp.z = math.ceil(maxp.z + 0.5)

for x = minp.x, maxp.x do
for z = minp.z, maxp.z do
local y = minp.y
local pos = vector.new(x, y, z)

if minetest.get_node(pos).name ~= "air" and minetest.get_node(vector.new(pos.x, pos.y + 1, pos.z)).name == "air" then
positions[i] = pos
i = i + 1
end
end
end

return positions
end

--- @brief Resets the jumping values of the player
--- once the player touches any node, except `air`.
--- @todo Fix checks not being detected well when a player is on the very corner of the node.
Expand All @@ -57,7 +88,20 @@ end
function double_jump.reset(player)
-- Reset values once the player touches any node.
local pos = player:get_pos()
local node = minetest.get_node(vector.new(pos.x, pos.y - 0.1, pos.z))
local minp = vector.new(pos.x - 0.3, pos.y - 0.1, pos.z - 0.3)
local maxp = vector.new(pos.x + 0.3, pos.y, pos.z + 0.3)
local nodes = find_nodes_in_area_under_air_all_nodes(minp, maxp)

local node_pos

for _, node in pairs(nodes) do
if node.y > pos.y then
node_pos = node
break
end
end

local node = minetest.get_node(node_pos or { })

if node and node.name ~= "air" then
double_jump.jump_number[player] = 0
Expand Down

0 comments on commit 12b736a

Please sign in to comment.