This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
93 lines (78 loc) · 2.25 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
--find block position
local _POSITION_ = { commands.getBlockPosition() }
local tArgs = { ... }
if #tArgs < 1 or #tArgs > 3 then
print( "Usage: platform <username> [radius] [block]" )
error()
end
if not commands then
error( "This program requires a command computer", 0 )
end
local rad = tonumber( tArgs[ 2 ] ) or 2
local block = tArgs[ 3 ] or "minecraft:glass"
local platform = {}
local function fillP()
for x = -rad, rad do
for z = -rad, rad do
if math.sqrt( x ^ 2 + z ^ 2 ) <= rad then
platform[ #platform + 1 ] = vector.new( x, 0, z )
end
end
end
end
local function getPlayerPosition( p )
local success, t = commands.exec( "/tp " .. p .. " ~ ~ ~" )
if not success then
error( "Invalid Player or Block", 0 )
end
local x, y, z = t[1]:match( "to (%-?%d+%.?%d*),(%-?%d+%.?%d*),(%-?%d+%.?%d*)" )
return math.floor( x ), math.floor( y ), math.floor( z )
end
local id = os.startTimer( 0.3 )
local last = {}
local current = {}
local pos
local toExecute = {}
local function checkPlatform()
while #platform > 0 do
local v = table.remove( platform, #platform )
local b = pos + v
local bstr = b:tostring()
local name = (last[bstr] and "minecraft:glass") or commands.getBlockInfo( b.x, b.y, b.z ).name
if name == "minecraft:air" then
current[ bstr ] = b
if not last[ bstr ] then
toExecute[ #toExecute + 1 ] = "setblock " .. b.x .. " " .. b.y .. " " .. b.z .. " " .. block
end
elseif name == "minecraft:glass" then
current[ bstr ] = b
end
last[ bstr ] = nil
end
end
while true do
local x, y, z = getPlayerPosition( tArgs[ 1 ] )
pos = vector.new( x, y - 1, z )
local time = os.clock()
fillP()
parallel.waitForAll( checkPlatform, checkPlatform, checkPlatform, checkPlatform, checkPlatform )
for k, v in pairs( last ) do
toExecute[ #toExecute + 1 ] = "setblock " .. v.x .. " " .. v.y .. " " .. v.z .. " minecraft:air"
end
for k, v in pairs( toExecute ) do
commands.execAsync( v )
end
last = current
current = {}
toExecute = {}
if os.clock() - time >= 0.3 then
os.queueEvent( "timer", id )
end
while true do
local event, tid = os.pullEvent( "timer" )
if id == tid then
break
end
end
id = os.startTimer( 0.3 )
end