Compare commits
78 commits
next
...
nextgen-me
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fb7614ece | ||
|
|
3918f77877 | ||
|
|
3a6b079704 | ||
|
|
97f807f922 | ||
|
|
79b31ab106 | ||
|
|
d9bc5cbca9 | ||
|
|
cd69cef03b | ||
|
|
e8f81bd080 | ||
|
|
804256e4f8 | ||
|
|
0839889d21 | ||
|
|
07e7c6f227 | ||
|
|
b47258301c | ||
|
|
e7c240694f | ||
|
|
14e20a2cf6 | ||
|
|
9057d3acb5 | ||
|
|
547658f489 | ||
|
|
bf9c47dd26 | ||
|
|
9cede6dbbc | ||
|
|
6a5ac4f8d2 | ||
|
|
2630a57d35 | ||
|
|
20569747ca | ||
|
|
9888bd55c1 | ||
|
|
b501893ab2 | ||
|
|
e2b78333a1 | ||
|
|
e917764b76 | ||
|
|
ed041972c4 | ||
|
|
b579ee1767 | ||
|
|
d450a31547 | ||
|
|
853e0e1d84 | ||
|
|
8ddac97414 | ||
|
|
5eedb3c456 | ||
|
|
11abbfcbb1 | ||
|
|
8ee4dc37e7 | ||
|
|
dc2ad7ccce | ||
|
|
b483923009 | ||
|
|
82d0638eb8 | ||
|
|
cae2b612ba | ||
|
|
f88e9c8b61 | ||
|
|
136b051695 | ||
|
|
9fedafe776 | ||
|
|
ccb00043cf | ||
|
|
c1a7765fcb | ||
|
|
de3eddad89 | ||
|
|
e851f4fac2 | ||
|
|
f2f1c2538e | ||
|
|
5364085030 | ||
|
|
400f5982be | ||
|
|
dc073cd559 | ||
|
|
6eb50cde24 | ||
|
|
67d90a56fb | ||
|
|
f2307632a2 | ||
|
|
d74d860726 | ||
|
|
4d4637f710 | ||
|
|
847314d50f | ||
|
|
8a3c84745d | ||
|
|
3a9e2aa384 | ||
|
|
7cc562bd02 | ||
|
|
0597a3dad2 | ||
|
|
cefdf5362f | ||
|
|
d197859d47 | ||
|
|
1861edf567 | ||
|
|
d8294d565b | ||
|
|
4381ef4f75 | ||
|
|
c65db9a8cb | ||
|
|
34972e4e71 | ||
|
|
638dd6711e |
||
|
|
9356daaefc |
||
|
|
fb10179691 | ||
|
|
7e74633c14 | ||
|
|
2d7ec12a75 | ||
|
|
c626d105ff | ||
|
|
8db6b5bb51 | ||
|
|
2848ab63d3 | ||
|
|
537658476d | ||
|
|
044153c2dc | ||
|
|
380c21486b | ||
|
|
aed5b40516 | ||
|
|
3051cc35f5 |
3 changed files with 4713 additions and 5234 deletions
14
package.json
14
package.json
|
|
@ -119,11 +119,11 @@
|
|||
"workbox-build": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rsbuild/core": "^1.0.1-beta.9",
|
||||
"@rsbuild/plugin-node-polyfill": "^1.0.3",
|
||||
"@rsbuild/plugin-react": "^1.0.1-beta.9",
|
||||
"@rsbuild/plugin-type-check": "^1.0.1-beta.9",
|
||||
"@rsbuild/plugin-typed-css-modules": "^1.0.1",
|
||||
"@rsbuild/core": "1.0.1-beta.9",
|
||||
"@rsbuild/plugin-node-polyfill": "1.0.3",
|
||||
"@rsbuild/plugin-react": "1.0.1-beta.9",
|
||||
"@rsbuild/plugin-type-check": "1.0.1-beta.9",
|
||||
"@rsbuild/plugin-typed-css-modules": "1.0.1",
|
||||
"@storybook/addon-essentials": "^7.4.6",
|
||||
"@storybook/addon-links": "^7.4.6",
|
||||
"@storybook/blocks": "^7.4.6",
|
||||
|
|
@ -154,7 +154,7 @@
|
|||
"mc-assets": "^0.2.52",
|
||||
"mineflayer-mouse": "^0.1.7",
|
||||
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
|
||||
"mineflayer": "github:zardoy/mineflayer",
|
||||
"mineflayer": "github:GenerelSchwerz/mineflayer",
|
||||
"mineflayer-pathfinder": "^2.4.4",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"os-browserify": "^0.3.0",
|
||||
|
|
@ -195,9 +195,9 @@
|
|||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"@nxg-org/mineflayer-physics-util": "1.8.5",
|
||||
"buffer": "^6.0.3",
|
||||
"vec3": "0.1.10",
|
||||
"@nxg-org/mineflayer-physics-util": "1.5.8",
|
||||
"three": "0.154.0",
|
||||
"diamond-square": "github:zardoy/diamond-square",
|
||||
"prismarine-block": "github:zardoy/prismarine-block#next-era",
|
||||
|
|
|
|||
10024
pnpm-lock.yaml
generated
10024
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
121
src/controls.ts
121
src/controls.ts
|
|
@ -714,142 +714,32 @@ document.addEventListener('visibilitychange', (e) => {
|
|||
}
|
||||
})
|
||||
|
||||
// #region creative fly
|
||||
// these controls are more like for gamemode 3
|
||||
|
||||
const makeInterval = (fn, interval) => {
|
||||
const intervalId = setInterval(fn, interval)
|
||||
|
||||
const cleanup = () => {
|
||||
clearInterval(intervalId)
|
||||
cleanup.active = false
|
||||
}
|
||||
cleanup.active = true
|
||||
return cleanup
|
||||
}
|
||||
|
||||
const isFlying = () => bot.physics.gravity === 0
|
||||
let endFlyLoop: ReturnType<typeof makeInterval> | undefined
|
||||
|
||||
const currentFlyVector = new Vec3(0, 0, 0)
|
||||
window.currentFlyVector = currentFlyVector
|
||||
|
||||
// todo cleanup
|
||||
const flyingPressedKeys = {
|
||||
down: false,
|
||||
up: false
|
||||
}
|
||||
|
||||
const startFlyLoop = () => {
|
||||
if (!isFlying()) return
|
||||
endFlyLoop?.()
|
||||
|
||||
endFlyLoop = makeInterval(() => {
|
||||
if (!bot) {
|
||||
endFlyLoop?.()
|
||||
return
|
||||
}
|
||||
|
||||
bot.entity.position.add(currentFlyVector.clone().multiply(new Vec3(0, 0.5, 0)))
|
||||
}, 50)
|
||||
}
|
||||
|
||||
// todo we will get rid of patching it when refactor controls
|
||||
let originalSetControlState
|
||||
const patchedSetControlState = (action, state) => {
|
||||
if (!isFlying()) {
|
||||
return originalSetControlState(action, state)
|
||||
}
|
||||
|
||||
const actionPerFlyVector = {
|
||||
jump: new Vec3(0, 1, 0),
|
||||
sneak: new Vec3(0, -1, 0),
|
||||
}
|
||||
|
||||
const changeVec = actionPerFlyVector[action]
|
||||
if (!changeVec) {
|
||||
return originalSetControlState(action, state)
|
||||
}
|
||||
if (flyingPressedKeys[state === 'jump' ? 'up' : 'down'] === state) return
|
||||
const toAddVec = changeVec.scaled(state ? 1 : -1)
|
||||
for (const coord of ['x', 'y', 'z']) {
|
||||
if (toAddVec[coord] === 0) continue
|
||||
if (currentFlyVector[coord] === toAddVec[coord]) return
|
||||
}
|
||||
currentFlyVector.add(toAddVec)
|
||||
flyingPressedKeys[state === 'jump' ? 'up' : 'down'] = state
|
||||
}
|
||||
const isFlying = () => (bot.entity as any).flying
|
||||
|
||||
const startFlying = (sendAbilities = true) => {
|
||||
bot.entity['creativeFly'] = true
|
||||
if (sendAbilities) {
|
||||
bot._client.write('abilities', {
|
||||
flags: 2,
|
||||
})
|
||||
}
|
||||
// window.flyingSpeed will be removed
|
||||
bot.physics['airborneAcceleration'] = window.flyingSpeed ?? 0.1 // todo use abilities
|
||||
bot.entity.velocity = new Vec3(0, 0, 0)
|
||||
bot.creative.startFlying()
|
||||
startFlyLoop()
|
||||
(bot.entity as any).flying = true
|
||||
}
|
||||
|
||||
const endFlying = (sendAbilities = true) => {
|
||||
bot.entity['creativeFly'] = false
|
||||
if (bot.physics.gravity !== 0) return
|
||||
if (!isFlying()) return
|
||||
if (sendAbilities) {
|
||||
bot._client.write('abilities', {
|
||||
flags: 0,
|
||||
})
|
||||
}
|
||||
Object.assign(flyingPressedKeys, {
|
||||
up: false,
|
||||
down: false
|
||||
})
|
||||
currentFlyVector.set(0, 0, 0)
|
||||
bot.physics['airborneAcceleration'] = standardAirborneAcceleration
|
||||
bot.creative.stopFlying()
|
||||
endFlyLoop?.()
|
||||
(bot.entity as any).flying = false
|
||||
}
|
||||
|
||||
let allowFlying = false
|
||||
|
||||
export const onBotCreate = () => {
|
||||
let wasSpectatorFlying = false
|
||||
bot._client.on('abilities', ({ flags }) => {
|
||||
allowFlying = !!(flags & 4)
|
||||
if (flags & 2) { // flying
|
||||
toggleFly(true, false)
|
||||
} else {
|
||||
toggleFly(false, false)
|
||||
}
|
||||
})
|
||||
const gamemodeCheck = () => {
|
||||
if (bot.game.gameMode === 'spectator') {
|
||||
allowFlying = true
|
||||
toggleFly(true, false)
|
||||
wasSpectatorFlying = true
|
||||
} else if (wasSpectatorFlying) {
|
||||
toggleFly(false, false)
|
||||
wasSpectatorFlying = false
|
||||
}
|
||||
}
|
||||
bot.on('game', () => {
|
||||
gamemodeCheck()
|
||||
})
|
||||
bot.on('login', () => {
|
||||
gamemodeCheck()
|
||||
})
|
||||
}
|
||||
|
||||
const standardAirborneAcceleration = 0.02
|
||||
const toggleFly = (newState = !isFlying(), sendAbilities?: boolean) => {
|
||||
// if (bot.game.gameMode !== 'creative' && bot.game.gameMode !== 'spectator') return
|
||||
if (!allowFlying) return
|
||||
if (bot.setControlState !== patchedSetControlState) {
|
||||
originalSetControlState = bot.setControlState
|
||||
bot.setControlState = patchedSetControlState
|
||||
}
|
||||
if (!bot.entity.canFly) return
|
||||
|
||||
if (newState) {
|
||||
startFlying(sendAbilities)
|
||||
|
|
@ -858,7 +748,6 @@ const toggleFly = (newState = !isFlying(), sendAbilities?: boolean) => {
|
|||
}
|
||||
gameAdditionalState.isFlying = isFlying()
|
||||
}
|
||||
// #endregion
|
||||
|
||||
const selectItem = async () => {
|
||||
const block = bot.blockAtCursor(5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue