Skip to content

Commit

Permalink
correctly clean entities on world switch!
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Aug 31, 2024
1 parent 5e62a83 commit c6755fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface BotEvents {
) => Promise<void> | void
actionBar: (jsonMsg: ChatMessage) => Promise<void> | void
error: (err: Error) => Promise<void> | void
worldSwitch: () => Promise<void> | void
message: (jsonMsg: ChatMessage, position: string) => Promise<void> | void
messagestr: (message: string, position: string, jsonMsg: ChatMessage) => Promise<void> | void
unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => Promise<void> | void
Expand Down Expand Up @@ -387,8 +388,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
times?: number
) => Promise<void>



setCommandBlock: (pos: Vec3, command: string, options: CommandBlockOptions) => void

clickWindow: (
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ function inject (bot, { version, storageBuilder, hideErrors }) {
bot._getDimensionName = () => worldName

async function switchWorld () {
bot.emit('worldSwitch')
if (bot.world) {
if (storageBuilder) {
await bot.world.async.waitSaving()
Expand Down
13 changes: 8 additions & 5 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ function inject (bot) {
return best
}

// Reset list of players and entities on login
bot._client.on('login', (packet) => {
bot.players = {}
bot.uuidToUsername = {}
removeAllEntities()
bot.entities = {}
// login
bot.entity = fetchEntity(packet.entityId)
bot.username = bot._client.username
Expand All @@ -112,6 +107,14 @@ function inject (bot) {
bot.entity.eyeHeight = PLAYER_EYEHEIGHT
})

// Reset list of players and entities on world switch (login or respawn packet)
bot.on('worldSwitch', () => {
bot.players = {}
bot.uuidToUsername = {}
removeAllEntities()
bot.entities = {}
})

bot._client.on('entity_equipment', (packet) => {
// entity equipment
const entity = fetchEntity(packet.entityId)
Expand Down

0 comments on commit c6755fc

Please sign in to comment.