Skip to content

Commit

Permalink
Reduce code duplication in register_on_punchnode
Browse files Browse the repository at this point in the history
Merges "pos1" and "pos1only" into the same code.
  • Loading branch information
Emojigit committed Oct 29, 2024
1 parent 998e346 commit a90e4f0
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions pos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,18 @@ minetest.register_on_punchnode(function(pos, node, puncher)
local name = puncher:get_player_name()
-- Currently setting position
if name ~= "" and areas.set_pos[name] then
if areas.set_pos[name] == "pos1" then
areas:setPos1(name, pos)
areas.set_pos[name] = "pos2"
if areas.set_pos[name] == "pos2" then
areas:setPos2(name, pos)
areas.set_pos[name] = nil
minetest.chat_send_player(name,
S("Position @1 set to @2", "1",
S("Position @1 set to @2", "2",
minetest.pos_to_string(pos)))
elseif areas.set_pos[name] == "pos1only" then
else
areas:setPos1(name, pos)
areas.set_pos[name] = nil
areas.set_pos[name] = areas.set_pos[name] == "pos1" and "pos2" or nil
minetest.chat_send_player(name,
S("Position @1 set to @2", "1",
minetest.pos_to_string(pos)))
elseif areas.set_pos[name] == "pos2" then
areas:setPos2(name, pos)
areas.set_pos[name] = nil
minetest.chat_send_player(name,
S("Position @1 set to @2", "2",
minetest.pos_to_string(pos)))
end
end
end)
Expand Down

0 comments on commit a90e4f0

Please sign in to comment.