Advertisement
Guest User

Lightbarrow Sugarcane Bot v1.0

a guest
Oct 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1.  
  2. // ***********************************************************************
  3. // Settings
  4. // ***********************************************************************
  5.  
  6. &crop = sugar_cane;
  7. &harvest_tool = minecart;
  8. &food = carrot;
  9.  
  10. // Starting coordinates at North-West corner of the field
  11.  
  12. #start_x = 8566
  13. #start_z = -3100
  14.  
  15. // Field Dimensions
  16. // row number is changed by z, increases moving south
  17. #num_rows = 103
  18. // 103
  19.  
  20. // column number is changed by x, decreases moving west
  21. #num_cols = 47
  22. // 47
  23.  
  24. // look(0, 90), is facing north(0) and down(90)
  25. // look(180,90), is facing south(180) and down(90)
  26.  
  27.  
  28. // **********************************************************************
  29. // Bot State
  30. // **********************************************************************
  31. #end_x = (#start_x + #num_cols) - 1
  32. #end_z = (#start_z + #num_rows) + 1
  33.  
  34.  
  35.  
  36. // **********************************************************************
  37. // Algorithm
  38. // **********************************************************************
  39.  
  40. // harvest field
  41. do;
  42.  
  43. #offset = 1;
  44.  
  45. // Make sure the bot starts at the correct spot
  46. IF( (%XPOS% != %#start_x%) || (%ZPOS% != %#start_z%));
  47. LOG("Bot not at starting position. Move to X=%#start_x%, Z=%#start_z%");
  48. stop();
  49. endif;
  50.  
  51. // The bot is at the starting spot
  52. &harvest_direction = "south";
  53.  
  54. // Harvest a column
  55. do(%#num_cols%);
  56.  
  57. // Eat the chosen food so that we dont
  58. // end up leaving spaces in the field
  59. // when if we eat the crop
  60. do;
  61. log("Eating food. Hunger = %HUNGER%");
  62. pick(%&food%);
  63. if(%ITEM% != %&food%);
  64. log("Bot does not have enough food.");
  65. disconnect();
  66. endif;
  67. key(use);
  68. while(%HUNGER% <= 16);
  69.  
  70. sprint();
  71. // =======================================================
  72. // Harvest
  73. // =======================================================
  74. log("Harvesting");
  75. pick(%&harvest_tool%);
  76. if(%ITEM% != %&harvest_tool%);
  77. log("Harvest tool unavailable. Stopping bot.");
  78. endif;
  79.  
  80. if(%&harvest_direction% = "south");
  81. #dest_z = #end_z;
  82. else;
  83. #dest_z = #start_z;
  84. endif;
  85.  
  86. do;
  87. if(%&harvest_direction% = "south");
  88. // look south
  89. look(180,0);
  90. else;
  91. // look north
  92. look(0,0);
  93. endif;
  94.  
  95. keydown(forward);
  96. key(attack);
  97. while(%ZPOS% != %#dest_z%);
  98. keyup(forward);
  99. unsprint();
  100.  
  101. // =========================================
  102. // Move #"offset" columns towards the east
  103. // =========================================
  104. if(%XPOS% != %#end_x%);
  105. log("Moving east to next column");
  106. #dest_x = %XPOS%+%#offset%;
  107. do;
  108. look(90,0);
  109. keydown(forward);
  110. while(%XPOS% != %#dest_x%);
  111. keyup(forward);
  112. endif;
  113.  
  114. if(%#offset% = 1);
  115. // make it 2
  116. #offset = #offset + 1;
  117. else;
  118. #offset = 1;
  119. endif;
  120.  
  121. // Change the harvest direction
  122. if(%&harvest_direction% = "south");
  123. &harvest_direction = "north";
  124. else;
  125. &harvest_direction = "south";
  126. endif;
  127.  
  128.  
  129. // end of harvesting one column and ready for next
  130. loop;
  131.  
  132. log("End of harvesting the sugar cane field");
  133.  
  134.  
  135. // ================================================
  136. // Walk back to the start (North-West corner)
  137. // ================================================
  138. if(%XPOS% != %#start_x%);
  139. log("Moving back to the start of the field.");
  140. // move west
  141. do;
  142. look(270,0);
  143. keydown(forward);
  144. //log("x = %XPOS%, and start_x = %#start_x%");
  145. while(%XPOS% != %#start_x%);
  146. keyup(forward);
  147. endif;
  148.  
  149. // walk back to the start (north-south) direction
  150. if(%ZPOS% != %#start_z%);
  151. log("Moving back to the start of the field.");
  152. // move north
  153. do;
  154. look(0,90);
  155. keydown(forward);
  156. //log("z = %ZPOS%, and start_z = %#start_z%");
  157. while(%ZPOS% != %#start_z%);
  158. keyup(forward);
  159. endif;
  160.  
  161.  
  162. // Bot should be at the start again.
  163. // if not something went wrong.
  164. if( (%XPOS% != %#start_x%) || (%ZPOS% != %#start_z%) );
  165. log("Bot went off-course. Stopping.");
  166. stop();
  167. endif;
  168.  
  169. log("Back at the start.");
  170.  
  171. // main loop
  172. loop;
  173.  
  174. log("Bot stopped successfully. Harvest complete.")
  175.  
  176. stop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement