View difference between Paste ID: FnAkbqXu and VAFUMNgf
SHOW: | | - or go back to the newest paste.
1-
if not fs.exists "json" then local a=http.get"https://raw.githubusercontent.com/rxi/json.lua/bee7ee3431133009a97257bde73da8a34e53c15c/json.lua"local b=fs.open("json","w")b.write(a.readAll())a.close()b.close() end
1+
2-
local json = require "/json"
2+
3
local mon = peripheral.find "monitor"
4
if mon then mon.setTextScale(0.5) term.redirect(mon) end
5
6
local function fetch(url)
7
	local h = http.get(url)
8
	local o = h.readAll()
9
	h.close()
10
	return o
11
end
12
13
local target = ...
14
local operator = "gollark"
15-
local worlds = {
15+
local canvas3 = peripheral.call("back", "canvas3d").create()
16-
	world = "overworld",
16+
setmetatable(canvas3, {
17-
	DIM1_the_end = "end",
17+
	__gc = function() canvas3.clear() end
18-
	DIM1 = "end",
18+
})
19-
	["DIM-1"] = "nether",
19+
--local box = canvas3.addBox(0, 0, 0)
20-
	["DIM-11325"] = "deepdark"
20+
local line = canvas3.addLine({0, 0, 0}, {0, 0, 0})
21-
}
21+
line.setScale(4)
22
23-
local function render_coords(player)
23+
parallel.waitForAll(function()
24-
	return ("%0d %0d %0d"):format(player.x, player.y, player.z)
24+
25
	local raw = fetch(API .. os.epoch "utc")
26
	local data = textutils.unserialiseJSON(raw)
27-
local function render_pos(player)
27+
28-
	local coords = render_coords(player)
28+
	local op
29-
	if player.x == 0 and player.y == 64 and player.z == 0 then coords = "[unknown]" end
29+
	local tplayer
30-
	return coords .. " " .. (worlds[player.world] or player.world)
30+
	for _, player in pairs(players) do
31
		if player.name:match(target) then tplayer = player end
32
		if player.name == operator then op = player end
33-
local w, h = term.getSize()
33+
34
	if tplayer then
35-
local function longest_by(t, k)
35+
		local tvec = vector.new(tplayer.x, tplayer.y, tplayer.z)
36-
	local sofar = 0
36+
		local ovec = vector.new(op.x, op.y, op.z)
37-
	for _, v in pairs(t) do
37+
		local dirvec = (tvec - ovec):normalize() * 10
38-
		if k then v = v[k] end
38+
		print(tostring(dirvec))
39-
		if #v > sofar then
39+
		line.setPoint(2, dirvec.x, dirvec.y, dirvec.z)
40-
			sofar = #v
40+
41-
		end
41+
	sleep(1)
42
end end, function() while true do canvas3.recenter() sleep(0.1) end end)