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
- if dim == 3 and InputEquation == 1 then
- io.write("You have selected the Coneslice package. Options: Ellipse:a>0,b<0,c<0; nontouchingHyperbola: a<0,b*c<0;touchingHyperbola:a>0,b*c<0;nontouching Diabolo:a>0,b>0,c>0;touching Diabolo a<0,b>0,c>0;")
- end
- 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 = tonumber(Args[11])
- b = tonumber(Args[12])
- c = tonumber(Args[13])
- d = tonumber(Args[14])
- e = tonumber(Args[15])
- j = tonumber(Args[16])
- locX = Xmin
- locZ = Zmin
- locY = Ymin
- Zx = {}
- Yx = {}
- closetoHomeY = 1
- closetoHomeZ = 1
- Xpos = 1
- Zx[Xpos] = 1
- u = 2 --Basic slot selection
- closetoHome = 1 --Close to start
- --Functions:
- function Correspondence()
- if Zx[Xpos] == Zx[Xpos] then
- --print("no nan value in Zx[Xpos]")
- if Zx[Xpos] ~= nil and Zx[-Xpos]== nil and mirror <= 2 and mirror ~=0 then
- print("inside if statement1")
- 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
- print("inside if statement2")
- 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
- print("inside if statement3")
- 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
- end
- end
- 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 math.sqrt(a+b*Xc^2+c*Yc^2) --3D Ellipse and hyperbola
- 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
- if dim == 2 then
- elseif dim == 3 then
- end
- 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
- Zx = {}
- while X - 1 < Xmax+1 do
- print("Table Filling")
- for Ypresicion = -j, j, 1 do
- table.insert(Zx,X/(i)*(j*2+1)+Ypresicion,Eq(X,locY+Ypresicion/(j*4))) --!!! Perhaps add better Y presicion !!! --Filling in the locations of the blocks in the table
- end
- X = X + i --Upcounting of the increment
- end
- X = Xmin
- tabZmax = maxtab(Zx)
- tabZmin = mintab(Zx)
- if math.fmod(Zmax,2) == 0 then
- Zmax = Zmax + 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)*(j*2+1), (locX+0.5)/(i)*(2*j+1) , 1 do
- --print("no nan value in Zx[Xpos]")
- Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
- --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
- if closetoHomeZ == 0 and locZ < Zmax and locZ > Zmin then --Turn around at the end of a 'strip'
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- --Change from far to close
- else
- turtle.turnRight()
- dignmove()
- turtle.turnRight()
- --Change from close to far
- end
- 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
- elseif dim == 2 then
- locZ = locZ - 1
- while X < Xmax do
- print("Table Filling")
- table.insert(Zx,X/i,Eq(X)) --!!! Perhaps add better Y presicion !!! --Filling in the locations of the blocks in the table
- X = X + i --Upcounting of the increment
- end
- X = Xmin
- tabZmax = maxtab(Zx)
- tabZmin = mintab(Zx)
- if math.fmod(Zmax,2) == 0 then
- Zmax = Zmax + 1
- end
- while locZ <= Zmax do --2D building loop
- print("Strip building")
- while locX <= Xmax and locX >= Xmin do
- for Xpos = (locX-0.5)/i, (locX+0.5)/i , 1 do
- Correspondence() --Checks whether the value of Zx[Xpos] and locZ correspond
- --print("X:",locX," Z:",locZ, " EqZ: ", EqZ(Xpos), " Zx[Xpos]:",Zx[Xpos])
- end
- placed = 0 --Reset of the placed variable
- dignmove()
- TurtleRefuel()
- locX = locX + 1 --Keeps track of the X coordinate
- end
- if math.fmod(locZ,2) == 0 and locZ < Zmax then --Turn around at the end of a 'strip'
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- closetoHome = 0 --Far away from start
- else
- turtle.turnRight()
- dignmove()
- turtle.turnRight()
- closetoHome = 1 --Close to start
- end
- dignmove()
- locX = Xmin
- locZ = locZ + 1 --Keeps track of the Z coordinate change in the math.mod block
- end
- end --2D-3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement