You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this is my code, any help in fixing this would be nice
constmineflayer=require('mineflayer');const{ Block }=require('prismarine-block');const{mineflayer: mineflayerViewer}=require('prismarine-viewer');constpathfinder=require('mineflayer-pathfinder').pathfinder;constMovements=require('mineflayer-pathfinder').Movements;const{ GoalNear, GoalBlock }=require('mineflayer-pathfinder').goals;constblockFinderPlugin=require('mineflayer-blockfinder')(mineflayer);constcollectBlock=require('mineflayer-collectblock').plugin;const{ Vec3 }=require('vec3');constminecraftData=require('minecraft-data');constpvp=require('mineflayer-pvp').plugin;constlocations={NewSpawnTown: {x: 16287,y: 78,z: 3995},// Add more locations as needed};constbot=mineflayer.createBot({host: 'play.callmecarson.live',auth: 'microsoft',version: '1.20.2',});constmcData=require('minecraft-data')(bot.version);console.log("Bot is starting...");bot.on('login',()=>{console.log("Bot has logged in!");});bot._client.on('resource_pack_send',(data)=>{bot._client.write('resource_pack_receive',{hash: "Resourcepack",result: 3});bot._client.write('resource_pack_receive',{hash: "Resourcepack",result: 0});});bot.on('message',(jsonMsg)=>{console.log(jsonMsg);});bot.loadPlugin(pathfinder);bot.loadPlugin(blockFinderPlugin);bot.loadPlugin(collectBlock)bot.loadPlugin(pvp);letisSpleefing=false;functionplaySpleef(){constmcData=minecraftData(bot.version);// Configure the bot's PVP behavior// Set up the bot's pathfindingconstdefaultMove=newMovements(bot,mcData);bot.pathfinder.setMovements(defaultMove);// Function to check if the player is standing on snowfunctionisStandingOnSnow(playerPosition){constblockBeneath=bot.blockAt(playerPosition.offset(0,-1,0));returnblockBeneath&&blockBeneath.name==='snow_block';}// Function to find the nearest player standing on snowfunctionfindNearestPlayer(){constplayers=Object.values(bot.players).filter(p=>p.entity&&p.entity.position);letnearestPlayer=null;letnearestDistance=Infinity;for(constplayerofplayers){if(!bot.entity.position||!isStandingOnSnow(player.entity.position)){continue;// Skip if the bot's position or the player's position is not available, or the player is not standing on snow}constdistance=player.entity.position.distanceTo(bot.entity.position);if(distance<nearestDistance){nearestPlayer=player;nearestDistance=distance;}}returnnearestPlayer;// Return the nearest player found, or null if no valid player was found}// Function to determine the bot's strategy based on the game statefunctiondetermineStrategy(){constnumTeammates=Object.values(bot.players).filter(p=>p.team===bot.team).length;constnumOpponents=Object.values(bot.players).filter(p=>p.team!==bot.team).length;if(numTeammates>numOpponents){return'attack';// Attack strategy: Pursue and spleef opponents aggressively}elseif(numTeammates<numOpponents){return'evasion';// Evasion strategy: Run and avoid attacks, focus on survival}else{return'balanced';// Balanced strategy: Mix of attacking and defending}}// Main loop for playing spleeffunctionstartSpleef(){if(!isSpleefing)return;constplayer=findNearestPlayer();conststrategy=determineStrategy();if(player){if(strategy==='attack'||(strategy==='balanced'&&bot.entity.position.distanceTo(player.entity.position)<5)){// Define the goal near the playerconstgoal=newGoalNear(player.entity.position.x,player.entity.position.y,player.entity.position.z,2);bot.pathfinder.setGoal(goal);bot.pathfinder.goto(goal);// Attempt to equip the netherite shovel and dig the block below the playerconstshovelItem=bot.inventory.items().find(item=>item.name==='netherite_shovel');if(!shovelItem){console.log('No netherite shovel found in inventory.');return;// Exit the function or choose an alternative action}bot.equip(shovelItem,'hand',(err)=>{if(err){console.log(`Error equipping netherite shovel:`,err);return;}constblockBelow=bot.blockAt(player.entity.position.offset(0,-1,0));if(blockBelow){bot.dig(blockBelow,(err)=>{if(err){console.log('Error digging block:',err);}});}});}elseif(strategy==='evasion'){// Run away from opponents and focus on survivalconstescapeDirection=bot.entity.position.minus(player.entity.position).normalize();constescapeGoal=newGoalNear(bot.entity.position.x+escapeDirection.x*10,bot.entity.position.y,bot.entity.position.z+escapeDirection.z*10);bot.pathfinder.setGoal(escapeGoal);bot.pathfinder.goto(escapeGoal);}else{// Balanced strategy when far from the opponent...constdefendDirection=bot.entity.position.minus(player.entity.position).normalize();constdefendGoal=newGoalNear(bot.entity.position.x+defendDirection.x*5,bot.entity.position.y,bot.entity.position.z+defendDirection.z*5,1);bot.pathfinder.setGoal(defendGoal);bot.pathfinder.goto(defendGoal);}}// Schedule the next spleef iterationsetTimeout(startSpleef,500);// Adjust the delay as needed}// Start playing spleefisSpleefing=true;startSpleef();}//look at a playerfunctionlookAtPlayer(player){constpos=player.entity.position.offset(0,player.entity.height,0);bot.lookAt(pos,true)}// Define global variables for storing bot statsletbotHealth=0;letbotHunger=0;// Update bot statsfunctionupdateBotStats(){botHealth=bot.health;botHunger=bot.food;}// Command handler for displaying bot statsfunctionshowBotStats(username){bot.whisper(username,`Bot Stats: Health: ${botHealth} Hunger: ${botHunger}`);}// Add a listener for when the bot's health changesbot.on('health',()=>{updateBotStats();});letfollowingPlayer=null;letfollowGoal=null;functionupdateFollowGoal(){if(followingPlayer){constplayer=bot.players[followingPlayer];if(player&&player.entity){// Calculate the distance to the playerconstdistance=bot.entity.position.distanceTo(player.entity.position);constvisibleDistance=100;// Set a distance threshold for followingif(distance<=visibleDistance){constnewPosition=newVec3(player.entity.position.x,player.entity.position.y,player.entity.position.z);// Check if there is already a goal and if it is the same as the new positionif(bot.pathfinder.goal&&bot.pathfinder.goal.isEnd(newPosition)){return;// If the current goal is the same, do not update it}constmcData=require('minecraft-data')(bot.version);constmovements=newMovements(bot,mcData);movements.scaffoldingBlocks=[];movements.canDig=false;bot.pathfinder.setMovements(movements);constgoal=newGoalNear(newPosition.x,newPosition.y,newPosition.z,1);followGoal=goal;bot.pathfinder.setGoal(goal,true);}}}}functionfindAndSit(){constblockTypes=['wooden_slab','brick_slab','stone_brick_slab','nether_brick_slab','quartz_slab','stone_slab','sandstone_slab','purpur_slab','wooden_stairs','brick_stairs','stone_brick_stairs','nether_brick_stairs','quartz_stairs','stone_stairs','sandstone_stairs','purpur_stairs'];constblockIDs=blockTypes.map(type=>bot.registry.blocksByName[type]?.id).filter(id=>id!==undefined);conststartTime=performance.now();bot.findBlock({point: bot.entity.position,matching: blockIDs,maxDistance: 128,count: 10,},(err,blocks)=>{if(err){console.log('Error finding blocks:',err);return;}consttime=(performance.now()-startTime).toFixed(2);if(blocks.length>0){constblock=blocks[0];constmcData=require('minecraft-data')(bot.version);constmovements=newMovements(bot,mcData);movements.canDig=false;movements.allowSprinting=false;movements.scaffoldingBlocks=[];bot.pathfinder.setMovements(movements);constgoal=newGoalBlock(block.position.x,block.position.y+1,block.position.z);bot.pathfinder.setGoal(goal,true);bot.pathfinder.goto(goal);bot.on('goal_reached',()=>{//make sure its an empty hand//remove the item from main handbot.unequip("hand");bot.activateBlock(block);});}else{bot.whisper("overtimepog",`No blocks found in ${time} ms.`);}});}// Global variable to track the Sumo game stateletisPlayingSumo=false;constSumoMovements=newMovements(bot,mcData);SumoMovements.canDig=false;SumoMovements.allowSprinting=true;SumoMovements.scaffoldingBlocks=[];// Function to start playing Sumo and continuously attempt to hit the opponentfunctionplaySumo(){bot.pathfinder.setMovements(SumoMovements);if(!isPlayingSumo)return;constopponents=Object.values(bot.players).filter(p=>p.username!==bot.username&&p.entity);constnearestOpponent=opponents.reduce((nearest,opponent)=>{if(!nearest||bot.entity.position.distanceTo(opponent.entity.position)<bot.entity.position.distanceTo(nearest.entity.position)){returnopponent;}returnnearest;},null);if(nearestOpponent){constopponentPos=nearestOpponent.entity.position;constdistanceToOpponent=bot.entity.position.distanceTo(opponentPos);// Ensure we're close enough to hit the opponentif(distanceToOpponent>3){// Move closer to the opponentconstmoveToOpponentGoal=newGoalNear(opponentPos.x,opponentPos.y,opponentPos.z,2);bot.pathfinder.setGoal(moveToOpponentGoal,true);bot.pathfinder.goto(moveToOpponentGoal);}else{// Stop moving and swing at the opponentbot.pathfinder.setGoal(null);bot.lookAt(opponentPos.offset(0,nearestOpponent.entity.height,0),true,()=>{bot.attack(nearestOpponent.entity);});}// Check if the opponent has fallenif(opponentPos.y<=bot.entity.position.y-2){console.log(`${nearestOpponent.username} has fallen off!`);isPlayingSumo=false;// Stop the game if opponent has fallenbot.pathfinder.setGoal(null);// Clear the current goalconsole.log('Sumo minigame stopped.');}}else{console.log('No opponents found nearby.');}}functioncheckAndEatFood(){consthungerThreshold=16;// Minecraft uses 20 scale, 16 means eat when 4 or less hunger shanks are fullif(bot.food<=hungerThreshold){constfood=findFoodInInventory();if(food){bot.equip(food,'hand').then(()=>{bot.activateItem();}).catch(console.error);}}}functionstopSpleef(){if(!isSpleefing){console.log('Spleef is not currently running.');return;}isSpleefing=false;bot.pathfinder.setGoal(null);clearTimeout(spleefTimeout);console.log('Spleef stopped.');}functionfindFoodInInventory(){constfoodItems=['apple','bread','cooked_porkchop','baked_potato'];// List all the food items you want the bot to considerreturnbot.inventory.items().find(item=>foodItems.includes(item.name));}asyncfunctionbringItemToPlayer(itemName,quantity,playerName){if(playerName==="me"){playerName="overtimepog";// Assuming 'overtimepog' is your username.}constplayer=bot.players[playerName];if(!player){bot.whisper("overtimepog",`Player '${playerName}' not found.`);return;}bot.whisper("overtimepog",`Attempting to bring ${quantity} of ${itemName} to ${playerName}.`);if(!mcData.blocksByName[itemName]){bot.whisper("overtimepog",`Item '${itemName}' not found.`);return;}constblocks=awaitbot.findBlocks({matching: mcData.blocksByName[itemName].id,maxDistance: 64,count: quantity});if(blocks.length<quantity){bot.whisper("overtimepog",`Not enough blocks of '${itemName}' found nearby. Only found ${blocks.length}.`);return;}bot.whisper("overtimepog",`Found ${blocks.length} blocks. Beginning to collect.`);constmovements=newMovements(bot,mcData);movements.allowSprinting=false;movements.canDig=true;bot.pathfinder.setMovements(movements);for(leti=0;i<blocks.length;i++){constblockPos=blocks[i];if(!awaitmoveToAndCollectBlock(newVec3(blockPos.x,blockPos.y,blockPos.z))){bot.whisper("overtimepog",`Failed to collect block at (${blockPos.x}, ${blockPos.y}, ${blockPos.z}). Stopping collection.`);break;}}}asyncfunctionmoveToAndCollectBlock(blockPos){returnnewPromise((resolve,reject)=>{constgoal=newGoalNear(blockPos.x,blockPos.y,blockPos.z,1);bot.pathfinder.setGoal(goal,true);constlistener=()=>{bot.removeListener('goal_reached',listener);// Remove the listener to clean upbot.collectBlock.collect(blockPos,(err)=>{if(err){bot.whisper("overtimepog",`Error collecting item: ${err.message}`);reject(false);// false indicates failure}else{bot.whisper("overtimepog",`Successfully collected item from (${blockPos.x}, ${blockPos.y}, ${blockPos.z}).`);resolve(true);// true indicates success}});};bot.once('goal_reached',listener);});}functionlookForBoats(){constnearestBoat=bot.nearestEntity(entity=>['boat','oak_boat','spruce_boat','birch_boat','jungle_boat','acacia_boat','dark_oak_boat'].includes(entity.name));if(!nearestBoat){bot.whisper("overtimepog","No boats found nearby.");return;}// Check if "overtimepog" is near the boatletovertimepogNearby=false;for(constplayerNameinbot.players){constplayer=bot.players[playerName];if(player.entity&&player.entity.position.distanceTo(nearestBoat.position)<=3){overtimepogNearby=true;break;// Exit loop early if found}}if(overtimepogNearby){constmcData=require('minecraft-data')(bot.version);constmovements=newMovements(bot,mcData);movements.canDig=false;movements.allowSprinting=false;movements.scaffoldingBlocks=[];bot.pathfinder.setMovements(movements);constgoal=newGoalNear(nearestBoat.position.x,nearestBoat.position.y,nearestBoat.position.z,2);bot.pathfinder.setGoal(goal,true);bot.pathfinder.goto(goal);bot.whisper("overtimepog","Heading towards the nearest boat...");bot.once('goal_reached',()=>{bot.whisper("overtimepog","Reached the nearest boat.");bot.activateEntity(nearestBoat);bot.activateBlock(nearestBoat);});}else{bot.whisper("overtimepog","No boats with 'overtimepog' nearby.");}}letlastBoatGiveTime=0;constboatGiveInterval=5000;// 5000 milliseconds or 5 seconds between giving boatsfunctiongiveBoatsToPlayer(username){constplayer=bot.players[username];if(!player||!player.entity){//console.log(`Player ${username} not found or not loaded.`);return;}constboatTypes=['oak_boat','spruce_boat','birch_boat','jungle_boat','acacia_boat','dark_oak_boat'];constboats=bot.inventory.items().filter(item=>boatTypes.includes(item.name));if(boats.length===0){//console.log(`I have no boats to give to ${username}.`);return;}consttargetPosition=player.entity.position;if(bot.entity.position.distanceTo(targetPosition)>5){//console.log(`Player ${username} is too far away to give boats.`);return;}for(constboatofboats){bot.tossStack(boat,err=>{if(err){console.log(`Error giving boat to ${username}: ${err.message}`);}else{console.log(`Gave a ${boat.name} to ${username}.`);}});}}letsumoInterval;// Holds the reference to the interval for managing lifecyclefunctionstartSumoGame(){if(!isPlayingSumo){isPlayingSumo=true;// Start the interval only if it hasn't been started beforeif(!sumoInterval){sumoInterval=setInterval(playSumo,100);}}}functionstopSumoGame(){if(isPlayingSumo){isPlayingSumo=false;if(sumoInterval){clearInterval(sumoInterval);// Clear the interval when the game stopssumoInterval=null;// Reset the interval variable}}}bot.on('physicsTick',()=>{constcurrentTime=Date.now();if(currentTime-lastBoatGiveTime>boatGiveInterval){lastBoatGiveTime=currentTime;giveBoatsToPlayer('overtimepog');// Replace 'overtimepog' with your username}updateFollowGoal();checkAndEatFood();});bot.on('whisper',(username,message)=>{if(username===bot.username)return;if(message==="hi"&&username==="overtimepog"){bot.chat("Hello!");}elseif(message.startsWith('follow')&&username==="overtimepog"){consttargetPlayer=message.split(' ')[1];if(targetPlayer==="me"){followingPlayer="overtimepog";}else{followingPlayer=targetPlayer;}if(targetPlayer===''){bot.whisper(username,"Player not found.");return;}bot.whisper(followingPlayer,`Following ${followingPlayer}, type "stop" to stop following`);}elseif(message==="stop"&&(username==="overtimepog"||username===followingPlayer)){followingPlayer=null;followGoal=null;bot.pathfinder.setGoal(null);if(isSpleefing){stopSpleef();// Ensure this stops the spleef game if it is running}isPlayingSumo=false;stopSumoGame();bot.whisper(username,"Stopped.");}elseif(message.startsWith('find')&&message.split(' ').length===2&&username==="overtimepog"){constname=message.split(' ')[1];if(bot.registry.blocksByName[name]===undefined){bot.whisper(username,`${name} is not a block name`);return;}constids=[bot.registry.blocksByName[name].id];conststartTime=performance.now();constblocks=bot.findBlocks({matching: ids,maxDistance: 128,count: 10});consttime=(performance.now()-startTime).toFixed(2);constvalidBlocks=blocks.filter(block=>block.position&&block.position.x!==undefined&&block.position.y!==undefined&&block.position.z!==undefined);if(validBlocks.length>0){constcoords=validBlocks.map(block=>`(${block.position.x}, ${block.position.y}, ${block.position.z})`).join(', ');bot.whisper(username,`I found ${validBlocks.length}${name} blocks in ${time} ms at coordinates: ${coords}`);}else{bot.whisper(username,`No ${name} blocks found within the search radius or with complete coordinates.`);}}elseif(message==="sit"&&username==="overtimepog"){findAndSit();bot.whisper(username,"Sitting down.")}elseif(message===("up"||"get up")&&username==="overtimepog"){bot.dismount();}elseif(message.startsWith("look at ")&&username==="overtimepog"){consttargetPlayerName=message.substring("look at ".length);// Extract the player's name from the messageif(!targetPlayerName){bot.whisper(username,"Please specify a player name.");return;}if(targetPlayerName===bot.username){bot.whisper(username,"I'm already looking at myself.");return;}if(targetPlayerName==="me"){lookAtPlayer(bot.players[username]);bot.whisper(username,"Looking at you.");return;}consttargetPlayer=bot.players[targetPlayerName];if(targetPlayer){lookAtPlayer(targetPlayer);bot.whisper(username,`Looking at ${targetPlayerName}.`);}else{bot.whisper(username,`Player '${targetPlayerName}' not found.`);}}elseif(message.startsWith('bring')&&username==="overtimepog"){constparts=message.split(' ');if(parts.length!==4){bot.whisper(username,"Invalid format. Usage: bring <player> <quantity> <item>");return;}consttargetPlayer=parts[1];constquantity=parseInt(parts[2]);if(isNaN(quantity)||quantity<=0){bot.whisper(username,"Invalid quantity. Please specify a positive integer.");return;}constitemName=parts[3];bringItemToPlayer(itemName,quantity,targetPlayer);}elseif(message==='stats'&&username==="overtimepog"){showBotStats(username);}elseif(message==='eat'&&username==="overtimepog"){checkAndEatFood();}elseif(message==='boat'&&username==="overtimepog"){if(followingPlayer!==null){followingPlayer=null;followGoal=null;isPlayingSumo=false;bot.pathfinder.setGoal(null);}lookForBoats();}elseif(message==='spleef'&&username==="overtimepog"){followingPlayer=null;followGoal=null;isPlayingSumo=false;playSpleef();}elseif(message==='join minigame'&&username==="overtimepog"){bot.chat("/mini join")}elseif(message.startsWith('say ')&&username==="overtimepog"){consttoSay=message.slice(4);// Removes the 'say ' part of the messagebot.chat(toSay);}if(message==='start sumo'){isPlayingSumo=true;console.log('Starting Sumo minigame.');startSumoGame();// Start the Sumo strategy}});//bot.on('entitySleep', () => {// bot.chat("gn :))");//});bot.once('spawn',()=>{console.log("Bot has spawned!");mineflayerViewer(bot,{port: 3007,firstPerson: true});});// Log errors and kick reasons:bot.on('kicked',console.log);bot.on('error',console.log);
The text was updated successfully, but these errors were encountered:
the bot keeps getting kicked like 5 seconds after it spawns, all I get is this, Idk what It means
this is my code, any help in fixing this would be nice
The text was updated successfully, but these errors were encountered: