Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------
- -- A program to place the excavator
- -- from Immersive Engineering.
- --
- -- Needed items:
- -- Slot 1: 23 Steel Scaffoldings
- -- Slot 2: 21 Blocks of steel
- -- Slot 3: 13 Heavy Engineering Blocks
- -- Slot 4: 9 Light Engineering Blocks
- --
- -- Make sure you clear out a nice
- -- 8x3x7 area.
- --------------------------------------
- local missingMessage = "Missing items: "
- local matrix = {
- {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}},
- {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 2, 1, 1, 1, 2, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}},
- {{0, 0, 3, 3, 3, 2, 4, 2}, {0, 1, 1, 1, 1, 1, 0, 2}, {0, 0, 3, 4, 3, 2, 3, 3}},
- {{0, 0, 3, 3, 3, 2, 4, 2}, {2, 1, 1, 2, 1, 1, 2, 3}, {0, 0, 4, 4, 4, 2, 2, 4}},
- {{0, 0, 1, 1, 1, 2, 4, 2}, {0, 1, 1, 1, 1, 1, 0, 2}, {0, 0, 0, 4, 0, 2, 3, 3}},
- {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 2, 1, 1, 1, 2, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}},
- {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}
- }
- local blocks = {
- {"Steel Scaffoldings", 23},
- {"Steel Blocks", 21},
- {"Heavy Engineering Blocks", 13},
- {"Light Engineering Blocks", 9}}
- --------------------------------------
- -- Don't touch things under here...
- -- ... yeah you!
- --------------------------------------
- function tableLen(T)
- local cnt = 0
- for _ in pairs(T) do cnt = cnt + 1 end
- return cnt
- end
- local maxHeight = tableLen(matrix)
- local maxWidth = tableLen(matrix[1])
- local maxDepth = tableLen(matrix[1][1])
- local position = {forward=1, right=1, up=0, face=1}
- local facing = { "forward", "right", "back", "left" }
- function _facingToNumber( direction )
- if direction == "forward" then return 1 end
- if direction == "right" then return 2 end
- if direction == "back" then return 3 end
- if direction == "left" then return 4 end
- return 0
- end
- function TurnTo( direction )
- local directionNum = _facingToNumber( direction )
- while facing[position.face] ~= direction do
- local difference = directionNum - position.face
- if difference == -1 or difference == 3 then
- turtle.turnLeft()
- position.face = position.face - 1
- else
- turtle.turnRight()
- position.face = position.face + 1
- end
- if position.face == 5 then position.face = 1 end
- if position.face == 0 then position.face = 4 end
- end
- end
- function Forward( amount )
- amount = amount or 1
- for i=1,amount do
- assert(turtle.forward(), "I got stuck! Give me more fuel next time and/or clear the area. You have to rerun me from the begining.")
- -- Update Position
- if position.face == 1 then position.forward = position.forward + 1 end
- if position.face == 3 then position.forward = position.forward - 1 end
- if position.face == 2 then position.right = position.right + 1 end
- if position.face == 4 then position.right = position.right - 1 end
- end
- end
- function Up( amount )
- amount = amount or 1
- for i=1,amount do
- assert(turtle.up(), "I got stuck! Give me more fuel next time and/or clear the area. You have to rerun me from the begining.")
- position.up = position.up + 1
- end
- end
- function Down( amount )
- amount = amount or 1
- for i=1,amount do
- turtle.down()
- position.up = position.up - 1
- end
- end
- function MoveTo(forward, right, up)
- local forwardMovement = forward - position.forward
- local rightMovement = right - position.right
- local upMovement = up - position.up
- if forwardMovement > 0 then
- TurnTo("forward")
- Forward(forwardMovement)
- end
- if forwardMovement < 0 then
- TurnTo("back")
- Forward(math.abs(forwardMovement))
- end
- if rightMovement > 0 then
- TurnTo("right")
- Forward(rightMovement)
- end
- if rightMovement < 0 then
- TurnTo("left")
- Forward(math.abs(rightMovement))
- end
- if upMovement < 0 then
- Down(upMovement)
- end
- if upMovement > 0 then
- Up(math.abs(upMovement))
- end
- end
- -- Intial Fun
- term.clear()
- term.setCursorPos(1,1)
- function checkForNeeded()
- local toReturn = true
- local cnt = 1
- for i, v in pairs(blocks) do
- toReturn = checkSlot(i, v[2], v[1]) and toReturn
- end
- return toReturn
- end
- function checkSlot(slotNum, itemAmount, itemName)
- if turtle.getItemCount(slotNum) < itemAmount then
- missingMessage = missingMessage .. "\n - " .. itemAmount .. " " .. itemName .. " [Slot " .. slotNum .. "]"
- return false
- else
- return true
- end
- end
- function placeMatrix()
- for height = 1,maxHeight do
- for width = 1,maxWidth do
- for depth = 1,maxDepth do
- if matrix[height][width][depth] > 0 then
- MoveTo(depth, width, height)
- placeBlock(matrix[height][width][depth])
- end
- end
- end
- end
- end
- function placeBlock(slotNum)
- if slotNum > 0 then
- turtle.select(slotNum)
- assert(turtle.placeDown(), "Either clear the area or give me permission to place a block. You'll have to start over.")
- end
- end
- -- Do all the stuff!
- if not checkForNeeded() then
- print(missingMessage)
- return
- end
- print("Running...")
- placeMatrix()
- print("Finished running...")
Add Comment
Please, Sign In to add comment