Cleanup vectors
This commit is contained in:
parent
c42ea6c005
commit
916e80f2c3
|
@ -1,8 +1,8 @@
|
||||||
|
local vec = vector.new
|
||||||
local ItemStack = ItemStack
|
local ItemStack = ItemStack
|
||||||
local loadstring = loadstring
|
local loadstring = loadstring
|
||||||
local reg_items = core.registered_items
|
local reg_items = core.registered_items
|
||||||
local translate = core.get_translated_string
|
local translate = core.get_translated_string
|
||||||
local vec_new, vec_add, vec_mul = vector.new, vector.add, vector.multiply
|
|
||||||
local sort, concat, insert = table.sort, table.concat, table.insert
|
local sort, concat, insert = table.sort, table.concat, table.insert
|
||||||
local min, floor, ceil = math.min, math.floor, math.ceil
|
local min, floor, ceil = math.min, math.floor, math.ceil
|
||||||
local fmt, find, match, gmatch, sub, split, lower, upper =
|
local fmt, find, match, gmatch, sub, split, lower, upper =
|
||||||
|
@ -376,7 +376,7 @@ local function spawn_item(player, stack)
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
local ppos = player:get_pos()
|
local ppos = player:get_pos()
|
||||||
ppos.y = ppos.y + player:get_properties().eye_height
|
ppos.y = ppos.y + player:get_properties().eye_height
|
||||||
local look_at = vec_add(ppos, vec_mul(dir, 1))
|
local look_at = ppos + dir
|
||||||
|
|
||||||
core.add_item(look_at, stack)
|
core.add_item(look_at, stack)
|
||||||
end
|
end
|
||||||
|
@ -473,9 +473,9 @@ local function safe_teleport(player, pos)
|
||||||
play_sound(name, "i3_teleport", 0.8)
|
play_sound(name, "i3_teleport", 0.8)
|
||||||
|
|
||||||
local vel = player:get_velocity()
|
local vel = player:get_velocity()
|
||||||
player:add_velocity(vec_mul(vel, -1))
|
player:add_velocity(-vel)
|
||||||
|
|
||||||
local p = vec_new(pos)
|
local p = vec(pos)
|
||||||
p.y += 0.25
|
p.y += 0.25
|
||||||
|
|
||||||
player:set_pos(p)
|
player:set_pos(p)
|
||||||
|
@ -780,12 +780,8 @@ local _ = {
|
||||||
random = math.random,
|
random = math.random,
|
||||||
|
|
||||||
-- Vectors
|
-- Vectors
|
||||||
vec_new = vector.new,
|
vec = vector.new,
|
||||||
vec_add = vector.add,
|
|
||||||
vec_sub = vector.subtract,
|
|
||||||
vec_mul = vector.multiply,
|
|
||||||
vec_round = vector.round,
|
vec_round = vector.round,
|
||||||
vec_eq = vector.equals,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function i3.get(...)
|
function i3.get(...)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local set_fs = i3.set_fs
|
local set_fs = i3.set_fs
|
||||||
|
|
||||||
|
IMPORT("min", "max", "vec_round")
|
||||||
IMPORT("reg_items", "reg_aliases")
|
IMPORT("reg_items", "reg_aliases")
|
||||||
IMPORT("min", "max", "vec_eq", "vec_round")
|
|
||||||
IMPORT("S", "random", "translate", "ItemStack")
|
IMPORT("S", "random", "translate", "ItemStack")
|
||||||
IMPORT("sort", "copy", "insert", "remove", "indexof")
|
IMPORT("sort", "copy", "insert", "remove", "indexof")
|
||||||
IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper")
|
IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper")
|
||||||
|
@ -180,7 +180,7 @@ local function inv_fields(player, data, fields)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
for _, v in ipairs(data.waypoints) do
|
for _, v in ipairs(data.waypoints) do
|
||||||
if vec_eq(vec_round(pos), vec_round(str_to_pos(v.pos))) then
|
if vec_round(pos) == vec_round(str_to_pos(v.pos)) then
|
||||||
play_sound(name, "i3_cannot", 0.8)
|
play_sound(name, "i3_cannot", 0.8)
|
||||||
return msg(name, S"You already have set a waypoint at this position")
|
return msg(name, S"You already have set a waypoint at this position")
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,8 @@ local PNG, styles, fs_elements, colors = i3.files.styles()
|
||||||
local sprintf = string.format
|
local sprintf = string.format
|
||||||
local VoxelArea, VoxelManip = VoxelArea, VoxelManip
|
local VoxelArea, VoxelManip = VoxelArea, VoxelManip
|
||||||
|
|
||||||
|
IMPORT("vec", "vec_round")
|
||||||
IMPORT("find", "match", "sub", "upper")
|
IMPORT("find", "match", "sub", "upper")
|
||||||
IMPORT("vec_new", "vec_sub", "vec_round")
|
|
||||||
IMPORT("clr", "ESC", "msg", "check_privs")
|
IMPORT("clr", "ESC", "msg", "check_privs")
|
||||||
IMPORT("compression_active", "compressible")
|
IMPORT("compression_active", "compressible")
|
||||||
IMPORT("min", "max", "floor", "ceil", "round")
|
IMPORT("min", "max", "floor", "ceil", "round")
|
||||||
|
@ -240,8 +240,8 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||||
local max_depth = -7
|
local max_depth = -7
|
||||||
local height = base_depth and (base_height - 1) or depth
|
local height = base_depth and (base_height - 1) or depth
|
||||||
|
|
||||||
local pos1 = vec_new(pos.x - width, pos.y + depth, pos.z - width)
|
local pos1 = vec(pos.x - width, pos.y + depth, pos.z - width)
|
||||||
local pos2 = vec_new(pos.x + width, pos.y + height, pos.z + width)
|
local pos2 = vec(pos.x + width, pos.y + height, pos.z + width)
|
||||||
|
|
||||||
local vm = VoxelManip(pos1, pos2)
|
local vm = VoxelManip(pos1, pos2)
|
||||||
local emin, emax = vm:get_emerged_area()
|
local emin, emax = vm:get_emerged_area()
|
||||||
|
@ -255,7 +255,7 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||||
|
|
||||||
if img then
|
if img then
|
||||||
local p = area:position(idx)
|
local p = area:position(idx)
|
||||||
p = vec_sub(p, pos)
|
p -= pos
|
||||||
|
|
||||||
local size = 0.25
|
local size = 0.25
|
||||||
local x = 2 + (size / 2 * (p.z - p.x))
|
local x = 2 + (size / 2 * (p.z - p.x))
|
||||||
|
|
Ŝarĝante…
Reference in New Issue