Advertisement
theinsekt

poz3 experiment

Mar 13th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.00 KB | None | 0 0
  1. -- experimental version of theinsektAPIs/poz3
  2. -- use poz3 instead, this is the more experimental version
  3. --(fixed some bugs here but not in original poz3...)
  4. -- pastebin get qyEYFZW0 theinsektAPIs/poz3
  5.  
  6. -- poz3 is a turtle API for going in different directions while keeping track of the changes
  7. -- in position and direction, compared to a starting point.
  8. -- Stores position  internally in a table called posT to simplify the usage of the functions.
  9. -- Also keeps track of the number of steps and turns that have been performed
  10. -- poz3 can be useful when digging, building etc.
  11. -- Another advantage is that you can write functions that take direction as a parameter, and therefore
  12. -- can work in any direction. This can make the code more reusable. Only write digLoop once!
  13. -- look in poz3a for an exmaple on how to make a digLoop.
  14.  
  15. -- Some techniques that were used to reduce the amount of code:
  16. -- The code uses lua tables as lookup tables in many situation.
  17. -- The amount of code has greatly been reduced by making the function turnDo, that turns if necessary
  18. -- and then does an action in one of three directions (up, forward or down).
  19. -- This makes it so only 3 function has to be in the lookup table for most actions,
  20. -- see detectT or goT. Only turnT needs lots of directions (but these are also reduced by
  21. -- translating north, east, west or south to a turn direction).
  22. -- Replaced repeated code with functions in many cases, also replaced some code with a function if it
  23. -- was potentially useful outside this file.
  24.  
  25. -- New feature: enterSimulationMode(), disables all actions, but still returns true (and false for some) and
  26. -- changes position, steps and turns, exitSimulationMode() to restore everything and
  27. -- be able to move again.
  28. -- To start a new simulation while in simulation you have to exit simulation mode then enter
  29. -- again.
  30. -- Warning: Many programs will not work in simulation mode because they might depend on finding a certain block
  31. -- or mining until the inventory is full etc.
  32. -- But if the program for example only depends on position then simulation mode might work.
  33. -- Simulation mode was created so that it's possible to simulate two different digging strategies and then
  34. -- choosing the fastest of them.
  35.  
  36. -- this api has the following useful functions
  37. --using wtf style:
  38.  
  39. --manipulate position manually
  40. --setPos(x0,y0,z0,f0)
  41. --getpos()->(x,y,z,f)
  42. --resetpos()
  43.  
  44. --test properties of the direction
  45. --validFacing(direction)->(result)
  46. --validDirection(direction)->(result)
  47. --validAbsoluteDirection(direction)->(result)
  48.  
  49. --manipulate directions
  50. --getReverse(direction)->(reverseDirection)
  51. --getAbsoluteDirection(direction)->(absoluteDirection)
  52.  
  53. --do actions (valid direction usually: n,s,)
  54. --valid direction for most are: f,b,r,l,u,d,n,s,e,w
  55. --(forward, back, right, left, up ,down, north, south, east, west)
  56. --go(direction)->(succes)
  57. --turn(direction)->(succes)
  58. --etc...
  59.  
  60. --the current position!!!
  61. --and stats!
  62. --can be changed with setPos, getPos and resetPos
  63. local posT={x=0,y=0,z=0,f="n"}
  64. local statsT={steps=0,turns=0}
  65.  
  66. --simulation, is probably to simple
  67. --Does not work very well for more advanced programs
  68. inSimulation=false
  69. local backupPosT=nil
  70. local backupStatsT=nil
  71.  
  72. --in simulation mode will pretend to do the action
  73. --then return true (or in some cases false, see detectT)
  74. --work in progress
  75. function enterSimulationMode()
  76.  --code to enter simulation code
  77.  if not inSimulation then
  78.   print("Entered simulation mode")
  79.   inSimulation=true
  80.   backupPosT=copyTable(posT)
  81.   backupStatsT=copyTable(statsT)
  82.  end
  83. end
  84.  
  85. function exitSimulationMode()
  86.  if inSimulation then
  87.   print("Exited simulation mode")
  88.   inSimulation=false
  89.   posT=copyTable(backupPosT)
  90.   --check posT just to be safe
  91.   if posT==nil then error("Internal error: posT is nil (this should never happen!)") end
  92.   statsT=copyTable(backupStatsT)
  93.  end
  94. end
  95.  
  96. function incrementSteps()
  97.  statsT["steps"]=statsT["steps"]+1
  98. end
  99.  
  100. function incrementTurns()
  101.  statsT["turns"]=statsT["turns"]+1
  102. end
  103.  
  104. function getStats()
  105.  return statsT["steps"], statsT["turns"]
  106. end
  107.  
  108. function setStats(steps,turns)
  109.  statsT["steps"]=steps
  110.  statsT["turns"]=turns
  111. end
  112.  
  113. function resetStats()
  114.  statsT["steps"]=0
  115.  statsT["turns"]=0
  116. end
  117.  
  118. --change coordinates
  119.  
  120.  
  121.  
  122. --sets the position values
  123. function setPos(x0,y0,z0,f0)
  124.  --check that none of the inputs are nil
  125.  if(x0==nil) then error("Error: x0 is nil") end
  126.  if(y0==nil) then error("Error: y0 is nil") end
  127.  if(z0==nil) then error("Error: z0 is nil") end
  128.  if(f0==nil) then error("Error: f0 is nil") end
  129.  --check that the f0 direction is recognized
  130.  if(not validFacing(f0)) then error("Error: f0 isn't a valid facing (valid: n,s,w,e)") end
  131.  --check that coordinates are numbers
  132.  if(type(x0) ~= "number") then error("Error: x0 isn't a number") end
  133.  if(type(y0) ~= "number") then error("Error: y0 isn't a number") end
  134.  if(type(z0) ~= "number") then error("Error: z0 isn't a number") end
  135.  --set the position
  136.  posT["x"]=x0
  137.  posT["y"]=y0
  138.  posT["z"]=z0
  139.  posT["f"]=f0
  140. end
  141.  
  142. --sets the position values using a pos table
  143. function setPos2(posT)
  144.   setPos(posT["x"],posT["y"],posT["z"],posT["f"])
  145. end
  146.  
  147.  
  148. function resetPos()
  149.  setPos(0,0,0,"n")
  150. end
  151.  
  152.  
  153. --return x,y,z,f
  154. --uses the same conventions as minecraft
  155. --but the facing north is determined by the starting direction
  156. function getPos()
  157.  return posT["x"],posT["y"],posT["z"],posT["f"]
  158. end
  159.  
  160. function copyTable(inTable)
  161.  local outTable={}
  162.  for k,v in pairs(inTable) do
  163.   outTable[k]=v
  164.  end
  165.  return outTable
  166. end
  167.  
  168. function getPos2()
  169.  return copyPos(posT)
  170.  --return {x=posT["x"],y=posT["y"],z=posT["z"],f=posT["f"]}
  171. end
  172.  
  173. function getPosField(fieldName)
  174.  return posT[fieldName]
  175. end
  176.  
  177.  
  178. function copyPos(aPosT)
  179.  if aPosT==nil then error("Error: aPosT is nil") end
  180.  return {x=aPosT["x"],y=aPosT["y"],z=aPosT["z"],f=aPosT["f"]}
  181. end
  182.  
  183. --check directions
  184.  
  185.  
  186. function validFacing(direction)
  187.  return faceT[direction]~=nil
  188. end
  189.  
  190.  
  191. function validDirection(direction)
  192.  return reverseT[direction]~=nil
  193. end
  194.  
  195.  
  196. function validAbsoluteDirection(direction)
  197.  return goUpdateT[direction]~=nil
  198. end
  199.  
  200. function isHorizontal(direction)
  201.  return not isVertical(direction)
  202. end
  203.  
  204. function isVertical(direction)
  205.  direction=getAbsoluteDirection(direction)
  206.  return direction=="u" or direction=="d"
  207. end
  208.  
  209.  
  210.  
  211.  
  212. --various direction calculations
  213.  
  214.  
  215. --directions: n,s,e,w,u,d
  216. --returns which coordinate would be changed and by how much
  217. function getCoordinateChange(direction,length)
  218.  local tmp=goUpdateT[direction]
  219.  if tmp==nil then Error("Error: unrecognised direction (valid: n,s,e,w,u,d)") end
  220.  local posTFieldName, change = unpack(tmp)
  221.  return posTFieldName,change*length
  222. end
  223.  
  224.  
  225. --return the resulting facing after doing a turn in the given direction
  226. --returns nil if the direction is not valid/recognized
  227. --directions: n,s,e,w,u,d,f,b,l,r
  228. --throws and error if invalid direction
  229. function getTurnRes(direction)
  230.  --check inputs
  231.  typeErrorIf("direction",direction,"string",2)
  232.  --u or d doesn’t change so return old facing
  233.  if direction=="u" or direction=="d" then
  234.   return posT["f"]
  235.  end
  236.  --n,e,s,w are already facings
  237.  if turnResT[direction] ~= nil then
  238.   return direction --direction is one of n,e,s,w
  239.  end
  240.  --convert f,b,r,l to facing (n,e,s,w)
  241.  local res = turnResT[posT["f"]][direction]
  242.  
  243.  --check if res is nil through error
  244.  if res==nil then
  245.    if not validDirection(direction) then error("Error: invalid direction (valid: n,s,e,w,u,d,f,b,l,r).") end
  246.    error("Error: internal bug")
  247.  end
  248.  
  249.  return res
  250. end
  251.  
  252. --to get the resulting facing (n,e,s,w)
  253. --converts wanted facing (n,e,s,w) to
  254. --needed turn direction (r,l,b,f)
  255. function getFacingToTurnDirection(facing)
  256.   return faceT[posT["f"]][facing]
  257. end
  258.  
  259. --turns: n,s,e,w,u,d,f,b,l,r into n,s,e,w,u,d
  260. --directions: n,s,e,w,u,d,f,b,l,r
  261. --returns nil if the direction isn't recognized
  262. function getAbsoluteDirection(direction)
  263.  --check input
  264.  typeErrorIf("direction",direction,"string",2)
  265.  --u and d are already absolute direction
  266.  if direction=="u" or direction=="d" then
  267.   return direction
  268.  end
  269.  --get the cardinal direction
  270.  return getTurnRes(direction)
  271. end
  272.  
  273.  
  274. --get the reverse direction
  275. --directions:
  276. --works best for n,s,e,w,u,d, because if you use go on the reverse of those you will go to your
  277. --previous position
  278. --also works for f,b,l,r
  279. function getReverse(direction)
  280.   return reverseT[direction]
  281. end
  282.  
  283.  
  284. --get a new table with position 0
  285. --all the parameters are optional, just use nil to
  286. --to set the default value
  287. --x0,y0,z0 are integer number
  288. --f0 is a string that can be n,e,s,w
  289. function getNewPos(x0,y0,z0,f0)
  290.  --replace nil with default value
  291.  if x0==nil then x0=0 end
  292.  if y0==nil then y0=0 end
  293.  if z0==nil then z0=0 end
  294.  if f0==nil then f0="n" end
  295.  
  296.  --check that the f0 direction is recognized
  297.  if(not validFacing(f0)) then error("Error: f0 isn't a valid facing (valid: n,s,w,e)") end
  298.  
  299.  --check that coordinates are numbers
  300.  if(type(x0) ~= "number") then error("Error: x0 isn't a number") end
  301.  if(type(y0) ~= "number") then error("Error: y0 isn't a number") end
  302.  if(type(z0) ~= "number") then error("Error: z0 isn't a number") end
  303.  
  304.  --return new posT
  305.  return {x=x0,y=y0,z=z0,f=f0}
  306. end
  307.  
  308.  
  309. --get the direction and distance needed to get to a coord value
  310. function coordToGoValues(coordName,wantedCoordValue)
  311.  return coordChangeToDirection(coordName, wantedCoordValue-posT[coordName])
  312. end
  313.  
  314.  
  315. --turns x,y,z into s,e,u
  316. --negative length reverses the direction
  317. --can be used to get the direction and distance if you want to
  318. --go to a certain coordinate
  319. function coordChangeToDirection(coordName, length)
  320.  --check input
  321.  typeErrorIf("coordName",coordName,"string",2)
  322.  --get direction to increase coordinate
  323.  local direction=fieldToDirectionT[coordName]
  324.  --check if invalid coordName
  325.  if direction==nil then
  326.    error("Error: invalid coordinate name (valid names: x, y, x, f)")
  327.  end
  328.  --invert direction if length is negative
  329.  if length<0 then
  330.    direction=getReverse(direction)
  331.    length=-length
  332.  end
  333.  --return direction and change
  334.  return direction, length
  335. end
  336.  
  337.  
  338. --turn, go, detect etc...
  339.  
  340.  
  341. --turn in/to the given direction
  342. --directions: n,s,e,w,u,d,f,b,l,r
  343. --Has simulation mode!
  344. function turn(direction)
  345.   --check input
  346.   typeErrorIf("direction",direction,"string",2)
  347.   --convert n,e,s,w if neccesary
  348.   if turnT[direction]==nil then
  349.     direction=getFacingToTurnDirection(direction)
  350.    --faceT[posT["f"]][direction] -- translates n,s,e,w into equivalent r,l,u,d,f,b
  351.   end
  352.   --check if unrecognised direction
  353.   if direction==nil then
  354.     error("Error: unrecognised direction (recognized directions: n,s,e,w,u,d,f,b,l,r)")
  355.   end
  356.   --turn and return turn result
  357.   return turnT[direction]() -- r,l,u,d,f,b
  358. end
  359.  
  360.  
  361. --directions: n,s,e,w,u,d,f,b,l,r
  362. --Supports simulation mode!
  363. function go(direction)
  364.   return turnDo(goT,direction)
  365. end
  366.  
  367.  
  368. --directions: n,s,e,w,u,d,f,b,l,r
  369. --Supports simulation mode!
  370. function attack(direction)
  371.  return turnDo(attackT,direction)
  372. end
  373.  
  374.  
  375. --directions: n,s,e,w,u,d,f,b,l,r
  376. --Supports simulation mode!
  377. function dig(direction)
  378.  return turnDo(digT,direction)
  379. end
  380.  
  381.  
  382. --directions: n,s,e,w,u,d,f,b,l,r
  383. --Supports simulation mode!
  384. --sign text should be nil, or not specified if direction is u or d
  385. function place(direction,signText)
  386.  return turnDo(placeT,direction,signText)
  387. end
  388.  
  389.  
  390. --directions: n,s,e,w,u,d,f,b,l,r
  391. --Supports simulation mode!
  392. function detect(direction)
  393.  return turnDo(detectT,direction)
  394. end
  395.  
  396.  
  397. --directions: n,s,e,w,u,d,f,b,l,r
  398. --Supports simulation mode!
  399. function compare(direction)
  400.  return turnDo(compareT,direction)
  401. end
  402.  
  403.  
  404. --syntax: drop(string direction, [number count])
  405. --uses: turtle.drop([number count])
  406. --directions: n,s,e,w,u,d,f,b,l,r
  407. --returns: boolean true if an item was dropped; false otherwise.
  408. --Supports simulation mode!
  409. --... captures zero or more optional parameters
  410. function drop(direction, amount)
  411.  return turnDo(dropT,direction, amount)
  412. end
  413.  
  414.  
  415. --directions: n,s,e,w,u,d,f,b,l,r
  416. --Supports simulation mode!
  417. function suck(direction,amount)
  418.  return turnDo(suckT,direction,amount)
  419. end
  420.  
  421. --available in cc1.64 and later
  422. --directions: n,s,e,w,u,d,f,b,l,r
  423. --Supports simulation mode!
  424. function inspect(direction)
  425.  return turnDo(inspectT,direction)
  426. end
  427.  
  428. --help functions
  429.  
  430.  
  431. --help function, turns if necessary, then looks up an action in the doT (f,u or d) and does the action.
  432. --The do table (doT) should have f,u and d
  433. --turn do returns the result of the do action
  434. function turnDo(doT,direction, ...)--... are variable amount of arguments passed to the do function
  435.   --check input
  436.   typeErrorIf("direction",direction,"string",2)
  437.   typeErrorIf("doT",doT,"table",2)
  438.   --turn if neccesary
  439.   if doT[direction] == nil then  -- if does not have action in that direction then turn
  440.     direction=turn2(direction) -- turn and get "after turn action direction"
  441.   end
  442.  --special case code if in simulation
  443.  if inSimulation then
  444.   if not doT["simSupport"] then
  445.    error("Error: is in simulation mode but the given action does not support simulation")
  446.   end
  447.   if doT["simReturn"] then
  448.     --sim return is a table with one or more return values
  449.     return unpack(doT["simReturn"])
  450.   end
  451.   --if has no sim return the original code is supposed to be run
  452.   --the original code could change position and statistics but should not move or move items.
  453.  end
  454.  --do function and return result
  455.  --have to do this because turtle.suck() works but not turtle.suck(nil)
  456.  --so if someone did poz3.suck(amount) without checking if amount isn't nil, then it wouldn't work before.
  457.  if ... then
  458.    --print("debug: optional is not nil")--DEBUG
  459.    return doT[direction](...)--do the function
  460.  else
  461.    --print("debug: optional is nil")--DEBUG
  462.    return doT[direction]()
  463.  end
  464.  
  465. end
  466.  
  467.  
  468.  
  469. --checks if variable is the wantedType, else throws an error saying it's not correct type
  470. --has standardised error message
  471. function typeErrorIf(name,variable,wantedType,responsibleNumber)
  472.   if responsibleNumber==nil then responsibleNumber=1 end
  473.   if type(variable)~=wantedType then
  474.     error("Error: param called "..name.." should be a "..wantedType.." not a "..type(variable),responsibleNumber+1)
  475.   end
  476. end
  477.  
  478.  
  479. -- turns and then return the "after turn action direction" (f, u or d)
  480. function turn2(direction)
  481.  turn(direction)
  482.  return getTurnDoDirection(direction)
  483. end
  484.  
  485.  
  486. function getTurnDoDirection(direction)
  487.  if direction=="u" or direction=="d" then
  488.   return direction --up or down
  489.  else
  490.   return "f"--forward
  491.  end
  492. end
  493.  
  494. --updates the coordinate as if went in the given direction
  495. --only works for absolute directions
  496. --directions: n,s,e,w,u,d
  497. function goUpdate(direction)
  498.  local posTFieldName, change = getCoordinateChange(direction,1)
  499.  posT[posTFieldName]=posT[posTFieldName]+change
  500.  return true
  501. end
  502.  
  503.  
  504. --updates the facing in pos if it’s a valid turn direction
  505. --returns true if it was a valid turn direction, and posT was updated
  506. --directions: n,s,e,w,u,d,f,b,l,r
  507. function turnUpdate(direction)
  508.  local facing=getTurnRes(direction)
  509.  posT["f"]=facing
  510.  return true
  511. end
  512.  
  513.  
  514.  
  515.  
  516. function doCommand(commandName,direction,optional)
  517.     return commandNameT[commandName](direction,optional)
  518. end
  519.  
  520.  
  521. commandNameT={
  522.     ["turn"]=turn,
  523.     ["go"]=go,
  524.     ["attack"]=attack,
  525.     ["dig"]=dig,
  526.     ["place"]=place,
  527.     ["detect"]=detect,
  528.     ["compare"]=compare,
  529.     ["drop"]=drop,
  530.     ["suck"]=suck,
  531.     ["ddgloop"]=function(direction,optional) return doLoop(tonumber(optional),detectDigGo,direction,nil) end,
  532. }
  533.  
  534.  
  535. commandUsageT={
  536.     ["turn"]="usage: turn <direction> a \nexplanation: turns in the given direction",
  537.     ["go"]="usage: go <direction> a \nexplanation: tries to go in the given direction",
  538.     ["attack"]="usage: attack <direction> a \nexplanation: tries to attack in the given direction",
  539.     ["dig"]="usage: dig <direction> a \nexplanation: tries to dig a block in the given direction",
  540.     ["place"]="usage: place <direction> <optionalSignText> \nexplanation: places an item from the selected slot in the given direction",
  541.     ["detect"]="usage: detect <direction> a \nexplanation: returns true if there is a block in the given direction else false",
  542.     ["compare"]="usage: compare <direction> a \nexplanation: compares the block in the given direction to the item in the selected slot",
  543.     ["drop"]="usage: drop <direction> <count> \nexplanation: drops count items in the given direction",
  544.     ["suck"]="usage: suck <direction> a \nexplanation:",
  545.     ["ddgloop"]="usage: ddgloop <direction> <length> \nexplanation: digs and moves in the given direction for the given length",
  546. }
  547.  
  548.  
  549. -- reverse: return the reverse of the given action, useful you want to move in one direction and then back
  550.  
  551.  
  552. --this table is used look up the reverse action
  553. --the reverse function uses this table to look up what the reverse action is
  554. --is also used to check valid direction, because it contains all directions
  555. reverseT={
  556. f="b",
  557. b="f",
  558. n="s", --turn north, reverse: turn south
  559. s="n", --turn south, reverse: turn north
  560. e="w", --turn east, reverse: turn west
  561. w="e", --turn west, reverse: turn east
  562. u="d", --turn up, reverse: turn down (tu does nothing)
  563. d="u", --turn down, reverse: turn up (td does nothing)
  564. r="l", --turn right, reverse: turn left
  565. l="r", --turn left, reverse: turn right
  566. }
  567.  
  568.  
  569. -- This is a lookup table containing functions
  570. -- go uses this table to simply look up what function is needed to do the given action
  571. -- these functions update positions but does not move if in simulation mode
  572. goT={
  573. simSupport=true,--in simulation: will update position without moving
  574.  
  575. --go forward then update position
  576. f=function()
  577.  if(inSimulation or turtle.forward()) then
  578.   incrementSteps()
  579.   goUpdate(posT["f"])
  580.   return true
  581.  end
  582.  return false
  583. end,
  584.  
  585.  
  586. --go up then update position
  587. u=function()
  588.  if(inSimulation or turtle.up()) then
  589.   incrementSteps()
  590.   goUpdate("u")
  591.   return true
  592.  end
  593.  return false
  594. end,
  595.  
  596.  
  597. --go down then update position
  598. d=function()
  599.  if(inSimulation or turtle.down()) then
  600.   incrementSteps()
  601.   goUpdate("d")
  602.   return true
  603.  end
  604.  return false
  605. end,
  606.  
  607. }
  608.  
  609.  
  610. -- these functions update positions but does not move if in simulation mode
  611. turnT={
  612. simSupport=true,--in simulation: will update position without moving
  613.  
  614. --turn right and then update position
  615. r=function()
  616.  if(inSimulation or turtle.turnRight()) then
  617.   incrementTurns()
  618.   turnUpdate("r")
  619.   return true
  620.  end
  621.  return false
  622. end,
  623.  
  624.  
  625. --turn left and then update position
  626. l=function()
  627.  if(inSimulation or turtle.turnLeft()) then
  628.   incrementTurns()
  629.   turnUpdate("l")
  630.   return true
  631.  end
  632.  return false
  633. end,
  634.  
  635.  
  636. --does nothing, but may avoid special case in your code
  637. u=function() return true end,
  638.  
  639.  
  640. --does nothing, but may avoid special case in your code
  641. d=function() return true end,
  642.  
  643.  
  644. --does nothing, keeps facing forward
  645. f=function() return true end,
  646.  
  647.  
  648. --calls turn right twice, used to turn 180 degrees
  649. b=function()
  650.  return turn("r") and turn("r")
  651. end,
  652.  
  653. }
  654.  
  655.  
  656. --given current facing and wanted facing
  657. --used to look up the needed turn action
  658. faceT={
  659. n={
  660. n="f",
  661. s="b",
  662. e="r",
  663. w="l",
  664. },
  665. s={
  666. s="f",
  667. n="b",
  668. w="r",
  669. e="l",
  670. },
  671. e={
  672. e="f",
  673. w="b",
  674. s="r",
  675. n="l",
  676. },
  677. w={
  678. w="f",
  679. e="b",
  680. n="r",
  681. s="l",
  682. },
  683. }
  684.  
  685. -- Creates an inverted table, were keys become values and values become keys.
  686. -- http://stackoverflow.com/questions/7925090/lua-find-a-key-from-a-value
  687. function table_invert(t)
  688.    local s={}
  689.    for k,v in pairs(t) do
  690.      s[v]=k
  691.    end
  692.    return s
  693. end
  694.  
  695.  
  696. --lookup table to se what the resulting facing is after doing a turn in the given direction
  697. --does not include u or d, because they don’t change the facing
  698. --does not include n,e,s,w becuase they are alredy facings
  699. --each subtable is the inverse of the corresponding subtable in faceT
  700. turnResT={
  701. n=table_invert(faceT["n"]),
  702. s=table_invert(faceT["s"]),
  703. e=table_invert(faceT["e"]),
  704. w=table_invert(faceT["w"]),
  705. }
  706.  
  707.  
  708. --use to look up the coordinate change
  709. --going one step in the given direction
  710. goUpdateT={
  711. n={"z",-1},
  712. s={"z",1},
  713. e={"x",1},
  714. w={"x",-1},
  715. u={"y",1},
  716. d={"y",-1},
  717. }
  718.  
  719.  
  720. --used to look up the direction
  721. --to increase the given coordinate
  722. fieldToDirectionT={
  723. x="e",
  724. y="u",
  725. z="s",
  726. }
  727.  
  728.  
  729. attackT={
  730. simReturn={false},
  731. simSupport=true,
  732. f=function() return turtle.attack() end,
  733. u=function() return turtle.attackUp() end,
  734. d=function() return turtle.attackDown() end,
  735. }
  736.  
  737.  
  738. digT={
  739. simReturn={false},
  740. simSupport=true,
  741. f=function() return turtle.dig() end,
  742. u=function() return turtle.digUp() end,
  743. d=function() return turtle.digDown() end,
  744. }
  745.  
  746.  
  747. placeT={
  748. simReturn={false},
  749. simSupport=true,
  750. --turtle.place(nil) works
  751. f=function(signText) return turtle.place(signText) end,--TEST
  752. u=function() return turtle.placeUp() end,
  753. d=function() return turtle.placeDown() end,
  754. }
  755.  
  756.  
  757. detectT={
  758. simReturn={false},--this data is used by turnDo if inSimulation is true
  759. simSupport=true,--this data is used by turnDo if inSimulation is true
  760. f=function() return turtle.detect() end,
  761. u=function() return turtle.detectUp() end,
  762. d=function() return turtle.detectDown() end,
  763. }
  764.  
  765.  
  766. compareT={
  767. simReturn={false},
  768. simSupport=true,
  769. f=function() return turtle.compare() end,
  770. u=function() return turtle.compareUp() end,
  771. d=function() return turtle.compareDown() end,
  772. }
  773.  
  774.  
  775. dropT={
  776. simReturn={false},
  777. simSupport=true,
  778. --For some reason turtle.drop(nil) does not work, so these three does not work for all cases.
  779. --f=function(amount) return turtle.drop(amount) end,
  780. --u=function(amount) return turtle.dropUp(amount) end,
  781. --d=function(amount) return turtle.dropDown(amount) end,
  782. --these three works for all cases
  783. -- ... captures a variable amount of arguments
  784. f=function(...) return turtle.drop(...) end,
  785. u=function(...) return turtle.dropUp(...) end,
  786. d=function(...) return turtle.dropDown(...)  end,
  787. }
  788.  
  789.  
  790. suckT={
  791. simReturn={true},
  792. simSupport=true,
  793. f=function(...) return turtle.suck(...) end,
  794. u=function(...) return turtle.suckUp(...) end,
  795. d=function(...) return turtle.suckDown(...) end,
  796. }
  797.  
  798. inspectT={
  799. simReturn={false,"No block to inspect"},
  800. simSupport=true,
  801. f=function() return turtle.inspect() end,
  802. u=function() return turtle.inspectUp() end,
  803. d=function() return turtle.inspectDown() end,
  804. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement