Skip to content

Commit dd37ca4

Browse files
committed
FIX allow to reassign movement keyboard buttons fixes #428
FIX colored banners
1 parent 80c9eb4 commit dd37ca4

File tree

6 files changed

+70
-54
lines changed

6 files changed

+70
-54
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"browserify-zlib": "^0.2.0",
145145
"buffer": "^6.0.3",
146146
"constants-browserify": "^1.0.0",
147-
"contro-max": "^0.1.9",
147+
"contro-max": "^0.1.12",
148148
"crypto-browserify": "^3.12.0",
149149
"cypress-esbuild-preprocessor": "^1.0.2",
150150
"eslint": "^8.50.0",
@@ -154,7 +154,7 @@
154154
"http-browserify": "^1.7.0",
155155
"http-server": "^14.1.1",
156156
"https-browserify": "^1.0.0",
157-
"mc-assets": "^0.2.62",
157+
"mc-assets": "^0.2.72",
158158
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
159159
"mineflayer": "github:zardoy/mineflayer#gen-the-master",
160160
"mineflayer-mouse": "^0.1.24",

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renderer/viewer/three/bannerRenderer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ export const renderBanner = (
143143

144144
ctx.imageSmoothingEnabled = false
145145

146-
// Always render base color first (even if no patterns)
147-
const baseColorHex = BANNER_COLORS[baseColor] || BANNER_COLORS[15]
148-
ctx.fillStyle = baseColorHex
149-
ctx.fillRect(0, 0, BANNER_WIDTH * scale, BANNER_HEIGHT * scale)
146+
// Base color rendering disabled
147+
// // Always render base color first (even if no patterns)
148+
// const baseColorHex = BANNER_COLORS[baseColor] || BANNER_COLORS[15]
149+
// ctx.fillStyle = baseColorHex
150+
// ctx.fillRect(0, 0, BANNER_WIDTH * scale, BANNER_HEIGHT * scale)
150151

151152
// Render patterns on top of base color (if any)
152153
if (blockEntity?.Patterns && blockEntity.Patterns.length > 0) {

src/controls.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@ const controlOptions = {
4343

4444
export const contro = new ControMax({
4545
commands: {
46-
general: {
47-
// movement
46+
movement: {
47+
forward: ['KeyW'],
48+
back: ['KeyS'],
49+
left: ['KeyA'],
50+
right: ['KeyD'],
4851
jump: ['Space', 'A'],
49-
inventory: ['KeyE', 'X'],
50-
drop: ['KeyQ', 'B'],
51-
dropStack: [null],
5252
sneak: ['ShiftLeft', 'Down'],
5353
toggleSneakOrDown: [null, 'Right Stick'],
5454
sprint: ['ControlLeft', 'Left Stick'],
55+
},
56+
general: {
57+
inventory: ['KeyE', 'X'],
58+
drop: ['KeyQ', 'B'],
59+
dropStack: [null],
5560
// game interactions
5661
nextHotbarSlot: [null, 'Right Bumper'],
5762
prevHotbarSlot: [null, 'Left Bumper'],
@@ -95,7 +100,6 @@ export const contro = new ControMax({
95100
// showLookingBlockUsages: ['Numpad4']
96101
// }
97102
} satisfies Record<string, Record<string, SchemaCommandInput>>,
98-
movementKeymap: 'WASD',
99103
movementVector: '2d',
100104
groupedCommands: {
101105
general: {
@@ -181,17 +185,14 @@ contro.on('movementUpdate', ({ vector, soleVector, gamepadIndex }) => {
181185
}
182186

183187
for (const key of ['forward', 'back', 'left', 'right'] as const) {
184-
if (newState[key] === bot.controlState[key]) continue
188+
if (!!(newState[key]) === !!(bot.controlState[key])) continue
185189
const action = !!newState[key]
186190
if (action && !isGameActive(true)) continue
187191
bot.setControlState(key, action)
188192

189193
if (key === 'forward') {
190194
// todo workaround: need to refactor
191-
if (action) {
192-
void contro.emit('trigger', { command: 'general.forward' } as any)
193-
} else {
194-
void contro.emit('release', { command: 'general.forward' } as any)
195+
if (!action) {
195196
setSprinting(false)
196197
}
197198
}
@@ -201,12 +202,12 @@ contro.on('movementUpdate', ({ vector, soleVector, gamepadIndex }) => {
201202
let lastCommandTrigger = null as { command: string, time: number } | null
202203

203204
const secondActionActivationTimeout = 300
204-
const secondActionCommands = {
205-
'general.jump' () {
205+
const secondActionCommands: Partial<Record<Command, () => void>> = {
206+
'movement.jump' () {
206207
// if (bot.game.gameMode === 'spectator') return
207208
toggleFly()
208209
},
209-
'general.forward' () {
210+
'movement.forward' () {
210211
setSprinting(true)
211212
}
212213
}
@@ -300,11 +301,10 @@ const setSneaking = (state: boolean) => {
300301
const onTriggerOrReleased = (command: Command, pressed: boolean) => {
301302
// always allow release!
302303
if (!bot || !isGameActive(false)) return
303-
if (stringStartsWith(command, 'general')) {
304-
// handle general commands
305-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
304+
305+
if (stringStartsWith(command, 'movement')) {
306306
switch (command) {
307-
case 'general.jump':
307+
case 'movement.jump':
308308
if (isSpectatingEntity()) break
309309
// if (viewer.world.freeFlyMode) {
310310
// const moveSpeed = 0.5
@@ -313,27 +313,45 @@ const onTriggerOrReleased = (command: Command, pressed: boolean) => {
313313
bot.setControlState('jump', pressed)
314314
// }
315315
break
316-
case 'general.sneak':
316+
case 'movement.sneak':
317317
// if (viewer.world.freeFlyMode) {
318318
// const moveSpeed = 0.5
319319
// viewer.world.freeFlyState.position.add(new Vec3(0, pressed ? -moveSpeed : 0, 0))
320320
// } else {
321321
setSneaking(pressed)
322322
// }
323323
break
324-
case 'general.sprint':
324+
case 'movement.sprint':
325325
// todo add setting to change behavior
326326
if (pressed) {
327327
setSprinting(pressed)
328328
}
329329
break
330-
case 'general.toggleSneakOrDown':
330+
case 'movement.toggleSneakOrDown':
331331
if (gameAdditionalState.isFlying) {
332332
setSneaking(pressed)
333333
} else if (pressed) {
334334
setSneaking(!gameAdditionalState.isSneaking)
335335
}
336336
break
337+
case 'movement.forward':
338+
contro.setMovement('forward', pressed)
339+
break
340+
case 'movement.back':
341+
contro.setMovement('backward', pressed)
342+
break
343+
case 'movement.left':
344+
contro.setMovement('left', pressed)
345+
break
346+
case 'movement.right':
347+
contro.setMovement('right', pressed)
348+
break
349+
}
350+
}
351+
if (stringStartsWith(command, 'general')) {
352+
// handle general commands
353+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
354+
switch (command) {
337355
case 'general.attackDestroy':
338356
document.dispatchEvent(new MouseEvent(pressed ? 'mousedown' : 'mouseup', { button: 0 }))
339357
break
@@ -479,7 +497,7 @@ contro.on('trigger', ({ command }) => {
479497
if (secondActionCommand) {
480498
if (command === lastCommandTrigger?.command && Date.now() - lastCommandTrigger.time < secondActionActivationTimeout) {
481499
const commandToTrigger = secondActionCommands[lastCommandTrigger.command]
482-
commandToTrigger()
500+
commandToTrigger?.()
483501
lastCommandTrigger = null
484502
} else {
485503
lastCommandTrigger = {
@@ -493,10 +511,6 @@ contro.on('trigger', ({ command }) => {
493511

494512
if (stringStartsWith(command, 'general')) {
495513
switch (command) {
496-
case 'general.jump':
497-
case 'general.sneak':
498-
case 'general.toggleSneakOrDown':
499-
case 'general.sprint':
500514
case 'general.attackDestroy':
501515
case 'general.rotateCameraLeft':
502516
case 'general.rotateCameraRight':
@@ -952,10 +966,6 @@ export const handleMobileButtonActionCommand = (command: ActionType | ActionHold
952966
if (typeof commandValue === 'string' && !stringStartsWith(commandValue, 'custom')) {
953967
const event: CommandEventArgument<typeof contro['_commandsRaw']> = {
954968
command: commandValue as Command,
955-
schema: {
956-
keys: [],
957-
gamepad: []
958-
}
959969
}
960970
if (isDown) {
961971
contro.emit('trigger', event)

src/inventoryWindows.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,14 @@ export const openItemsCanvas = (type, _bot = bot as typeof bot | null) => {
403403
}
404404

405405
const upWindowItemsLocal = () => {
406-
if (!lastWindow && bot.currentWindow) {
407-
// edge case: might happen due to high ping, inventory should be closed soon!
408-
// openWindow(implementedContainersGuiMap[bot.currentWindow.type])
409-
return
410-
}
411-
void Promise.resolve().then(() => upInventoryItems(lastWindowType === null))
406+
void Promise.resolve().then(() => {
407+
if (!lastWindow && bot.currentWindow) {
408+
// edge case: might happen due to high ping, inventory should be closed soon!
409+
// openWindow(implementedContainersGuiMap[bot.currentWindow.type])
410+
return
411+
}
412+
upInventoryItems(lastWindowType === null)
413+
})
412414
}
413415

414416
let skipClosePacketSending = false

src/react/AppStatus.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export default ({
4242

4343
const lockConnect = appQueryParams.lockConnect === 'true'
4444
const connectOptions = lastConnectOptions.value
45+
const connectionProxy =
46+
connectOptions?.server && !connectOptions.server.startsWith('ws://') && !connectOptions.server.startsWith('wss://')
47+
? connectOptions.proxy : undefined
4548

4649
return (
4750
<div className=''>
@@ -73,9 +76,9 @@ export default ({
7376
<p className={styles['last-status']}>{lastStatus ? `Last status: ${lastStatus}` : lastStatus}</p>
7477
{isError && <p className={`app-status-title-context-info ${styles.appStatusTitleContextInfo}`}>
7578
S: {connectOptions?.server ?? 'N/A'} {' '}
76-
P: {connectOptions?.proxy ?? 'N/A'} {' '}
79+
P: {connectionProxy ?? 'N/A'} {' '}
7780
V: {connectOptions?.botVersion ?? 'auto'} {' '}
78-
U: {connectOptions?.username ?? 'N/A'}
81+
U: {connectOptions?.username ?? 'N/A'}{' '}
7982
cV: {process.env.RELEASE_TAG ?? 'N/A'}
8083
</p>}
8184
</>

0 commit comments

Comments
 (0)