Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. var mineflayer = require('mineflayer');
  2. var navigatePlugin = require('mineflayer-navigate')(mineflayer);
  3. var vec3 = mineflayer.vec3;
  4.  
  5. if(process.argv.length<4 || process.argv.length>6)
  6. {
  7. console.log("Usage : node pkFisher.js <host> <port> [<name>] [<password>]");
  8. process.exit(1);
  9. }
  10.  
  11. var bot = mineflayer.createBot({
  12. username: process.argv[4] ? process.argv[4] : "fisher",
  13. verbose: true,
  14. port:parseInt(process.argv[3]),
  15. host:process.argv[2],
  16. password:process.argv[5]
  17. });
  18.  
  19. navigatePlugin(bot);
  20.  
  21. var posChest = null;
  22. var posFish = null;
  23. var posFishX = null;
  24. var posFishY = null;
  25. var posFishZ = null;
  26. var blockChest = null;
  27.  
  28. var status = 'init';
  29.  
  30. bot.on('chat', function (username, message) {
  31. if (username == bot.username) return;
  32. if (message == '!coffre') {
  33. posChest = bot.players[username].entity.position;
  34. blockChest = findBlock('chest', 4, posChest);
  35. bot.chat('Bien, je vais stocker tous les poissons dans le coffre en ' + posChest);
  36. } else if (message == 'fish') {
  37. posFish = bot.players[username].entity.position;
  38. posFishX = bot.players[username].entity.position.x;
  39. posFishY = bot.players[username].entity.position.y;
  40. posFishZ = bot.players[username].entity.position.z;
  41. fish();
  42. }
  43.  
  44. if (message == 'come') {
  45. status == 'come';
  46. bot.navigate.to(bot.players[username].entity.position);
  47. }
  48. });
  49.  
  50. bot.navigate.on('arrived', function () {
  51. if (status == 'fish') {
  52. fishing();
  53. } else if (status == 'storing') {
  54. placeInChest();
  55. }
  56.  
  57. if (status == 'come') {
  58. bot.chat("Here !");
  59. come = null;
  60. }
  61. });
  62.  
  63. bot.on('soundEffectHeard', function (soundName, position, volume, pitch) {
  64. if (soundName == 'random.splash') {
  65. if (status == 'fishing') {
  66. // add timeout... Without we have bugs
  67. setTimeout(bot.activateItem, 500);
  68.  
  69. setTimeout(storeInChest, 1000);
  70. }
  71. }
  72. });
  73.  
  74. function fish() {
  75. status = 'fish';
  76. var temp = vec3(posFishX, posFishY, posFishZ);
  77. //bot.chat(temp + "");
  78. //bot.chat(posFish + "");
  79. bot.navigate.to(temp);
  80. }
  81.  
  82. function fishing(){
  83. status = 'fishing';
  84. selectRod();
  85. bot.activateItem();
  86. }
  87.  
  88. function selectRod() {
  89. var rod = bot.inventory.findInventoryItem(346);
  90. var rod_count = bot.inventory.count(346);
  91. if (rod) {
  92. bot.equip(rod, 'hand');
  93. console.log(rod_count + " fishing rods, " + rod.metadata + " damage taken from current rod");
  94. } else {
  95. console.log('You do not have a fishing rod!');
  96. }
  97. return rod;
  98. }
  99.  
  100. function storeInChest() {
  101. status = 'storing';
  102. var tempVar = vec3(blockChest.position.x, blockChest.position.y + 1, blockChest.position.z);
  103. //bot.chat(status + " " + tempVar);
  104. bot.navigate.to(tempVar);
  105. }
  106.  
  107. function placeInChest() {
  108. var chest = bot.openChest(blockChest);
  109. var fishI = bot.inventory.findInventoryItem(349);
  110. chest.on('open', function () {
  111. if (fishI) {
  112. chest.deposit(fishI.type, null, bot.inventory.count(fishI.type));
  113. }
  114. setTimeout(chest.close, 500);
  115. setTimeout(fish, 500);
  116. })
  117. }
  118.  
  119. function findBlock(type, size, point) {
  120. var block = null;
  121. var shortest = null;
  122. var x1 = Math.floor(point.x - size);
  123. var x2 = Math.floor(point.x + size);
  124. var y1 = Math.floor(point.y - size);
  125. var y2 = Math.floor(point.y + size);
  126. var z1 = Math.floor(point.z - size);
  127. var z2 = Math.floor(point.z + size);
  128. //bot.chat(x1 + "");
  129.  
  130. for (x = x1; x < x2; x++) {
  131. for (y = y1; y < y2; y++) {
  132. for (z = z1; z < z2; z++) {
  133.  
  134. var cPoint = vec3(x, y, z);
  135. var cBlock = bot.blockAt(cPoint);
  136. //bot.chat(cPoint + "");
  137. if (cBlock) {
  138. //bot.chat(cBlock.name);
  139. if (cBlock.name == type) {
  140. if ((shortest > cPoint.distanceTo(point)) || shortest == null) {
  141. shortest = cPoint.distanceTo(point);
  142. block = cBlock;
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149.  
  150. return block;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement