Skip to content

Instantly share code, notes, and snippets.

@davidfooks
Created December 20, 2019 17:38
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/aaf4cba088d72503691c6c8c6c4d78d1 to your computer and use it in GitHub Desktop.
Save davidfooks/aaf4cba088d72503691c6c8c6c4d78d1 to your computer and use it in GitHub Desktop.
function getBlockType(p)
local c = boundless.ChunkCoord(p)
local blockType
boundless.loadChunkAnd8Neighbours(c, function (chunks)
local v = boundless.getBlockValues(boundless.BlockCoord(p))
blockType = v.blockType
end)
return blockType
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
local lastBlock
local function onEnterFrame()
for c in boundless.connections() do
local e = boundless.getEntity(c:get_id())
if e then
blockPosUnderFeet = e:get_position():withYOffset(-0.5)
blockType = getBlockType(blockPosUnderFeet)
-- 0 is AIR block type
-- 10858-10862 are the (un-chiseled) TANGLE block types
-- so this checks if you are in the AIR and you were on a TANGLE block
if blockType == 0 and lastBlock >= 10858 and lastBlock < 10862 then
for x = -3,3 do
for z = -3,3 do
-- create a TANGLE (10858) block with a random color!
setBlock(math.floor(blockPosUnderFeet.x + x),
math.floor(blockPosUnderFeet.y - 1),
math.floor(blockPosUnderFeet.z + z),
10858, --TANGLE
math.random(255)) --random color
end
end
end
lastBlock = blockType
end
end
end
function stop()
boundless.removeEventListener(boundless.onEnterFrame, onEnterFrame)
end
boundless.addEventListener(boundless.onEnterFrame, onEnterFrame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment