Advertisement
ecco7777

CC Pixelart Builder Block ME Supplier

Apr 10th, 2022 (edited)
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. args={...}
  2. file=args[1]
  3. me=peripheral.wrap("left")
  4. matID="chisel:antiblock"
  5. chars={}
  6. delay=0.1
  7. id={}
  8. id[" "]=0 --empty
  9. id["0"]=15
  10. id["1"]=14
  11. id["2"]=13
  12. id["3"]=12
  13. id["4"]=11
  14. id["5"]=10
  15. id["6"]=9
  16. id["7"]=8
  17. id["8"]=7
  18. id["9"]=6
  19. id["a"]=5
  20. id["b"]=4
  21. id["c"]=3
  22. id["d"]=2
  23. id["e"]=1
  24. id["f"]=0
  25.  
  26. function getCharCount(str,char)
  27.     charnum=0
  28.     for i=1, #str do
  29.         if string.sub(str,i,i)==char then
  30.             charnum=charnum+1
  31.         end
  32.     end
  33. return(charnum)
  34. end
  35.  
  36. function fileToTable(file)
  37.         if fs.exists(file)~=true then
  38.             print("file"..file.." not found")
  39.             return(false)
  40.         end
  41.     fp=fs.open(file,"r")
  42.     line={}
  43.     i=1
  44.     line[i]=fp.readLine()
  45.         if line[i]==nil then return(false) end
  46.         while line[i]~=nil do  
  47.         i=i+1
  48.         line[i]=fp.readLine()
  49.         end
  50. return(line)
  51. end
  52.  
  53. img=fileToTable(file)
  54.  
  55. i=1
  56. i2=1
  57. i3=1
  58.     while img[i]~=nil do
  59.         for i2=1, #img[i] do
  60.             chars[i3]=string.sub(img[1],i2,i2)
  61.             i3=i3+1
  62.         end
  63.     i=i+1
  64.     end
  65.  
  66. onechar=""
  67.     for i=1, #img do
  68.         onechar=onechar..img[i]
  69.     end
  70. term.clear()
  71. term.setCursorPos(1,1)
  72. term.write("Slot1 weiß: "..tostring(getCharCount(onechar,"0")))term.setCursorPos(1,2)
  73. term.write("Slot2 orange: "..tostring(getCharCount(onechar,"1")))term.setCursorPos(1,3)
  74. term.write("Slot3 magenta: "..tostring(getCharCount(onechar,"2")))term.setCursorPos(1,4)
  75. term.write("Slot4 hellblau: "..tostring(getCharCount(onechar,"3")))term.setCursorPos(1,5)
  76. term.write("Slot5 gelb: "..tostring(getCharCount(onechar,"4")))term.setCursorPos(1,6)
  77. term.write("Slot6 hellgrün: "..tostring(getCharCount(onechar,"5")))term.setCursorPos(1,7)
  78. term.write("Slot7 pink: "..tostring(getCharCount(onechar,"6")))term.setCursorPos(1,8)
  79. term.write("Slot8 grau: "..tostring(getCharCount(onechar,"7")))term.setCursorPos(21,1)
  80. term.write("Slot9 hellgrau: "..tostring(getCharCount(onechar,"8")))term.setCursorPos(21,2)
  81. term.write("Slot10 cyan: "..tostring(getCharCount(onechar,"9")))term.setCursorPos(21,3)
  82. term.write("Slot11 lila: "..tostring(getCharCount(onechar,"a")))term.setCursorPos(21,4)
  83. term.write("Slot12 blau: "..tostring(getCharCount(onechar,"b")+getCharCount(onechar,"b")))term.setCursorPos(21,5)
  84. term.write("Slot13 braun: "..tostring(getCharCount(onechar,"c")))term.setCursorPos(21,6)
  85. term.write("Slot14 grün: "..tostring(getCharCount(onechar,"d")))term.setCursorPos(21,7)
  86. term.write("Slot15 rot: "..tostring(getCharCount(onechar,"e")))term.setCursorPos(21,8)
  87. term.write("Slot16 schwarz: "..tostring(getCharCount(onechar,"f")))term.setCursorPos(1,9)
  88.  
  89. maxX=#img[1]
  90. maxY=#img
  91. print("Höhe: "..tostring(#img))
  92. print("Breite: "..tostring(#img[1]))
  93. as=io.read()
  94.  
  95. --dviding into chunks
  96. maxChunksY=math.ceil(maxY/16)
  97. maxChunksX=math.ceil(maxX/16)
  98. maxChunks=maxChunksX*maxChunksY
  99.  
  100. chunks={}
  101. for icy=1, maxChunksY do --icy ichunksy
  102.     ccyMax=16
  103.     ccyMin=icy*16-16
  104.     if maxChunksY>math.floor(maxY/16) and icx==math.floor(maxY/16) then
  105.         ccyMax=math.mod(maxY/16)
  106.         ccyMin=(icy-1)*16+1
  107.     end
  108.     for icx=1, maxChunksX do --icx ichunksx
  109.         ccxMax=16
  110.         ccxMin=icx*16-16
  111.         if maxChunksX>math.floor(maxX/16) and icx==math.floor(maxX/16) then
  112.             ccxMax=math.mod(maxX/16)
  113.             ccxMin=(icx-1)*16+1
  114.         end
  115.         --addtochunks
  116.         for iccx=1,ccxMax do
  117.             for iccy=1,ccyMax do
  118.                 table.insert(chunks,id[string.sub(img[ccyMin+iccx],ccxMin+iccy,ccxMin+iccy)])
  119.             end
  120.         end
  121.     end
  122. end
  123.  
  124. for i=1,#chunks do
  125. fingerprint={damage=chunks[i],name=matID}
  126. me.findItem(fingerprint).export("up",1)
  127. sleep(delay)
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement