Skip to content

Instantly share code, notes, and snippets.

@mworzala
Created July 4, 2024 21:37
Show Gist options
  • Save mworzala/6598df60e6edc207bcc6dece01d7f7c8 to your computer and use it in GitHub Desktop.
Save mworzala/6598df60e6edc207bcc6dece01d7f7c8 to your computer and use it in GitHub Desktop.
local player = script.Parent
local world = player.World
BRIDGE_MIN = vec(16, 45, -51)
BRIDGE_MAX = vec(27, 45, -47)
PLAYER_BB_OFFSETS = {
vec(-0.3, 0, -0.3),
vec(0.3, 0, -0.3),
vec(-0.3, 0, 0.3),
vec(0.3, 0, 0.3),
}
function fill(from: vector, to: vector, block: BlockType)
for x = from.x, to.x do
for y = from.y, to.y do
for z = from.z, to.z do
world:SetBlock(vec(x, y, z), block)
end
end
end
end
function floorvec(v: vector): vector
return vec(math.floor(v.x), math.floor(v.y), math.floor(v.z))
end
pendingBlocks = {}
function OnTick()
local blockPos = player.Position - vec(0, 1, 0)
for _, offset in PLAYER_BB_OFFSETS do
local pos = blockPos + offset
if world:GetBlock(pos) ~= blocks.GRAY_WOOL then
return
end
pos = floorvec(pos)
if pendingBlocks[pos] then
return
end
pendingBlocks[pos] = true
system:RunLater(10, function()
world:SetBlock(pos, blocks.AIR)
world:SpawnEntity("minecraft:falling_block", pos + vec(0.5, 0, 0.5), {})
end)
end
end
function OnLeverFlipped(pos: vector, block: BlockType): boolean
if block ~= blocks.LEVER or block["powered"] ~= "false" then
return false -- Do not allow the block interaction (cancel it basically)
end
-- Build the bridge
world:SetBlock(pos, block{ powered = "true" })
fill(BRIDGE_MIN, BRIDGE_MAX, blocks.LIME_CONCRETE)
return true
end
world.OnTick:Listen(OnTick)
world.OnBlockInteract:Listen(OnLeverFlipped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment