Skip to content

Commit

Permalink
properly cleanup all entities
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Jul 13, 2024
1 parent c03c76e commit 7f65e46
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function inject (bot) {
bot._client.on('login', (packet) => {
bot.players = {}
bot.uuidToUsername = {}
removeAllEntities()
bot.entities = {}
// login
bot.entity = fetchEntity(packet.entityId)
Expand All @@ -115,6 +116,18 @@ function inject (bot) {
bot.emit('entityEquip', entity)
})

const removeAllEntities = () => {
for (const entity of Object.values(bot.entities ?? {})) {
// refactor to function
bot.emit('entityGone', entity)
entity.isValid = false
if (entity.username && bot.players[entity.username]) {
bot.players[entity.username].entity = null
}
delete bot.entities[entity.id]
}
}

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

0 comments on commit 7f65e46

Please sign in to comment.