Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Equation Builder:
- --Initialize:
- print("hi")
- 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); then a,b,c,d,e parameters of eq; fill in: f = 1")
- --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
- j = 1/i --Opposite incrementer
- f = tonumber(Args[16]) --Fill in : f = 1
- 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])
- locX = Xmin
- locZ = Zmin
- locY = Ymin
- Zx = {}
- Yx = {}
- closetoHomeY = 1
- closetoHomeZ = 1
- closetoHomeX = 1
- Xpos = 1
- Zx[Xpos] = 1
- u = 2 --Basic slot selection
- --Functions:
- function Correspondence(a)
- --print("no nan value in Zx[Xpos]")
- --(round(Zx[a]) <= locZ and round(Zx[a]) >= -locZ and f == 1)
- if (round(Zx[a]) == locZ or (round(Zx[a]) == -locZ and mirror <= 2 and mirror ~= 0)) and placed~=1 then
- --print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- elseif isempty(round(Zx[a])) == false then
- --print("not nil blockplacing maybe")
- if (round(Zx[a]) >= math.abs(locZ) and f == 1) and placed~=1 then
- --print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- elseif (round(Zx[a]) <= math.abs(locZ) and f == 2) and placed~=1 then
- --print("Will place a block")
- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- placed = 1
- end
- end
- --if (round(Zx[-a]) == locZ or round(Zx[-a]) == -locZ or round(Zx[a]) == locZ or round(Zx[a]) == -locZ ) and placed~=1 then
- -- print("Will place a block")
- -- BlockplaceDown() --Does NOT replace blocks (except water/lava)
- -- placed = 1
- --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=2,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
- if turtle.getItemCount(u) ==0 then
- emptyInven = true
- end
- else
- emptyInven = false
- end
- end
- function ChestSucking()
- for k=2,16 do
- turtle.select(k)
- turtle.suck()
- end
- turtle.select(u)
- emptyInven = false
- end
- --Place underneath (down) block (even on water and lava)
- function BlockplaceDown()
- SlotSelection()
- if emptyInven ~= true then
- 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
- if turtle.placeDown() then
- placed = 1
- end
- end
- else
- if turtle.placeDown() then
- placed = 1
- end
- end
- else
- print("Empty inventory!")
- end
- end
- --Turn around
- function turnaround()
- turtle.turnLeft()
- turtle.turnLeft()
- 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
- --Checks emptyness
- function isempty(s)
- return s == nil or s == ' '
- end
- --Rounding numbers
- function round(num)
- if num ~= nil and num ~= nan then
- return math.floor(num+0.5)
- else
- return
- end
- 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
- while locX <= Xmax and locX >= Xmin do
- while locZ <= Zmax and locZ >= Zmin do
- TurtleRefuel()
- for Xvar = locX-i,locX+i,i/10 do
- for Yvar = locY-i,locY+i,i/10 do
- if (((round(Eq(Xvar,Yvar)) <= round(locZ)+i and round(Eq(Xvar,Yvar)) >= round(locZ)-i)
- or (round(Eq(Xvar,Yvar)) <= -round(locZ)+i and round(Eq(Xvar,Yvar)) >= -round(locZ)-i)
- or (round(Eq(locX,locY)) >= math.abs(round(locZ)) and f == 1)
- or (round(Eq(locX,locY)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
- BlockplaceDown()
- end
- if emptyInven == true then
- break
- end
- end
- end
- if emptyInven == true then --Module for empty inventory and refill
- print("inside empty inventory")
- if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
- turnaround()
- end
- for k = 1, locZ-Zmin do --Moves back to starting X axis
- dignmove()
- end
- turtle.turnRight()
- for k = 1 , locX-Xmin do --Moves back to starting Z axis
- dignmove()
- end
- turtle.turnLeft()
- for k = 1 , locY - Ymin do
- dignmove()
- end
- ChestSucking()
- for k = 1 , locY - Ymin do
- dignmove()
- end
- turtle.turnLeft()
- for k = 1 ,locX-Xmin do --Moves back to starting Z axis
- dignmove()
- end
- turtle.turnLeft()
- for k = 1, locZ-Zmin do --Moves back to starting X axis
- dignmove()
- end
- if closetoHomeZ == 0 then
- turnaround()
- end
- BlockplaceDown()
- end
- placed = 0
- dignmove()
- if closetoHomeZ == 1 then --going towards Zmax
- locZ = locZ + 1
- else --away from Zmax
- locZ = locZ - 1
- end
- end
- if closetoHomeZ == 1 and locX <= Xmax and locX >= Xmin then
- turtle.turnRight()
- dignmove()
- turtle.turnRight()
- closetoHomeZ = 0
- if closetoHomeX == 1 then
- locX = locX + 1
- elseif closetoHomeX == 0 then
- locX = locX - 1
- end --away from Zmax
- elseif closetoHomeZ == 0 and locX <= Xmax and locX >= Xmin then
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- closetoHomeZ = 1 --going towards Zmax
- if closetoHomeX == 1 then
- locX = locX + 1
- elseif closetoHomeX == 0 then
- locX = locX - 1
- end
- end
- dignmove()
- if closetoHomeZ == 1 then --going towards Zmax
- locZ = locZ + 1
- else --away from Zmax
- locZ = locZ - 1
- end
- end
- turnaround()
- if closetoHomeX == 1 then --going towards Zmax
- closetoHomeX = 0
- else --away from Zmax
- closetoHomeX = 1
- end
- if closetoHomeZ == 1 then --going towards Zmax
- closetoHomeZ = 0
- else --away from Zmax
- closetoHomeZ = 1
- end
- dignmove()
- if closetoHomeZ == 1 then --going towards Zmax
- locZ = locZ + 1
- else --away from Zmax
- locZ = locZ - 1
- end
- UpdigMoveUp()
- locY = locY + 1
- end
- elseif dim == 2 then
- while locX <= Xmax and locX >= Xmin do
- while locZ <= Zmax and locZ >= Zmin do
- TurtleRefuel()
- for Xvar = locX-i,locX+i,i/10 do
- if (((round(Eq(Xvar)) <= round(locZ)+i and round(Eq(Xvar)) >= round(locZ)-i)
- or (round(Eq(Xvar)) <= -round(locZ)+i and round(Eq(Xvar)) >= -round(locZ)-i)
- or (round(Eq(locX)) >= math.abs(round(locZ)) and f == 1)
- or (round(Eq(locX)) <= math.abs(round(locZ)) and f == 2)) and placed ~= 1) then
- BlockplaceDown()
- end
- if emptyInven == true then
- break
- end
- end
- if emptyInven == true then --Module for empty inventory and refill
- print("inside empty inventory")
- if closetoHomeZ == 1 then --Turns around if turtle is facing away from chest
- turnaround()
- end
- for k = 1, locZ-Zmin do --Moves back to starting X axis
- dignmove()
- end
- turtle.turnRight()
- for k = 1 , locX-Xmin do --Moves back to starting Z axis
- dignmove()
- end
- turtle.turnLeft()
- ChestSucking()
- turtle.turnLeft()
- for k = 1 ,locX-Xmin do --Moves back to starting Z axis
- dignmove()
- end
- turtle.turnLeft()
- for k = 1, locZ-Zmin do --Moves back to starting X axis
- dignmove()
- end
- if closetoHomeZ == 0 then
- turnaround()
- end
- BlockplaceDown()
- end
- placed = 0
- dignmove()
- if closetoHomeZ == 1 then --going towards Zmax
- locZ = locZ + 1
- else --away from Zmax
- locZ = locZ - 1
- end
- end
- if closetoHomeZ == 1 and locX < Xmax then
- turtle.turnRight()
- dignmove()
- turtle.turnRight()
- closetoHomeZ = 0 --away from Zmax
- elseif closetoHomeZ == 0 and locX < Xmax then
- turtle.turnLeft()
- dignmove()
- turtle.turnLeft()
- closetoHomeZ = 1 --going towards Zmax
- end
- locX = locX + 1
- dignmove()
- if closetoHomeZ == 1 then --going towards Zmax
- locZ = locZ + 1
- else --away from Zmax
- locZ = locZ - 1
- end
- end
- end --2D-3D if loop closer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement