Skip to content

Commit

Permalink
Update entities.js
Browse files Browse the repository at this point in the history
  • Loading branch information
aesthetic0001 authored Dec 16, 2023
1 parent 0dcdb30 commit 31d4e06
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ function inject (bot) {
if (entity.username && bot.players[entity.username]) {
bot.players[entity.username].entity = null
}
if (entity.passengers) {
entity.passengers.forEach((passengerId) => {
const passengerEntity = fetchEntity(passengerId)
if (!passengerEntity) return
passengerEntity.vehicle = null
})
}
delete bot.entities[id]
})
})
Expand Down Expand Up @@ -342,6 +349,14 @@ function inject (bot) {
entity.heldItem = entity.equipment[0] // Update held item like prismarine-entity does upon equipment updates
}

if (eventName === 'entityDead' && entity.passengers) {
entity.passengers.forEach((passengerId) => {
const passengerEntity = fetchEntity(passengerId)
if (!passengerEntity) return
passengerEntity.vehicle = null
})
}

if (eventName) bot.emit(eventName, entity)
})

Expand Down Expand Up @@ -750,12 +765,16 @@ function inject (bot) {
const passenger = fetchEntity(vehicle.passengers[0])
if (!passenger) return
passenger.vehicle = null
bot.emit('entityDetach', passenger, vehicle)
} else {
vehicle.passengers.forEach((passengerId) => {
if (passengers.find(id => id === passengerId)) return
const passenger = fetchEntity(passengerId)
if (!passenger) return
passenger.vehicle = null
})
const passenger = fetchEntity(passengers[0])
if (!passenger) return
passenger.vehicle = vehicle
bot.emit('entityAttach', passenger, vehicle)
}
vehicle.passengers = passengers
}
Expand Down

0 comments on commit 31d4e06

Please sign in to comment.