Triacontakai

CompCraft Useful Functions

Feb 22nd, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- lua function testing for cc 1.75
  2. -------------------------------------
  3.  
  4. function digCheck()
  5.   turtle.dig();
  6.   local icheck = turtle.getItemDetail();
  7.   if icheck.name == "minecraft:cobblestone" or icheck.name == "minecraft:dirt" then
  8.     turtle.drop();
  9.   end
  10. end
  11. function switchToEmpty()
  12.   while not(turtle.getItemCount() == 0) do
  13.     if (turtle.getSelectedSlot() == 16) then
  14.       return false;
  15.     else
  16.       turtle.select(turtle.getSelectedSlot()+1);
  17.     end
  18.   end
  19. end
  20. function split(x, y)
  21.   local itr = 1;
  22.   local t = {};
  23.   for i in string.gmatch(x,"[^"..y.."]+") do
  24.     t[itr] = i;
  25.     itr = itr+1
  26.   end
  27.   return t;
  28. end
  29. function tableLength(t)
  30.   local itr = 0;
  31.   for i in pairs(t) do
  32.     itr = itr+1;
  33.   end
  34.   return itr;
  35. end
  36. function kvSplit(x,y)
  37.   local t = {};
  38.   s = split(x,y);
  39.   for i=1,tableLength(s),2 do
  40.     t[s[i]] = s[i+1];
  41.   end
  42.   return t;
  43. end
  44. function minerCompare(path)
  45.   local h = fs.open(path,"r");
  46.   local l = kvSplit(h.readAll(),">\n");
  47.   h.close();
  48.   a,scn = turtle.inspect();
  49.   local item = turtle.getItemDetail();
  50.   if scn["name"]==l[item.name] then
  51.     return true;
  52.   else
  53.     return turtle.compare();
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment