Download Adam/control_primitives/waitForMobRemoved.js from OpenCausaLab/ADAM: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/OpenCausaLab/ADAM/resolve/main/Adam/control_primitives/waitForMobRemoved.js
- Command line
-
hf download hf://OpenCausaLab/ADAM/Adam/control_primitives/waitForMobRemoved.js
-
curl -L -o waitForMobRemoved.js https://huggingface.co/OpenCausaLab/ADAM/resolve/main/Adam/control_primitives/waitForMobRemoved.js
2.74 kB
| function waitForMobRemoved(bot, entity, timeout = 300) { | |
| return new Promise((resolve, reject) => { | |
| let success = false; | |
| let droppedItem = null; | |
| // Set up timeout | |
| const timeoutId = setTimeout(() => { | |
| success = false; | |
| bot.pvp.stop(); | |
| }, timeout * 1000); | |
| // Function to handle entityRemoved event | |
| function onEntityGone(e) { | |
| if (e === entity) { | |
| success = true; | |
| clearTimeout(timeoutId); | |
| bot.chat(`Killed ${entity.name}!`); | |
| bot.pvp.stop(); | |
| } | |
| } | |
| function onItemDrop(item) { | |
| if (entity.position.distanceTo(item.position) <= 1) { | |
| droppedItem = item; | |
| } | |
| } | |
| function onStoppedAttacking() { | |
| clearTimeout(timeoutId); | |
| bot.removeListener("entityGone", onEntityGone); | |
| bot.removeListener("stoppedAttacking", onStoppedAttacking); | |
| bot.removeListener("itemDrop", onItemDrop); | |
| if (!success) reject(new Error(`Failed to kill ${entity.name}.`)); | |
| else resolve(droppedItem); | |
| } | |
| // Listen for entityRemoved event | |
| bot.on("entityGone", onEntityGone); | |
| bot.on("stoppedAttacking", onStoppedAttacking); | |
| bot.on("itemDrop", onItemDrop); | |
| }); | |
| } | |
| function waitForMobShot(bot, entity, timeout = 300) { | |
| return new Promise((resolve, reject) => { | |
| let success = false; | |
| let droppedItem = null; | |
| // Set up timeout | |
| const timeoutId = setTimeout(() => { | |
| success = false; | |
| bot.hawkEye.stop(); | |
| }, timeout * 1000); | |
| // Function to handle entityRemoved event | |
| function onEntityGone(e) { | |
| if (e === entity) { | |
| success = true; | |
| clearTimeout(timeoutId); | |
| bot.chat(`Shot ${entity.name}!`); | |
| bot.hawkEye.stop(); | |
| } | |
| } | |
| function onItemDrop(item) { | |
| if (entity.position.distanceTo(item.position) <= 1) { | |
| droppedItem = item; | |
| } | |
| } | |
| function onAutoShotStopped() { | |
| clearTimeout(timeoutId); | |
| bot.removeListener("entityGone", onEntityGone); | |
| bot.removeListener("auto_shot_stopped", onAutoShotStopped); | |
| bot.removeListener("itemDrop", onItemDrop); | |
| if (!success) reject(new Error(`Failed to shoot ${entity.name}.`)); | |
| else resolve(droppedItem); | |
| } | |
| // Listen for entityRemoved event | |
| bot.on("entityGone", onEntityGone); | |
| bot.on("auto_shot_stopped", onAutoShotStopped); | |
| bot.on("itemDrop", onItemDrop); | |
| }); | |
| } | |