Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tankSize = 3*3
- tankHeight = 4
- function refill(targetSlot, targetItems, fromSlot, toSlot)
- if turtle.getItemCount( targetSlot )<targetItems then
- for i=fromSlot, toSlot do
- if turtle.getItemCount ( i )~=0 then
- turtle.select( i )
- turtle.transferTo(targetSlot, turtle.getItemCount ( i ))
- if turtle.getItemCount( targetSlot )>=targetItems then
- turtle.select(targetSlot)
- return true
- end
- end
- end
- else
- return true
- end
- turtle.select(targetSlot)
- return false --if not enough items in the targetSlot
- end
- function countItemsInSlots(fromSlot, toSlot)
- local count = 0
- for i = fromSlot, toSlot do
- count = count + turtle.getItemCount(i)
- end
- return count
- end
- function enoughIronTankWallBlocks()
- if countItemsInSlots(1,4) < frameBlocks + lidBlocks then
- print("I don't have enough 'Iron Tank Wall' blocks!")
- print("I need ".. (frameBlocks + lidBlocks) - countItemsInSlots(1,4) .." more blocks!")
- return false
- end
- return true
- end
- function enoughIronTankGaugeBlocks()
- if countItemsInSlots(5,8) < sideBlocks then
- print("I don't have enough 'Iron Tank Gauge' blocks!")
- print("I need ".. (sideBlocks) - countItemsInSlots(5,8) .." more blocks!")
- return false
- end
- return true
- end
- function enoughBlocks()
- return (enoughIronTankWallBlocks() and enoughIronTankGaugeBlocks())
- end
- function OddOrEven(num, odd, even)
- if num%2 == 1 then
- return odd
- end
- return even
- end
- function even(num)
- return num%2 == 0
- end
- tankSize = math.sqrt(tankSize)
- function calculateSideBlocks()
- return (tankSize - 2) * (tankHeight - 2) * 4
- end
- function calculateLids()
- return (tankSize - 2)^2 * 2
- end
- function calculateFrame()
- return (tankHeight - 2) * 4 + (tankSize - 2) * 8 + 8
- end
- frameBlocks = calculateFrame()
- sideBlocks = calculateSideBlocks()
- lidBlocks = calculateLids()
- print("Tank size: "..tankSize.." | Tank height: "..tankHeight)
- print("Frame: " ..frameBlocks.. " blocks")
- print("Side: " ..sideBlocks.. " blocks")
- print("Lids: " ..lidBlocks.. " blocks")
- print("Total volume: ".. tankSize * tankHeight * tankSize * 16 .."mB")
- sleep(1)
- print("\nPut ".. frameBlocks + lidBlocks .." 'Iron Tank Wall' blocks in slots 1-4")
- print("Put ".. sideBlocks .." 'Iron Tank Gauge' blocks in slots 5-8")
- print("\nPress Enter to continue")
- while true do
- local event, key = os.pullEventRaw("key")
- if key == 28 then -- Enter
- break
- elseif key == 211 or key == 14 then -- Delete
- print("Exit...")
- error()
- end
- end
- enoughBlocks()
- while true do --true is necessary
- print("\nPress Enter to count blocks again")
- local event, key = os.pullEvent("key")
- if key == 28 then -- Enter
- if enoughBlocks() then break end
- elseif key == 211 or key == 14 then -- Delete
- print("Exit...")
- error()
- end
- end
- print("\n\n\n\n\n\n\n\n\n\nI have enough blocks, starting building the "..tankSize.."x"..tankHeight.."x"..tankSize.." tank!")
- function buildRow(buildDirection, moveDirection)
- for z = 1, tankSize do
- turtle[buildDirection]()
- if z~= tankSize then turtle[moveDirection]() end --dont outbreak from border
- end
- end
- function buildSurface(slot)
- turtle.select(slot)
- for x = 1, tankSize do
- buildRow("placeDown", OddOrEven(x, "forward", "back")) --switch movement direction every iteration
- if x ~= tankSize then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- refill(slot, 32, slot + 1, slot + 3)
- end
- end
- end
- function buildColumn(slot, buildDirection, moveDirection)
- turtle.select(slot)
- for y = 2, tankHeight - 2 do --1 block is already below us, the top will be built later
- turtle[moveDirection]()
- turtle[buildDirection]()
- refill(slot, 32, slot + 1, slot + 3)
- end
- end
- function buildWall(stay)
- buildColumn(1, "placeDown", "up")
- turtle.turnRight()
- for z = 2, tankSize - 1 do
- turtle.turnLeft()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- buildColumn(5, OddOrEven(z, "placeDown", "placeUp"), OddOrEven(z, "up", "down"))
- end
- if not stay then --nil or false
- --place a block where the turtle currently is and move to block on the right
- turtle.turnLeft()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- end
- end
- function buildTank()
- buildSurface(1)
- buildWall()
- buildWall()
- buildWall()
- buildWall(true)
- --go to the top
- turtle.back()
- turtle.place()
- for i = 2, tankHeight do
- turtle.up()
- end
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- buildSurface(1)
- end
- buildTank()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement