Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Ragy's scheme creating program
- Warning: After converting into scheme you're bilding will be destroyed.
- Warning: Turtle can't recognise block types in inventory, this program work with inventory slots
- My email is [email protected]
- ]]--
- function fSetDirection(sDirection)
- if(sMyDirection=="+y") then
- if(sDirection=="+y") then
- end
- if(sDirection=="-y") then
- turtle.turnRight()
- turtle.turnRight()
- sMyDirection="-y"
- end
- if(sDirection=="+x") then
- turtle.turnRight()
- sMyDirection="+x"
- end
- if(sDirection=="-x") then
- turtle.turnLeft()
- sMyDirection="-x"
- end
- end
- if(sMyDirection=="-y") then
- if(sDirection=="+y") then
- turtle.turnRight()
- turtle.turnRight()
- sMyDirection="+y"
- end
- if(sDirection=="-y") then
- end
- if(sDirection=="+x") then
- turtle.turnLeft()
- sMyDirection="+x"
- end
- if(sDirection=="-x") then
- turtle.turnRight()
- sMyDirection="-x"
- end
- end
- if(sMyDirection=="+x") then
- if(sDirection=="+y") then
- turtle.turnLeft()
- sMyDirection="+y"
- end
- if(sDirection=="-y") then
- turtle.turnRight()
- sMyDirection="-y"
- end
- if(sDirection=="+x") then
- end
- if(sDirection=="-x") then
- turtle.turnRight()
- turtle.turnRight()
- sMyDirection="-x"
- end
- end
- if(sMyDirection=="-x") then
- if(sDirection=="+y") then
- turtle.turnRight()
- sMyDirection="+y"
- end
- if(sDirection=="-y") then
- turtle.turnLeft()
- sMyDirection="-y"
- end
- if(sDirection=="+x") then
- turtle.turnRight()
- turtle.turnRight()
- sMyDirection="+x"
- end
- if(sDirection=="-x") then
- end
- end
- end
- function fMove(sDirection,iDistance)
- if(iDistance==0) then
- return
- end
- while(iDistance<0) do
- if(sDirection=="+y") then
- sDirection="-y"
- iDistance=(iDistance^2)^0.5
- break
- end
- if(sDirection=="-y") then
- sDirection="+y"
- iDistance=(iDistance^2)^0.5
- break
- end
- if(sDirection=="+x") then
- sDirection="-x"
- iDistance=(iDistance^2)^0.5
- break
- end
- if(sDirection=="-x") then
- sDirection="+x"
- iDistance=(iDistance^2)^0.5
- break
- end
- if(sDirection=="+z") then
- sDirection="-z"
- iDistance=(iDistance^2)^0.5
- break
- end
- if(sDirection=="-z") then
- sDirection="+z"
- iDistance=(iDistance^2)^0.5
- break
- end
- end
- if(sDirection=="+y" or sDirection=="-y" or sDirection=="+x" or sDirection=="-x") then
- fSetDirection(sDirection)
- if(bWriting==true) then
- fSetBlock()
- end
- for n=1,iDistance,1 do
- while(turtle.forward()~=true) do
- if(sMode=="replace") then
- turtle.dig()
- end
- if(sMode=="peacefull") then
- fChangeMode("forward")
- turtle.dig()
- end
- end
- if(sDirection=="+y") then
- y=y+1
- end
- if(sDirection=="-y") then
- y=y-1
- end
- if(sDirection=="+x") then
- x=x+1
- end
- if(sDirection=="-x") then
- x=x-1
- end
- end
- end
- if(sDirection=="+z") then
- for n=1,iDistance,1 do
- while(turtle.up()~=true) do
- if(sMode=="replace") then
- turtle.digUp()
- end
- if(sMode=="peacefull") then
- fChangeMode("up")
- turtle.digUp()
- end
- end
- end
- end
- if(sDirection=="-z") then
- for n=1,iDistance,1 do
- while(turtle.down()~=true) do
- if(sMode=="replace") then
- turtle.digDown()
- end
- if(sMode=="peacefull") then
- fChangeMode("down")
- turtle.digDown()
- end
- end
- end
- end
- end
- function fGoToPos(iNewX,iNewY,iNewZ)
- if(iNewX==nil) then
- iNewX=x
- end
- if(iNewY==nil) then
- iNewY=y
- end
- if(iNewZ==nil) then
- iNewZ=z
- end
- iNewX=iNewX-x
- iNewY=iNewY-y
- iNewZ=iNewZ-z
- fMove("+x",iNewX)
- fMove("+y",iNewY)
- fMove("+z",iNewZ)
- end
- function fTurtleGetBlockType()
- if(turtle.detect()==true) then
- if(iEarlyerType~=nil) then
- turtle.select(iEarlyerType)
- if(turtle.compare()==true) then
- return(tAllowedBlocks[iEarlyerType][1])
- end
- end
- local n=1
- for n=1,9,1 do
- turtle.select(n)
- if(turtle.compare()==true) then
- iEarlyerType=n
- return(tAllowedBlocks[n][1])
- end
- n=n+1
- end
- return(tAllowedBlocks[1][1])
- end
- end
- function fSetBlock()
- local sBlock=fTurtleGetBlockType()
- if(sMyDirection=="+y" and iBuildingZonelength>=(y+1)) then
- if(sBlock~=nil) then
- tLayer[y+1][x]=sBlock
- return
- else
- tLayer[y+1][x]="e"
- return
- end
- end
- if(sMyDirection=="-y" and (y-1)>=1) then
- if(sBlock~=nil) then
- tLayer[y-1][x]=sBlock
- return
- else
- tLayer[y-1][x]="e"
- return
- end
- end
- if(sMyDirection=="+x" and (x+1)<=iBuildingZoneWidth) then
- if(sBlock~=nil) then
- tLayer[y][x+1]=sBlock
- return
- else
- tLayer[y][x+1]="e"
- return
- end
- end
- if(sMyDirection=="-x" and (y-1)>=1) then
- if(sBlock~=nil) then
- tLayer[y][x-1]=sBlock
- return
- else
- tLayer[y][x-1]="e"
- return
- end
- end
- end
- function fWriteScheme(iLayerId)
- fileScheme:write("Layer "..iLayerId.."\n")
- local g=1
- for n=1,iBuildingZonelength,1 do
- fileScheme:write(string.reverse(tLayer[g]).."\n")
- g=g+1
- end
- fileScheme:write("end")
- if(iLayerId~=iBuildingZoneHeight) then
- fileScheme:write("\n")
- end
- end
- function fTabToString(tTab)
- local sStr=""
- for i,v in pairs(tTab) do sStr=sStr..v end
- --print(sStr)
- return(sStr)
- end
- local tArgs = { ... }
- if #tArgs < 1 then
- print( "Usage: smkr <scheme name>")
- return
- end
- sSchemeName=tArgs[1]
- tAllowedBlocks={}
- x=1
- y=0
- z=1
- sMyDirection="+y"
- sMode="replace"
- bWriting=false
- iEarlyerType=1
- term.clear()
- term.setCursorPos(1,1)
- if(fs.exists("/"..sSchemeName)==true) then
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("This file already exists. Do you want replace it?")
- write("y/n:")
- sInput=read()
- if(sInput=="y") then
- break
- end
- if(sInput=="n") then
- return
- end
- end
- end
- if(true) then
- print("Input Description")
- local sInput=read()
- fileScheme=io.open("/"..sSchemeName,"w")
- fileScheme:write("Turtle building scheme\n"..sSchemeName.."\n"..sInput.."\n")
- local n=1
- tAllowedBlocks={{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"},{"b","stone"}}
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("Do you want use standart block types?")
- local v=1
- for n=1,9,1 do
- print(tAllowedBlocks[v][1].."-"..tAllowedBlocks[v][2].." slot "..v)
- v=v+1
- end
- write("y/n:")
- sInput=read()
- if(sInput=="y") then
- break
- end
- if(sInput=="n") then
- for n=1,9,1 do
- local sInput
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("Input block id for slot "..n.." or input (default) to set rest of blocks to standart block types")
- sInput=read()
- if(sInput=="default") then
- break
- end
- if(#sInput==1) then
- break
- end
- if(#sInput~=1) then
- print("For block id can only be used one letter")
- os.sleep(2)
- end
- end
- if(sInput=="default") then
- break
- end
- tAllowedBlocks[n][1]=sInput
- print("Input block name ")
- sInput=read()
- tAllowedBlocks[n][2]=sInput
- n=n+1
- end
- break
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- local v=1
- for n=1,9,1 do
- print("Put "..tAllowedBlocks[v][2].." in slot "..v)
- v=v+1
- end
- print("Press any key")
- os.pullEvent("key")
- while(true) do
- local bItemsInSlot=true
- local n=1
- for n=1,9,1 do
- local iItemsInSlot=turtle.getItemCount(n)
- if(iItemsInSlot<1) then
- bItemsInSlot=false
- break
- end
- n=n+1
- end
- if(bItemsInSlot==false) then
- term.clear()
- term.setCursorPos(1,1)
- print("Put "..tAllowedBlocks[n][2].." in slot "..n.." and press any key")
- os.pullEvent("key")
- end
- if(bItemsInSlot==true) then
- break
- end
- end
- n=1
- local sAllowedBlocks=""
- for n=1,9,1 do
- sAllowedBlocks=sAllowedBlocks..tAllowedBlocks[n][1]..","..tAllowedBlocks[n][2]
- if(n~=9) then
- sAllowedBlocks=sAllowedBlocks.."|"
- end
- n=n+1
- end
- fileScheme:write(sAllowedBlocks.."\n")
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("Input building zone length")
- iBuildingZonelength=read()+0
- if(iBuildingZonelength~=nil and iBuildingZonelength>0) then
- break
- end
- end
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("Input building zone width")
- iBuildingZoneWidth=read()+0
- if(iBuildingZoneWidth~=nil and iBuildingZoneWidth>0) then
- break
- end
- end
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- print("Input building zone height")
- iBuildingZoneHeight=read()+0
- if(iBuildingZoneHeight~=nil and iBuildingZoneHeight>0) then
- break
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Scheme creating in progress")
- local k=1
- for n=1,iBuildingZoneHeight,1 do
- print("Processing layer "..k)
- local m=1
- local sDir="right"
- bWriting=true
- tLayer={}
- local j=1
- for n=1,iBuildingZonelength,1 do
- tLayer[j]={}
- j=j+1
- end
- for n=1,iBuildingZonelength,1 do
- local h=1
- fMove("+y",1)
- for n=1,iBuildingZoneWidth-1,1 do
- if(sDir=="right") then
- fMove("+x",1)
- else
- fMove("-x",1)
- end
- h=h+1
- end
- if(sDir=="right") then
- sDir="left"
- else
- sDir="right"
- end
- m=m+1
- end
- --for i,v in pairs(tLayer) do
- -- for d,s in pairs(v) do
- -- print(s)
- -- end
- --end
- g=1
- for n=1,iBuildingZonelength,1 do
- tLayer[g]=fTabToString(tLayer[g])
- g=g+1
- end
- fWriteScheme(k)
- bWriting=false
- --for i,v in ipairs(tLayer[5]) do print(i.." ",v) end
- fGoToPos(1,0)
- fMove("+z",1)
- k=k+1
- end
- end
- fileScheme:close()
- term.clear()
- term.setCursorPos(1,1)
- print("Scheme creating completed")
- print("Now you can find you're scheme at "..".minecraft\\saves\\(You're world)\\computer\\"..os.getComputerID())
- fGoToPos(1,0)
- fMove("-z",z-1)
Advertisement
Add Comment
Please, Sign In to add comment