Skip to content

Instantly share code, notes, and snippets.

@davidfooks
Created December 20, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfooks/44a4966fa919cacf274207ac7d9aded8 to your computer and use it in GitHub Desktop.
Save davidfooks/44a4966fa919cacf274207ac7d9aded8 to your computer and use it in GitHub Desktop.
-- requires a maze.txt file
function readAll(file)
local f = assert(io.open(file, "rb"))
local content = f:read("*all")
f:close()
return content
end
function setBlock(x, y, z, blockType, color)
local p = boundless.wrap(boundless.UnwrappedBlockCoord(x, y, z))
local c = boundless.ChunkCoord(p)
boundless.loadChunkAnd8Neighbours(c, function (chunks)
local v = boundless.getBlockValues(p)
v.blockType = blockType
v.blockMeta = 0
v.blockColorIndex = color
boundless.setBlockValues(p, v)
end)
end
mazeStr = readAll('maze.txt')
--print('\n' .. mazeStr)
local maze_pos
for c in boundless.connections() do
local e = boundless.getEntity(c:get_id())
if e then
local player_pos = e:get_position():withYOffset(-0.5)
maze_pos = boundless.wrap(boundless.UnwrappedBlockCoord(
math.floor(player_pos.x + 16),
math.floor(player_pos.y),
math.floor(player_pos.z)))
end
end
local x = 0;
local z = 0;
for line in mazeStr:gmatch("[^\r\n]+") do
local t = ''
for i = 1, #line do
local c = line:sub(i,i)
t = t .. c
if c == 'X' then
for y = 16, 24 do
setBlock(math.floor(maze_pos.x + x),
y,
math.floor(maze_pos.z + z),
11265, -- ROCK_MARBLE_REFINED
188) -- color
end
end
z = z + 1
end
print(t)
x = x + 1
z = 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment