Skip to content

Instantly share code, notes, and snippets.

@Tiefseetauchner
Last active July 31, 2025 18:43
Show Gist options
  • Save Tiefseetauchner/8c872642886ba62317d740b769eb9216 to your computer and use it in GitHub Desktop.
Save Tiefseetauchner/8c872642886ba62317d740b769eb9216 to your computer and use it in GitHub Desktop.
-- === Installation ============================================
-- pastebin get rLAZsh4n gist
-- gist
-- gist get 8c872642886ba62317d740b769eb9216
-- === USER‑TUNEABLE CONSTANTS =================================
local FUEL_WARN = 32 -- if turtle.getFuelLevel() < FUEL_WARN → refuel
local SLOT_FUEL = 16 -- coal/charcoal
local SLOT_TORCH = 15
local SLOT_SLAB = 14
local SLOT_CABLE = 13
local SOLAR_FIRST = 1 -- solar panel stack slots 1‑12
local SOLAR_LAST = 12
local COLS_PER_ROW = 24 -- 24 grids × 2 panels = 48 panels / row
local ROW_COUNT = 1 -- set >1 if you’re doing multiple 48‑long rows
local DIR = {N = 0, E = 1, S = 2, W = 3}
-- base station coords
local base = {x = 0, y = 0, z = 0, dir = 0}
local moduleOffset = {x = 0, z = 4}
-- === STATE ===================================================
local pos = {x = 0, y = 0, z = 0, dir = 0} -- dir: 0=N,1=E,2=S,3=W
local saved = {} -- stack for return‑after‑restock
---------------------------------------------------------------
-- BASIC UTILS
---------------------------------------------------------------
local function turnLeft() turtle.turnLeft(); pos.dir = (pos.dir+3)%4 end
local function turnRight() turtle.turnRight(); pos.dir = (pos.dir+1)%4 end
local function turnTwice() turnLeft(); turnLeft(); end
local function _forwardInternal()
if turtle.forward() then
if pos.dir==DIR.N then pos.z = pos.z-1
elseif pos.dir==DIR.E then pos.x = pos.x+1
elseif pos.dir==DIR.S then pos.z = pos.z+1
else pos.x = pos.x-1 end
return true
end
return false
end
local function forward(n)
if n == nil then
return _forwardInternal()
end
for i=1,n do
if not _forwardInternal() then
return false
end
end
return true
end
local function face(dir)
local turns = (dir - pos.dir + 4) % 4
if turns == 1 then turnRight()
elseif turns == 2 then turnTwice()
elseif turns == 3 then turnLeft() end
end
local function go(dir, n)
if dir == nil then error("64(go): Cannot go in no direction!") end
if n ~= nil and n < 0 then
dir = (dir + 2) % 4
n = n * -1
end
face(dir)
return forward(n)
end
local function goXPos(x)
go(DIR.E, x - pos.x)
end
local function goZPos(z)
go(DIR.S, z - pos.z)
end
local function up()
if turtle.up() then pos.y = pos.y+1; return true end
return false
end
local function down()
if turtle.down() then pos.y = pos.y-1; return true end
return false
end
local function placeForward(slot)
turtle.select(slot)
turtle.place()
end
local function placeDown(slot)
turtle.select(slot)
turtle.placeDown()
end
---------------------------------------------------------------
-- Placement Logic
---------------------------------------------------------------
-- We assume we're in the SE corner when starting this function
-- and no cables have been placed
local function placePanels()
startSlot = 1
for i=SOLAR_FIRST,SOLAR_LAST do
if turtle.getItemCount(i) > 0 then
startSlot = i
break
end
end
go(DIR.W, 2)
go(DIR.N)
face(DIR.E)
placeForward(startSlot)
go(DIR.W)
placeForward(startSlot + 1)
go(DIR.S)
go(DIR.E, 3)
face(DIR.N)
end
-- We assume we're in the SE corner when starting this function
local function placeCables()
up()
go(DIR.W, 2)
placeDown(SLOT_CABLE)
go(DIR.N)
placeDown(SLOT_CABLE)
go(DIR.N)
placeDown(SLOT_CABLE)
go(DIR.W)
go(DIR.S)
placeDown(SLOT_CABLE)
go(DIR.S)
go(DIR.E, 3)
face(DIR.N)
end
-- We assume we're in the SE corner when starting this function
local function placeFloor()
placeDown(SLOT_SLAB)
for i=1,5 do
go(DIR.W)
placeDown(SLOT_SLAB)
end
go(DIR.E, 5)
go(DIR.N)
placeDown(SLOT_SLAB)
for i=1,5 do
go(DIR.W)
placeDown(SLOT_SLAB)
end
go(DIR.E, 5)
go(DIR.N)
placeDown(SLOT_SLAB)
for i=1,5 do
go(DIR.W)
placeDown(SLOT_SLAB)
end
go(DIR.E, 5)
go(DIR.S, 2)
end
-- We assume we're in the SE corner when starting this function
local function moveToModule(x,z)
actualX = moduleOffset.x + ((x - 1) * 6)
actualZ = -1 * moduleOffset.z + ((z - 1) * 3)
-- Get to safe moving position
up()
go(DIR.W, 2)
-- Move to module
goZPos(actualZ)
goXPos(actualX)
down()
face(DIR.N)
end
-- We assume we're in the SE corner when starting this function
-- with a module placed
local function returnToBase()
up()
go(DIR.W, 2)
-- We're at a safe pos to move back to home now
go(DIR.S, pos.x)
go(DIR.E, pos.z)
face(DIR.N)
down()
end
local function placeModule()
placeFloor()
placePanels()
placeCables()
end
local function refuel()
turtle.select(SLOT_FUEL)
turtle.refuel(64)
end
local function needsToRefill()
local solarPanelCount = 0
for i=SOLAR_FIRST,SOLAR_LAST do
if turtle.getItemCount(i) > 0 then
solarPanelCount = solarPanelCount + 1
end
end
return solarPanelCount < 2 or
turtle.getItemCount(SLOT_FUEL) < 16 or
turtle.getItemCount(SLOT_TORCH) < 2 or
turtle.getItemCount(SLOT_SLAB) < 18 or
turtle.getItemCount(SLOT_CABLE) < 4;
end
-- We assume we're at home base
local function refill()
goZPos(1)
goXPos(2)
face(DIR.S)
for i=SOLAR_FIRST,SOLAR_LAST do
turtle.select(i)
turtle.suck()
end
goXPos(6)
face(DIR.S)
turtle.suck()
turtle.select(SLOT_FUEL)
goXPos(5)
face(DIR.S)
turtle.select(SLOT_TORCH)
turtle.suck()
goXPos(4)
face(DIR.S)
turtle.select(SLOT_SLAB)
turtle.suck()
goXPos(3)
face(DIR.S)
turtle.select(SLOT_CABLE)
turtle.suck()
end
---------------------------------------------------------------
-- Entrypoint
---------------------------------------------------------------
local function main()
for i=1,ROW_COUNT do
for j=1,COLS_PER_ROW do
refuel()
if needsToRefill() then
returnToBase()
refill()
returnToBase()
end
moveToModule(j, i)
placeModule()
end
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment