Skip to content

Commit aec7e90

Browse files
committed
Fixed issue when the server don't return UUID of arrow
Now if the uuid is empty the bot create new one for them is necessary to check the trayectory of bow, it is neeeded unique ID
1 parent ad1839e commit aec7e90

File tree

7 files changed

+64
-23
lines changed

7 files changed

+64
-23
lines changed

.vscode/launch.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
{
8-
"name": "Debug",
9-
"type": "node",
10-
"request": "attach",
11-
"restart": true,
12-
"port": 9229,
13-
},
7+
8+
{
9+
"name": "Debug",
10+
"type": "node",
11+
"request": "attach",
12+
"restart": true,
13+
"port": 9229,
14+
}
1415
]
15-
}
16-
16+
}

examples/shield_up.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ const bot = mineflayer.createBot({
1717
viewDistance: 'far'
1818
}) as ModdedBot
1919

20-
bot.loadPlugin(minecraftHawkEye)
2120

2221
const DISTANCE_VISION = 100
2322
let danger: number | undefined
2423

24+
bot.once('inject_allowed', () => {
25+
bot.loadPlugin(minecraftHawkEye)
26+
})
27+
2528
bot.once('spawn', () => {
2629
mineflayerViewer.mineflayer(bot, { port: 3000 })
2730
})

package-lock.json

+34-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"dependencies": {
1010
"detect-collisions": "^7.0.5",
11+
"uuid": "^9.0.1",
1112
"vec3": "^0.1.10"
1213
},
1314
"devDependencies": {
@@ -18,11 +19,13 @@
1819
"@babel/preset-typescript": "^7.24.1",
1920
"@types/chai": "^4.3.16",
2021
"@types/mocha": "^10.0.6",
22+
"@types/uuid": "^9.0.8",
2123
"babel-plugin-module-resolver": "^5.0.2",
2224
"chai": "^5.1.1",
2325
"minecraft-wrap": "^1.5.1",
2426
"mineflayer": "^4.20.1",
2527
"mocha": "^10.4.0",
28+
"prismarine-item": "^1.14.0",
2629
"prismarine-viewer": "^1.28.0",
2730
"swc": "^1.0.11",
2831
"ts-node": "^10.9.2",
@@ -32,6 +35,9 @@
3235
},
3336
"scripts": {
3437
"server": "ts-node test/common/start_test_server.ts",
38+
"server:docker": "docker run --rm -it -p:25565:25565 -v $(pwd):/app/ minecraft_server ts-node /app/test/common/start_test_server",
39+
"server:build": "docker build -t minecraft_server -f ./.devcontainer/Dockerfile .",
40+
"isnpect": "node --watch --inspect=0.0.0.0:9229 --inspect -r ts-node/register -r tsconfig-paths/register $1",
3541
"test": "mocha -r ts-node/register -r test/hooks.ts --timeout 60000 --exit",
3642
"test:all": "npm run test 'test/hawkTests/*.ts'",
3743
"build": "babel src --extensions \".ts,.js\" --delete-dir-on-start --out-dir dist",

src/hawkEye.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isEntity, OptionsMasterGrade, Projectil, Weapons, weaponsProps } from '
22
import { Vec3 } from 'vec3'
33
import getMasterGrade from './hawkEyeEquations'
44
import { Entity } from 'prismarine-entity'
5+
import { v4 as uuidv4 } from 'uuid';
56
import { bot } from './loadBot'
67

78
let target: Entity | OptionsMasterGrade
@@ -159,14 +160,16 @@ const sleep = (ms: number) => {
159160

160161
const currentProjectileDetected: Record<string, Projectil> = {}
161162
export const detectProjectiles = (projectile: string = 'arrow') => {
162-
const projectiles = Object.values(bot.entities)
163-
// @ts-ignore PR: https://github.com/PrismarineJS/prismarine-entity/pull/55
164-
.filter((e) => e.name === projectile && e.type === "projectile")
163+
const ArrayEntities = Object.values(bot.entities)
164+
const projectiles = ArrayEntities.filter((e) => e.name === projectile && e.type === "projectile")
165165

166166
const updatedAt = Date.now()
167167

168168
projectiles.forEach((e) => {
169-
if (!e.uuid) return
169+
if (!e.uuid) {
170+
e.uuid = uuidv4()
171+
}
172+
170173
if (!currentProjectileDetected[e.uuid]) {
171174
currentProjectileDetected[e.uuid] = {
172175
uuid: e.uuid,

src/projectilRadar.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@ const radar = () => {
6060
const colission = calculateImpactToBoundingBox(prevousArrow, currentArrow, botBoxes)
6161

6262
if (colission) {
63-
// @ts-ignore
6463
bot.emit('incoming_projectil', p, arrowTrajectoryPoints)
6564
return
6665
}
6766

6867
}
6968

70-
// console.log(p)
7169
})
7270
}
7371

7472
export const detectAim = () => {
7573
const system = new System();
7674
const { boxXZ } = getBoxes(getBotBoxes())
7775
const entities = Object.values(bot.entities)
78-
// @ts-ignore PR: https://github.com/PrismarineJS/prismarine-entity/pull/55
76+
// @ts-ignore metadata loading bow
7977
.filter((e) => (e.type === "player" && (e.metadata[8] === 1 || e.metadata[8] === 3) /* Is loading bow */) || (e.type === 'mob' && e.name === 'skeleton'))
8078
.filter(e => {
8179
if (e.name === 'skeleton' && e.position.distanceTo(bot.entity.position) > 16) return false

test/common/testCommon.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Vec3 } from 'vec3'
44
import { sleep, onceWithCleanup } from './promise_utils'
55

66
import { Block } from 'prismarine-block'
7+
import { Item } from 'prismarine-item'
78
import { Bot } from '../../src/types';
89

910
export default (bot: Bot) => {
@@ -103,8 +104,8 @@ export default (bot: Bot) => {
103104

104105
const inventoryClearedProm = Promise.all(
105106
bot.inventory.slots
106-
.filter(item => item)
107-
.map(item => onceWithCleanup(bot.inventory, `updateSlot:${item.slot}`, { checkCondition: (oldItem, newItem) => newItem === null })))
107+
.filter((item): item is Item => item !== null && item !== undefined)
108+
.map(item => onceWithCleanup(bot.inventory, `updateSlot:${item.slot}`, { checkCondition: (_, newItem) => newItem === null })))
108109

109110
bot.chat('/clear')
110111
await msgProm

0 commit comments

Comments
 (0)