Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Equation Builder:
- --Initialize:
- turtle.select(2)
- --Printables:
- io.write("Input equation, increment size, number of dimensions, mirrors, limits first dimension (lower upper), limits second dimension (lower upper), limits third dimension (lower upper)")
- --Input equation: 1 for ellipse, 2 for parabola, 3 for etc
- --Mirros is for mirroring in either X, Y or Z axis. For mirror over X-axis do mirror <= 2, for Z-axis do mirror >= 2. For neither do mirror = 0
- --Wireless Connection:
- --Not yes
- --Variables:
- Args = {...}
- --Parameters:
- InputEquation = tonumber(Args[1])
- i = tonumber(Args[2]) --Incrementer
- dim = tonumber(Args[3])
- mirror = tonumber(Args[4])
- Zmax = tonumber(Args[10])
- Zmin = tonumber(Args[9])
- Z = {}
- Xmax = tonumber(Args[6])
- Xmin = tonumber(Args[5])
- X = Xmin
- if dim > 2 then
- Ymax = tonumber(Args[8])
- Ymin = tonumber(Args[7])
- Y = Zmin
- end
- a = Args[11]
- b = Args[12]
- c = Args[13]
- d = Args[14]
- e = Args[15]
- locX = Xmin
- locZ = Zmin
- locY = Ymin
- Zx = {}
- Yx = {}
- closetoHomeY = 1
- closetoHomeZ = 1
- u = 2 --Basic slot selection
- closetoHome = 1 --Close to start
- --Functions:
- function Eq(Xc,Yc)
- if InputEquation == 1 then
- if dim == 2 then
- return (b/a)*math.sqrt(a^2-Xc^2) --Rewriten Ellipse of form "x^2/a^2+y^2/b^2==1"
- elseif dim == 3 then
- return (b/(a*c))*math.sqrt(a^2*c^2-c^2*Xc^2-a^2*Yc^2) --3D Ellipse
- end
- elseif InputEquation == 2 then --Polynomial
- if dim == 2 then
- return a*X^4+b*X^3+c*X^2+d*X+e
- elseif dim == 3 then
- end
- elseif InputEquation == 3 then
- end
- end
- --Refuels turtle
- function TurtleRefuel() --Refuel
- if turtle.getFuelLevel() < 320 and turtle.getItemCount(1) > 3 then
- turtle.select(1)
- turtle.refuel(3)
- print("TurtleRefueling")
- end
- turtle.select(u)
- end
- --Item slot selection , for block selection (ignores first item slot which is usually reserved for fuel)
- function SlotSelection()
- if turtle.getItemCount(u) == 0 then
- for k=1,16 do
- if turtle.getItemCount(u) == 0 then
- if u < 16 then
- u=u+1
- turtle.select(u)
- else
- turtle.select(2)
- u=2
- end
- end
- end
- end
- end
- --Place underneath (down) block (even on water and lava)
- function BlockplaceDown()
- SlotSelection()
- if turtle.detectDown() then
- bool,data = turtle.inspectDown()
- if data.name == "minecraft:lava" and data.name == "minecraft:water" and data.name == "minecraft:flowing_water" and data.name == "minecraft:flowing_lava" then
- turtle.placeDown()
- end
- else
- turtle.placeDown()
- end
- end
- --graveldigforward
- function graveldig() --Gravel Shield for digging and the digging
- os.sleep(9/20)
- if turtle.detect() then
- bool,data=turtle.inspect()
- while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspect()~= false do
- turtle.dig()
- os.sleep(9/20)
- bool,data=turtle.inspect()
- end
- end
- end
- --Gravel Shield (Ensures that when digging up it will keep digging until all falling blocks are dealt with
- function graveldigUp() --Gravel Shield for Up digging and the digging Up
- os.sleep(9/20)
- if turtle.detectUp() then
- bool,data=turtle.inspectUp()
- while data.name ~= "minecraft:flowing_water" and data.name ~= "minecraft:flowing_lava" and turtle.inspectUp()~= false do
- turtle.digUp()
- os.sleep(9/20)
- bool,data=turtle.inspect()
- end
- end
- end
- --Forward (in front) dig if something is detected (NO GRAVEL SHIELD!!!)
- function Fdig()
- if turtle.detect() then
- turtle.dig()
- end
- end
- --Dig N move
- function dignmove()
- Fdig()
- graveldig()
- turtle.forward()
- end
- function round(num)
- return math.floor(num+0.5)
- end
- --Max value in a table
- function maxtab(a)
- local values = {}
- for k,v in pairs(a) do
- values[#values+1] = v
- end
- table.sort(values)
- return values[#values]
- end
- --Min value in a table
- function mintab(a)
- local values = {}
- for k,v in pairs(a) do
- values[#values+1] = v
- end
- table.sort(values)
- return values[1]
- end
- --Moves turtle up (it breaks the block above it first (has gavelshield)
- function UpdigMoveUp()
- if turtle.detectUp() then
- turtle.digUp()
- end
- graveldigUp()
- turtle.up()
- end
- --Down dig
- function Ddig()
- if turtle.detectDown() then
- turtle.digDown()
- end
- end
- --Dig N movedown
- function dignmovedown()
- Ddig()
- turtle.down()
- end
- --Code:
- if dim == 3 then
- while locY < Ymax do --3D Building Loop This while loop build one volume
- while X < Xmax do
- print("Table Filling")
- table.insert(Zx,X/i,Eq(X,locY)) --Filling in the locations of the blocks in the table
- X = X + i --Upcounting of the increment
- end
- tabZmax = maxtab(Zx)
- tabZmin = mintab(Zx)
- if math.fmod(tabZmax,2) == 0 then
- tabZmax = tabZmax + 1
- end
- while locZ <= Zmax and locZ >= Zmin do --This while loop build one floor
- print("Strip building")
- while locX <= Xmax and locX >= Xmin do --This while loop builds one strip
- if tabZmax == tabZmax and tabZmin == tabZmin then
- print("Starting For loop strip builder")
- for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
- if Zx[Xpos] == Zx[Xpos] then
- if Zx[Xpos] ~= nil and Zx[-Xpos]== nil and mirror <= 2 and mirror ~=0 then
- if (round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ) and placed~=1 then
- print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- end
- elseif Zx[-Xpos]~= nil and Zx[Xpos]== nil and mirror >= 2 and mirror ~=0 then
- if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ) and placed~=1 then
- print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- end
- elseif Zx[-Xpos]~= nil and Zx[Xpos]~= nil then
- if (round(Zx[-Xpos]) == locZ or round(Zx[-Xpos]) == -locZ or round(Zx[Xpos]) == locZ or round(Zx[Xpos]) == -locZ ) and placed~=1 then
- print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- end
- end
- else
- print("nan value in Zx[Xpos]")
- end
- --print("X:",locX," Z:",locZ, " Eq: ", Eq(Xpos), " Zx[Xpos]:",Zx[Xpos])
- end
- else
- print("nan failure to start strip loop")
- end
- placed = 0 --Reset of the placed variable
- dignmove()
- TurtleRefuel()
- if closetoHomeZ == 1 then
- locX = locX + 1 --This is X coordinate for strip away
- else
- locX = locX - 1 --This is X coordinate for strip back
- end
- end
- if closetoHomeZ == 1 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- locX = Xmax
- closetoHomeZ = 0 --Change from far to close
- else
- turtle.turnRight()
- dignmove()
- turtle.turnRight()
- locX = Xmin
- closetoHomeZ = 1 --Change from close to far
- end
- dignmove()
- if closetoHomeY == 1 then
- locZ = locZ + 1 --This is Z coordinate for floor away
- else
- locZ = locZ - 1 --This is Z coordinate for floor back
- end
- end
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- locY = locY + 1 --Keeps track of Y coordinate
- --3D module
- if closetoHomeY == 1 and locY < Ymax and locY >= Ymin then --Turn around at the end of a 'floor'
- turtle.turnLeft()
- UpdigMoveUp()
- turtle.turnLeft()
- locZ = Zmax
- closetoHomeY = 0 --Change from far to close
- else
- turtle.turnRight()
- UpdigMoveUp()
- turtle.turnRight()
- locZ = Zmin
- closetoHomeY = 1 --Change from close to far
- end
- end
- end --3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement