Advertisement
ecco7777

CC Turtle Pixelart Filler Controller + Me Autocraft

Dec 28th, 2020 (edited)
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.19 KB | None | 0 0
  1. file="bild"
  2. me=peripheral.wrap("front")
  3. r=peripheral.wrap("right")
  4. slot={}
  5. chars={}
  6. slot[" "]=12
  7. slot["0"]=1
  8. slot["1"]=2
  9. slot["2"]=3
  10. slot["3"]=4
  11. slot["4"]=5
  12. slot["5"]=6
  13. slot["6"]=7
  14. slot["7"]=8
  15. slot["8"]=9
  16. slot["9"]=10
  17. slot["a"]=11
  18. slot["b"]=12
  19. slot["c"]=13
  20. slot["d"]=14
  21. slot["e"]=15
  22. slot["f"]=16
  23. id={}
  24. id[" "]=15*32768+3225
  25. id["0"]=0*32768+3225
  26. id["1"]=1*32768+3225
  27. id["2"]=2*32768+3225
  28. id["3"]=3*32768+3225
  29. id["4"]=4*32768+3225
  30. id["5"]=5*32768+3225
  31. id["6"]=6*32768+3225
  32. id["7"]=7*32768+3225
  33. id["8"]=8*32768+3225
  34. id["9"]=9*32768+3225
  35. id["a"]=10*32768+3225
  36. id["b"]=11*32768+3225
  37. id["c"]=12*32768+3225
  38. id["d"]=13*32768+3225
  39. id["e"]=14*32768+3225
  40. id["f"]=15*32768+3225
  41.  
  42. function getCharCount(str,char)
  43.     charnum=0
  44.         for i=1, #str do
  45.             if string.sub(str,i,i)==char then
  46.                 charnum=charnum+1
  47.             end
  48.         end
  49.     return(charnum)
  50. end
  51.  
  52. function fileToTable(file)
  53.         if fs.exists(file)~=true then
  54.         print("file"..file.." not found")
  55.         return(false)
  56.         end
  57.     fp=fs.open(file,"r")
  58.     line={}
  59.     i=1
  60.     line[i]=fp.readLine()
  61.         if line[i]==nil then return(false) end
  62.             while line[i]~=nil do  
  63.             i=i+1
  64.             line[i]=fp.readLine()
  65.             end
  66.         end
  67.     return(line)
  68. end
  69.  
  70. img=fileToTable(file)
  71.  
  72. i=1
  73. i2=1
  74. i3=1
  75.     while img[i]~=nil do
  76.         for i2=1, #img[i] do
  77.             chars[i3]=string.sub(img[1],i2,i2)
  78.             i3=i3+1
  79.         end
  80.     i=i+1
  81.     end
  82.  
  83. onechar=""
  84.     for i=1, #img do
  85.     onechar=onechar..img[i]
  86.     end
  87. term.clear()
  88. term.setCursorPos(1,1)
  89. term.write("Slot1 weiß: "..tostring(getCharCount(onechar,"0")))term.setCursorPos(1,2)
  90. term.write("Slot2 orange: "..tostring(getCharCount(onechar,"1")))term.setCursorPos(1,3)
  91. term.write("Slot3 magenta: "..tostring(getCharCount(onechar,"2")))term.setCursorPos(1,4)
  92. term.write("Slot4 hellblau: "..tostring(getCharCount(onechar,"3")))term.setCursorPos(1,5)
  93. term.write("Slot5 gelb: "..tostring(getCharCount(onechar,"4")))term.setCursorPos(1,6)
  94. term.write("Slot6 hellgrün: "..tostring(getCharCount(onechar,"5")))term.setCursorPos(1,7)
  95. term.write("Slot7 pink: "..tostring(getCharCount(onechar,"6")))term.setCursorPos(1,8)
  96. term.write("Slot8 grau: "..tostring(getCharCount(onechar,"7")))term.setCursorPos(21,1)
  97. term.write("Slot9 hellgrau: "..tostring(getCharCount(onechar,"8")))term.setCursorPos(21,2)
  98. term.write("Slot10 cyan: "..tostring(getCharCount(onechar,"9")))term.setCursorPos(21,3)
  99. term.write("Slot11 lila: "..tostring(getCharCount(onechar,"a")))term.setCursorPos(21,4)
  100. term.write("Slot12 blau: "..tostring(getCharCount(onechar,"b")+getCharCount(onechar,"b")))term.setCursorPos(21,5)
  101. term.write("Slot13 braun: "..tostring(getCharCount(onechar,"c")))term.setCursorPos(21,6)
  102. term.write("Slot14 grün: "..tostring(getCharCount(onechar,"d")))term.setCursorPos(21,7)
  103. term.write("Slot15 rot: "..tostring(getCharCount(onechar,"e")))term.setCursorPos(21,8)
  104. term.write("Slot16 schwarz: "..tostring(getCharCount(onechar,"f")))term.setCursorPos(1,9)
  105.  
  106. as=io.read()
  107.  
  108. if as=="craft" then
  109.     me.craft(id["0"],getCharCount(onechar,"0"))
  110.     me.craft(id["1"],getCharCount(onechar,"1"))
  111.     me.craft(id["2"],getCharCount(onechar,"2"))
  112.     me.craft(id["3"],getCharCount(onechar,"3"))
  113.     me.craft(id["4"],getCharCount(onechar,"4"))
  114.     me.craft(id["5"],getCharCount(onechar,"5"))
  115.     me.craft(id["6"],getCharCount(onechar,"6"))
  116.     me.craft(id["7"],getCharCount(onechar,"7"))
  117.     me.craft(id["8"],getCharCount(onechar,"8"))
  118.     me.craft(id["9"],getCharCount(onechar,"9"))
  119.     me.craft(id["a"],getCharCount(onechar,"a"))
  120.     me.craft(id["b"],getCharCount(onechar,"b"))
  121.     me.craft(id["c"],getCharCount(onechar,"c"))
  122.     me.craft(id["d"],getCharCount(onechar,"d"))
  123.     me.craft(id["e"],getCharCount(onechar,"e"))
  124.     me.craft(id["f"],getCharCount(onechar,"f"))
  125. end
  126.  
  127. if as=="request" then
  128.     me.retrieve(id["0"],getCharCount(onechar,"0"),1)
  129.     me.retrieve(id["1"],getCharCount(onechar,"1"),1)
  130.     me.retrieve(id["2"],getCharCount(onechar,"2"),1)
  131.     me.retrieve(id["3"],getCharCount(onechar,"3"),1)
  132.     me.retrieve(id["4"],getCharCount(onechar,"4"),1)
  133.     me.retrieve(id["5"],getCharCount(onechar,"5"),1)
  134.     me.retrieve(id["6"],getCharCount(onechar,"6"),1)
  135.     me.retrieve(id["7"],getCharCount(onechar,"7"),1)
  136.     me.retrieve(id["8"],getCharCount(onechar,"8"),1)
  137.     me.retrieve(id["9"],getCharCount(onechar,"9"),1)
  138.     me.retrieve(id["a"],getCharCount(onechar,"a"),1)
  139.     me.retrieve(id["b"],getCharCount(onechar,"b"),1)
  140.     me.retrieve(id["c"],getCharCount(onechar,"c"),1)
  141.     me.retrieve(id["d"],getCharCount(onechar,"d"),1)
  142.     me.retrieve(id["e"],getCharCount(onechar,"e"),1)
  143.     me.retrieve(id["f"],getCharCount(onechar,"f"),1)
  144. end
  145.  
  146. print("Höhe: "..tostring(#img))
  147. print("Breite: "..tostring(#img[1]))
  148. e,key=os.pullEvent("key")
  149.     while key~=28 do
  150.     e,key=os.pullEvent("key")
  151.     end
  152.  
  153.     for i=1, #chars do
  154.     turtle.select(slot[string.sub(onechar,i,i)])
  155.         if turtle.getItemCount(slot[string.sub(onechar,i,i)])>1 then
  156.         turtle.drop(1)
  157.         else
  158.         print("Bitte slot "..slot[string.sub(onechar,i,i)].." nachfüllen")
  159.         io.read()
  160.         end
  161.     turtle.drop(1)
  162.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement