Advertisement
kssr3951

mining_0.1.1

Sep 28th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. dofile("lib_turtle_0.2.3");
  2. dofile("lib_neko_0.1.1");
  3.  
  4. local tunnelLen = 0;
  5. local depthLevel = 0;
  6.  
  7. local negaAry = { 3, 4, 5, 6, 7 };
  8. local OTHER_FROM = 8;
  9. local OTHER_TO = 16;
  10.  
  11. local function unloadBlocks()
  12.   local tmpAry = {};
  13.   for _, slotIdx in pairs(negaAry) do
  14.     table.insert(tmpAry, { slotIndex = slotIdx, keepCnt = 1 });
  15.   end
  16.   for i = OTHER_FROM, OTHER_TO do
  17.     table.insert(tmpAry, { slotIndex = i, keepCnt = 0 });
  18.   end
  19.  
  20.   local primaryChest = true;
  21.   for _, unloadInfo in pairs(tmpAry) do
  22.     local idx = unloadInfo.slotIndex;
  23.     local keepCnt = unloadInfo.keepCnt;
  24.     turtle.select(idx);
  25.     local failureCnt = 0;
  26.     while true do
  27.       turtle.drop(turtle.getItemCount(idx) - keepCnt);
  28.       if keepCnt < turtle.getItemCount(idx) then
  29.         failureCnt = failureCnt + 1;
  30.         if 2 <= failureCnt then
  31.           print("Since the contents of the chest are full,");
  32.           print("blocks cannot be put in.");
  33.           print("Please make sufficient free space.");
  34.           print("Hit enter key when ready.");
  35.           read();
  36.           failureCnt = 0;
  37.         end
  38.         turtle.turnRight();
  39.         turtle.turnRight();
  40.         primaryChest = not primaryChest;
  41.       else
  42.         break;
  43.       end
  44.     end
  45.   end
  46.   if primaryChest then
  47.     turtle.turnLeft();
  48.   else
  49.     turtle.turnRight();
  50.   end
  51. end
  52.  
  53. local function dropNegaBlocks()
  54.   for _, slotIdx in pairs(negaAry) do
  55.     turtle.select(slotIdx);
  56.     for j = OTHER_FROM, OTHER_TO do
  57.       if turtle.compareTo(j) then
  58.         turtle.select(j);
  59.         turtle.drop();
  60.         turtle.select(slotIdx);
  61.       end
  62.     end
  63.   end
  64.  
  65. end
  66.  
  67. local function myUserEvent(para1)
  68.   if 0 == para1 then
  69.     nekoNega(0, negaAry);
  70.   elseif 1 == para1 then
  71.     nekoNega(1, negaAry);
  72.   elseif 2 == para1 then
  73.     nekoNega(2, negaAry);
  74.   elseif 3 == para1 then
  75.     for _, slotIdx in pairs(negaAry) do
  76.       if 2 <= turtle.getItemCount(slotIdx) then
  77.         turtle.select(slotIdx);
  78.         turtle.place();
  79.         break;
  80.       end
  81.     end
  82.   elseif 4 == para1 then
  83.     if 0 == tunnelLen % 8 then
  84.       local sel = -1;
  85.       if 2 <= turtle.getItemCount(1) then
  86.         sel = 1;
  87.       elseif 2 <= turtle.getItemCount(2) then
  88.         sel = 2;
  89.       end
  90.       if -1 ~= sel then
  91.         turtle.select(sel);
  92.         turtle.up();
  93.         turtle.dig();
  94.         turtle.down();
  95.         turtle.placeUp();
  96.         turtle.select(1);
  97.       end
  98.     end
  99.     tunnelLen = tunnelLen + 1;
  100.     if 0 == tunnelLen % 6 then
  101.       dropNegaBlocks();
  102.     end
  103.   elseif 5 == para1 then
  104.     tunnelLen = 0;
  105.   elseif 6 == para1 then
  106.     unloadBlocks();
  107.   elseif 7 == para1 then
  108.     dropNegaBlocks();
  109.   end
  110. end
  111.  
  112. userEventHandler = myUserEvent;
  113.  
  114. print("slot1 : torch x 64");
  115. print("slot2 : torch x 64");
  116. print("slot3 : Stone       x 1");
  117. print("slot4 : Dirt        x 1");
  118. print("slot5 : Gravel      x 1");
  119. print("slot6 : Obsidian    x 1");
  120. print("slot7 : Cobblestone x 1");
  121. print("Hit enter key when ready.");
  122. read();
  123.  
  124. log("-------------------------------");
  125. log("-- mining_0.1.1 start");
  126. log("-------------------------------");
  127.  
  128. for depthLevel = 0, 31 do
  129.   local msg = "depthLevel = " .. depthLevel .. " / fuelLevel = " .. turtle.getFuelLevel();
  130.   print(msg);
  131.   log(msg);
  132.  
  133.   doCommand(
  134.           " e0e1f"
  135.        .. "(e0e1 v2 lv1 rrv1 u v1 ll v1 r v0 df)3 e0 v2 l v7"
  136.        .. "(e1fv2 lv1 rrv1 e0uv1 llv1 rv0d v4)" .. (depthLevel * 4 + 10)
  137.        .. "(s1 ll e1fe0rr v3 uv3d)" .. (depthLevel * 4 + 10)
  138.        .. "e0u e1 s1p1d rr v5"
  139.        .. "s1 (e1fv2 lv1 rrv1 e0uv1 llv1 rv0d v4)" .. (depthLevel * 4 + 10)
  140.        .. "(s1 ll e1f k1 e0rr v3 uv3d)" .. (depthLevel * 4 + 10)
  141.        .. "r  (e1f)" .. ((depthLevel + 1) * 4)
  142.        .. "l v6"
  143.        );
  144.   if turtle.getFuelLevel() < 2000 then
  145.     print("Keep fuelLevel over 2000.");
  146.     print("Please refuel.");
  147.     refuelPrompt(nil);
  148.   end
  149.   doCommand(
  150.           "   (e1f)" .. ((depthLevel + 1) * 4)
  151.        );
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement