Added math.order

apparently builtin already has the math. namespace, testing for it doesn't seam to work?
but assigning an empty table over it makes it angry, so lets not do that
This commit is contained in:
Pascal Abresch 2019-10-04 04:38:18 +02:00
parent a3c297ac21
commit 13b78ff838
2 changed files with 17 additions and 19 deletions

8
sparkapi/lua/math.lua Normal file
View File

@ -0,0 +1,8 @@
function math.order(x, y) -- might change to arbitrary args later, but now now ... this is just the simple impl written for the quarry
if not x or not y then return nil end
if x <= y then
return x, y
else
return y, x
end
end

View File

@ -14,15 +14,6 @@ local function Position(x, y, z) ---
return {x=x, y=y, z=z}
end
local function order(x, y) ---
--- Returns (smaller, bigger)
if x <= y then
return x, y
else
return y,x
end
end
local function try_drain_energy(target_pos, amount) ---
--- Returns true if drained, false otherwise
--- Removes amount energy from target_pos if energy >= amount
@ -99,9 +90,9 @@ local function on_marker_placed(pos, quarry_pos, player)
end
local minx, maxx = order(pos.x, quarry_pos.x)
local miny, maxy = order(pos.y, quarry_pos.y)
local minz, maxz = order(pos.z, quarry_pos.z)
local minx, maxx = math.order(pos.x, quarry_pos.x)
local miny, maxy = math.order(pos.y, quarry_pos.y)
local minz, maxz = math.order(pos.z, quarry_pos.z)
local diffx = maxx - minx
local diffy = maxy - miny
@ -112,7 +103,6 @@ local function on_marker_placed(pos, quarry_pos, player)
diffz < 2 or diffz >= MAX_SIZE
then
notify.hud.sendtext(player, "Invalid dimensions for quarry 3x3x3")
-- minetest.chat_send_player(player:get_player_name(), "Invalid dimensions for quarry")
return
end
@ -149,9 +139,9 @@ end
local function prepare_area(pos, pos2)
local placement_done = true
local minx, maxx = order(pos.x, pos2.x)
local miny, maxy = order(pos.y, pos2.y)
local minz, maxz = order(pos.z, pos2.z)
local minx, maxx = math.order(pos.x, pos2.x)
local miny, maxy = math.order(pos.y, pos2.y)
local minz, maxz = math.order(pos.z, pos2.z)
for x=minx , maxx do
for y=miny, maxy do
for z=minz, maxz do
@ -231,9 +221,9 @@ local function timer_trigger(pos, elapsed)
else
--shrink the operational area here to a 2d space with one piece of border taken away to drill there
--
local posx, pos2x = order(pos.x, marker_pos.x)
local posy, pos2y = order(pos.y, marker_pos.y)
local posz, pos2z = order(pos.z, marker_pos.z)
local posx, pos2x = math.order(pos.x, marker_pos.x)
local posy, pos2y = math.order(pos.y, marker_pos.y)
local posz, pos2z = math.order(pos.z, marker_pos.z)
posx = posx +1
pos2x = pos2x -1
posz = posz + 1