diff --git a/lib/plugins/entities.js b/lib/plugins/entities.js index 33b83e95f..16d747d1c 100644 --- a/lib/plugins/entities.js +++ b/lib/plugins/entities.js @@ -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] }) }) @@ -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) }) @@ -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 }