Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Copyright by Pascal-HP.de 2017
- -> To lazy to whole out a room? This script will do that for you ;)
- ]]
- textutils.slowPrint("Welcome to kronova room builder.)")
- textutils.slowPrint("Please note: The turtle builds from\nthe left to the right side!")
- print([[
- Slot IDs:
- -----------
- | 1| 2| 3| 4|
- | 5| 6| 7| 8|
- | 9|10|11|12|
- |13|14|15|16|
- -----------
- ]])
- function digBlocks()
- -- break block(s)
- while turtle.detect() do
- turtle.dig()
- end
- end
- function digBlocksUp()
- -- break block(s)
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function digBlocksDown()
- -- break block(s)
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- --[[ inspects the item in direction and returns the nameDamage value ]]
- function inspectItemNameDamage(direction)
- if direction == "up" then
- local success, itemDetail = turtle.inspectUp()
- if success then
- return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
- end
- elseif direction == "down" then
- local success, itemDetail = turtle.inspectDown()
- if success then
- return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
- end
- else
- local success, itemDetail = turtle.inspect()
- if success then
- return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
- end
- end
- end
- --[[ places item in direction if target block is not equal to the slot item
- ]]
- function digAndPlaceBlock(direction)
- if direction == "up" then
- if inspectItemNameDamage("up") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
- digBlocksUp()
- turtle.placeUp()
- end
- elseif direction == "down" then
- if inspectItemNameDamage("down") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
- digBlocksDown()
- turtle.placeDown()
- end
- else
- if inspectItemNameDamage("") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
- digBlocks()
- turtle.place()
- end
- end
- end
- --[[ reads a number and validates if there is a item in it.
- returns the slot id if there are items in it ]]
- function selectItemSlot()
- repeat
- continue = false
- write(" SlotID: ")
- slotId = io.read()
- if slotId ~= "" then
- slotId = tonumber(slotId)
- if slotId > 0 and slotId < 17 then
- turtle.select(slotId)
- if turtle.getItemCount() > 0 then
- continue = true
- else
- print("You have to put an item into that slot!")
- end
- else
- print("SlotID must between 1-16!")
- end
- else
- print("SlotID must between 1-16!")
- end
- until continue == true
- return slotId
- end
- --[[ selects and returns name, damage or count of this item if possible.
- returnValue can be: name, damage, count, nameDamage ]]
- function selectAndGetItemDetail(slotNumber, returnValue)
- turtle.select(slotNumber)
- local itemDetail = turtle.getItemDetail()
- if itemDetail then
- if returnValue == "name" then
- return itemDetail.name
- elseif returnValue == "damage" then
- return itemDetail.damage
- elseif returnValue == "nameDamage" then
- return itemDetail.name .. "::" .. tostring(itemDetail.damage)
- else
- return itemDetail.count
- end
- else
- return false
- end
- end
- --[[ compares the item with the currently selected item
- returns true if identical else false
- use function selectAndGetItemDetail(slotNumber, "nameDamage")
- for param nameDamage ]]
- function compareItem(nameDamage)
- if selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") == nameDamage then
- return true
- else
- return false
- end
- end
- --[[ selects an item by nameDamage value.
- use selectAndGetItemDetail(slotNumber, "nameDamage") to get nameDamage value ]]
- function selectItemByNameDamage(nameDamage)
- continue = false
- repeat
- loop = 1
- while loop < 17 do
- if selectAndGetItemDetail(loop, "nameDamage") == nameDamage then
- return true
- end
- loop = loop + 1
- end
- print("Please put more " .. nameDamage .. " into the turtle and press ENTER!")
- inputString = io.read()
- until continue == true
- end
- -- deprecated: will be removed soon
- function selectAndCheckItem(slotNumber, slotName)
- turtle.select(slotNumber)
- if turtle.getItemCount() < 2 then
- print("Please insert more " .. slotName .. " into slot " .. slotNumber)
- while turtle.getItemCount() < 2 do
- os.queueEvent("randomEvent")
- os.pullEvent()
- end
- end
- end
- function checkFuel()
- while turtle.getFuelLevel() <= 0 do
- print("No fuel left, going to refuel...")
- selectItemByNameDamage(fuelSlot)
- turtle.refuel(turtle.getItemCount())
- print("Fuelled turtle. New fuel level: " .. turtle.getFuelLevel())
- end
- end
- --[[ moves like turtle.forward(), back(), up(), down() but additionally checks
- if there is a mob in its way ]]
- function moveTurtle(direction)
- movement = false
- while (not turtle.inspect() and not movement) do
- if direction == "forward" then
- movement = turtle.forward()
- elseif direction == "back" then
- movement = turtle.back()
- elseif direction == "up" then
- movement = turtle.up()
- elseif direction == "down" then
- movement = turtle.down()
- else
- print("Unknown movement! (" .. movement .. ")")
- return false
- end
- if not movement then
- turtle.attack()
- print("Attack!!!")
- end
- end
- end
- function checkYesOrNo()
- input = io.read()
- if input == "y" then
- return true
- else
- return false
- end
- end
- repeat
- -- fuelSlot - Put coal or lava bucket into this slot!
- print("\nSelect fuel slot: ")
- fuelSlot = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. fuelSlot)
- -- room width
- write("\nRoom width in blocks: ")
- roomWidth = tonumber(io.read())
- -- room length
- write("\nRoom length in blocks: ")
- roomLength = tonumber(io.read())
- -- room height
- write("\nRoom height in blocks: ")
- roomHeight = tonumber(io.read())
- print("\n\n-> Viewpoint is the position of the turtle!")
- print("\n\nShould I build the blanket (wall on top) for you? y/N: ")
- if (checkYesOrNo()) then
- print("\n\nMaterial slot for the blanket (wall on top):")
- wallMaterialTop = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialTop)
- Blanket = true
- end
- print("\n\nShould I build the floor for you? y/N: ")
- if (checkYesOrNo()) then
- print("\nMaterial slot for the floor (wall at the bottom):")
- wallMaterialBottom = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialBottom)
- Floor = true
- end
- print("\n\nShould I build the front wall for you? y/N: ")
- if (checkYesOrNo()) then
- print("\nMaterial slot for the front wall:")
- wallMaterialFront = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialFront)
- FrontWall = true
- end
- print("\n\nShould I build the back wall for you? y/N: ")
- if (checkYesOrNo()) then
- print("\nMaterial slot for the back wall:")
- wallMaterialBack = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialBack)
- BackWall = true
- end
- print("\n\nShould I build the left wall for you? y/N: ")
- if (checkYesOrNo()) then
- print("\nMaterial slot for the left wall:")
- wallMaterialLeft = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialLeft)
- LeftWall = true
- end
- print("\n\nShould I build the right wall for you? y/N: ")
- if (checkYesOrNo()) then
- print("\nMaterial slot for the right wall:")
- wallMaterialRight = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
- print(" Selected: " .. wallMaterialRight)
- end
- textutils.slowPrint("\n\nEnter 'y' to start building or any other key to repeat.")
- startJob = string.lower(io.read())
- until startJob == "y"
- textutils.slowPrint("Starting... Go away and dont block the Turtle!!!")
- for totalLength = 1, roomLength, 1 do
- print("Mining in row " .. totalLength)
- checkFuel()
- --
- for totalWidth = 1, roomWidth, 1 do
- for totalHeight = 1, roomHeight, 1 do
- -- wall on the left side
- if totalWidth == 1 then
- turtle.turnLeft()
- selectItemByNameDamage(wallMaterialLeft)
- digAndPlaceBlock("")
- turtle.turnRight()
- end
- -- wall on the right side
- if totalWidth == roomWidth then
- turtle.turnRight()
- selectItemByNameDamage(wallMaterialRight)
- digAndPlaceBlock("")
- turtle.turnLeft()
- end
- -- wall at the bottom
- if totalHeight == 1 then
- selectItemByNameDamage(wallMaterialBottom)
- digAndPlaceBlock("down")
- end
- -- wall on top
- if totalHeight == roomHeight then
- selectItemByNameDamage(wallMaterialTop)
- digAndPlaceBlock("up")
- end
- -- wall on the back
- if totalLength == 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- selectItemByNameDamage(wallMaterialBack)
- digAndPlaceBlock("")
- turtle.turnRight()
- turtle.turnRight()
- end
- -- wall on the front
- if totalLength == roomLength then
- selectItemByNameDamage(wallMaterialFront)
- digAndPlaceBlock("")
- end
- if totalLength ~= roomLength then
- -- destroy block(s)
- digBlocks()
- end
- -- go up if not last operation
- if totalHeight < roomHeight then
- digBlocksUp()
- moveTurtle("up")
- end
- end
- -- go to primary position
- for totalHeight = 1, roomHeight - 1, 1 do
- digBlocksDown()
- moveTurtle("down")
- end
- -- next column
- if totalWidth < roomWidth then
- turtle.turnRight()
- digBlocks()
- moveTurtle("forward")
- turtle.turnLeft()
- end
- end
- -- go to primary position
- turtle.turnLeft()
- for totalWidth = 1, roomWidth - 1, 1 do
- digBlocks()
- moveTurtle("forward")
- end
- turtle.turnRight()
- digBlocks()
- moveTurtle("forward")
- end
- -- go to primary position
- for totalLength = 1, roomLength - 1, 1 do
- moveTurtle("back")
- end
- print("room finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement