Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 5, 2023
1 parent 22e065a commit f5da310
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions lib/plugins/digging.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function inject (bot) {

bot.targetDigBlock = null
bot.lastDigTime = null
bot.digPercentage = 0;
bot.lastHeldItemName = "";
if (bot.heldItem) {bot.lastHeldItemName = bot.heldItem.name;}
bot.digPercentage = 0
bot.lastHeldItemName = ''
if (bot.heldItem) { bot.lastHeldItemName = bot.heldItem.name }
bot.on('heldItemChanged', () => {
//if (bot.heldItem) {console.log("this why " + bot.heldItem.name);}
//if (!bot.heldItem) {console.log("this why " + bot.heldItem);}
var nameToCompare = "";
if (bot.heldItem) {nameToCompare = bot.heldItem.name;}
// if (bot.heldItem) {console.log("this why " + bot.heldItem.name);}
// if (!bot.heldItem) {console.log("this why " + bot.heldItem);}
let nameToCompare = ''
if (bot.heldItem) { nameToCompare = bot.heldItem.name }
if (bot.lastHeldItemName != nameToCompare) {
bot.lastHeldItemName = nameToCompare;
bot.digPercentage = 0;
bot.lastHeldItemName = nameToCompare
bot.digPercentage = 0
}
});
})

async function dig (block, forceLook, digFace) {
if (block === null || block === undefined) {
Expand Down Expand Up @@ -112,34 +112,33 @@ function inject (bot) {
face: diggingFace // default face is 1 (top)
})
const waitTime = bot.digTime(block)
//waitInterval = setTimeout(finishDigging, waitTime)
if (waitInterval) {clearInterval(waitInterval);}
//bot.digPercentage = (50 / bot.digTime(block));
//bot.referenceTime = window.performance.now();
waitInterval = setInterval(() => {//!!!!
bot.digPercentage += (50 / bot.digTime(block));
//bot.digPercentage += (Math.abs(bot.referenceTime - window.performance.now()) / bot.digTime(block));
//console.log(Math.abs(bot.referenceTime - window.performance.now()) + ", " + bot.digPercentage);
//bot.referenceTime = window.performance.now();
if (bot.digPercentage >= 1.0) {
//console.log("broke it");
finishDigging();
}
}, 50);
// waitInterval = setTimeout(finishDigging, waitTime)
if (waitInterval) { clearInterval(waitInterval) }
// bot.digPercentage = (50 / bot.digTime(block));
// bot.referenceTime = window.performance.now();
waitInterval = setInterval(() => { //! !!!
bot.digPercentage += (50 / bot.digTime(block))
// bot.digPercentage += (Math.abs(bot.referenceTime - window.performance.now()) / bot.digTime(block));
// console.log(Math.abs(bot.referenceTime - window.performance.now()) + ", " + bot.digPercentage);
// bot.referenceTime = window.performance.now();
if (bot.digPercentage >= 1.0) {
// console.log("broke it");
finishDigging()
}
}, 50)
bot.targetDigBlock = block
bot.swingArm()


swingInterval = setInterval(() => {
if (bot.targetDigBlock) {
bot.swingArm()
} else {
clearInterval(swingInterval);
clearInterval(swingInterval)
}
}, 250)

function finishDigging () {
bot.digPercentage = 0;
bot.digPercentage = 0
clearInterval(swingInterval)
clearInterval(waitInterval)
swingInterval = null
Expand All @@ -157,14 +156,14 @@ function inject (bot) {
}

const eventName = `blockUpdate:${block.position}`
//console.log(bot.digPercentage + "% " + eventName);
// console.log(bot.digPercentage + "% " + eventName);
bot.on(eventName, onBlockUpdate)

bot.stopDigging = () => {
if (!bot.targetDigBlock) return
bot.removeListener(eventName, onBlockUpdate)
clearInterval(swingInterval)
bot.digPercentage = 0;
bot.digPercentage = 0
clearInterval(waitInterval)
swingInterval = null
waitInterval = null
Expand All @@ -184,14 +183,14 @@ function inject (bot) {
function onBlockUpdate (oldBlock, newBlock) {
// vanilla server never actually interrupt digging, but some server send block update when you start digging
// so ignore block update if not air
if (!newBlock) return;
if (!newBlock) return
if (newBlock.type !== 0) return
bot.removeListener(eventName, onBlockUpdate)
clearInterval(swingInterval)
clearInterval(waitInterval)
swingInterval = null
waitInterval = null
bot.digPercentage = 0.0;
bot.digPercentage = 0.0
bot.targetDigBlock = null
bot.lastDigTime = performance.now()
bot.emit('diggingCompleted', newBlock)
Expand Down Expand Up @@ -242,4 +241,4 @@ function inject (bot) {

function noop (err) {
if (err) throw err
}
}

0 comments on commit f5da310

Please sign in to comment.