Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/switch_game_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { client_chat_msg, Formats } from '../core/chat.js'
import { write_error } from './commands.js'
import { literal } from './declare_options.js'

const GameStates = ['GAME_ALIVE', 'GAME_GHOST']
const GameStates = ['GAME_ALIVE', 'GAME_GHOST', 'MAIN_MENU']

export const switch_game_state_nodes = [
literal({
Expand Down
23 changes: 23 additions & 0 deletions src/core/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,26 @@ export function send_movement_speed(client, speed) {
],
})
}

function abilities_flags({
invulnerable = false,
flying = false,
allow_flying = false,
creative_mode = false,
}) {
return (
(invulnerable ? 0x01 : 0) |
(flying ? 0x02 : 0) |
(allow_flying ? 0x04 : 0) |
(creative_mode ? 0x08 : 0)
)
}

export function set_flying(client, flying) {
log.info({ flying, username: client.username }, 'send flying')
client.write('abilities', {
flags: abilities_flags({ flying }),
flyingSpeed: 0.05,
walkingSpeed: 0.1,
})
}
1 change: 1 addition & 0 deletions src/core/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const CATEGORY = {
export const Sound = {
SWITCH_SPELL: 'aresrpg:ui_spell_switch',
SPELL_FAILED: 'aresrpg:ui_spell_failed',
MUSIC_MANRACNI: 'aresrpg:music_manracni',
}

export function play_sound({
Expand Down
53 changes: 53 additions & 0 deletions src/modules/player_main_menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { setInterval } from 'timers/promises'

import { aiter } from 'iterator-helper'

import { set_flying } from '../core/attribute.js'
import { write_inventory } from '../core/inventory.js'
import { Sound, play_sound } from '../core/sound.js'
import { PLAYER_INVENTORY_ID } from '../settings.js'
import { abortable } from '../core/iterator.js'

const MANRACNI_DURATION = 67000

function reset_player_inventory(client) {
write_inventory(client, { inventory: {} }) // clear inventory
// set overlay
client.write('set_slot', {
windowId: PLAYER_INVENTORY_ID,
slot: 5, // head slot
item: { present: true, itemId: 217 /* carved_pumpkin */, itemCount: 1 },
})
}

/** @type {import("../server").Module} */
export default {
name: 'player_main_menu',
observe({ client, events, signal }) {
client.on('window_click', () => reset_player_inventory(client))

events.once('STATE_UPDATED', state => {
reset_player_inventory(client)
set_flying(client, true)

play_sound({ client, sound: Sound.MUSIC_MANRACNI, ...state.position })

aiter(
abortable(setInterval(MANRACNI_DURATION, null, { signal })),
).forEach(() =>
play_sound({ client, sound: Sound.MUSIC_MANRACNI, ...state.position }),
)
})

signal.addEventListener(
'abort',
() => {
set_flying(client, false)
client.write('stop_sound', {
flags: 0 /* https://wiki.vg/index.php?title=Protocol&oldid=16907#Stop_Sound MASTER category */,
})
},
{ once: true },
)
},
}
11 changes: 9 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import player_resource_pack from './modules/player_resource_pack.js'
import player_login from './modules/player_login.js'
import player_statistics from './modules/player_statistics.js'
import { create_client_handler } from './player.js'
import player_main_menu from './modules/player_main_menu.js'

/** @template U
* @typedef {import('./types').UnionToIntersection<U>} UnionToIntersection */
Expand Down Expand Up @@ -113,16 +114,23 @@ const world = await Promise.resolve(entity_modules)
const observables = {
/** @type {import("./player").Observables} */
optional_modules: {
'MAIN:MENU': [player_main_menu],
'GAME:GHOST': [
player_attributes,
player_bells,
player_block_placement,
player_inventory,
player_position,
player_soul,
player_sync,
player_tablist,
player_ui,
player_chunk,
],
'GAME:ALIVE': [
player_attributes,
player_bells,
player_block_placement,
player_position,
player_damage,
player_environmental_damage,
player_experience,
Expand Down Expand Up @@ -153,7 +161,6 @@ const observables = {
...(USE_RESOURCE_PACK ? [player_resource_pack] : []),
player_login,
player_statistics,
player_position,
player_commands,
player_chat,
],
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,4 @@ type MobAction = {
[K in keyof MobActions]: { type: K; payload: MobActions[K]; time: number }
}[keyof MobActions]

type GameState = 'GAME:ALIVE' | 'GAME:GHOST'
type GameState = 'GAME:ALIVE' | 'GAME:GHOST' | 'MAIN:MENU'