Skip to content

Commit

Permalink
fix entity name (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1504 committed Mar 16, 2021
1 parent 34edba1 commit 9f050d3
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function inject (bot, { version }) {
bot.username = bot._client.username
bot.entity.username = bot._client.username
bot.entity.type = 'player'
bot.entity.name = 'player'
})

bot._client.on('entity_equipment', (packet) => {
Expand Down Expand Up @@ -124,6 +125,7 @@ function inject (bot, { version }) {
// spawn named entity
const entity = fetchEntity(packet.entityId)
entity.type = 'player'
entity.name = 'player'
entity.username = bot.uuidToUsername[packet.playerUUID]
entity.uuid = packet.playerUUID
entity.dataBlobs = packet.data
Expand Down Expand Up @@ -159,17 +161,12 @@ function inject (bot, { version }) {
bot.emit('playerCollect', collector, collected)
})

bot._client.on('spawn_entity', (packet) => {
// spawn object/vehicle
const entity = fetchEntity(packet.entityId)
let entityData = objects[packet.type]

function setEntityData (entity, type, entityData) {
if (entityData === undefined) {
entityData = entitiesArray.find(entity => entity.internalId === packet.type)
entityData = entitiesArray.find(entity => entity.internalId === type)
}

if (entityData) {
entity.type = 'object'
entity.mobType = entityData.displayName
entity.objectType = entityData.displayName
entity.displayName = entityData.displayName
entity.entityType = entityData.id
Expand All @@ -180,8 +177,21 @@ function inject (bot, { version }) {
} else {
// unknown entity
entity.type = 'other'
entity.entityType = packet.type
entity.entityType = type
entity.mobType = 'unknown'
entity.displayName = 'unknown'
entity.name = 'unknown'
entity.kind = 'unknown'
}
}

bot._client.on('spawn_entity', (packet) => {
// spawn object/vehicle
const entity = fetchEntity(packet.entityId)
const entityData = objects[packet.type]

entity.type = 'object'
setEntityData(entity, packet.type, entityData)

if (bot.supportFeature('fixedPointPosition')) {
entity.position.set(packet.x / 32, packet.y / 32, packet.z / 32)
Expand All @@ -199,6 +209,9 @@ function inject (bot, { version }) {
bot._client.on('spawn_entity_experience_orb', (packet) => {
const entity = fetchEntity(packet.entityId)
entity.type = 'orb'
entity.name = 'experience_orb'
entity.width = 0.5
entity.height = 0.5

if (bot.supportFeature('fixedPointPosition')) {
entity.position.set(packet.x / 32, packet.y / 32, packet.z / 32)
Expand All @@ -215,27 +228,9 @@ function inject (bot, { version }) {
const entity = fetchEntity(packet.entityId)
entity.type = 'mob'
entity.uuid = packet.entityUUID
let entityData = mobs[packet.type]
const entityData = mobs[packet.type]

if (entityData === undefined) {
entityData = entitiesArray.find(entity => entity.internalId === packet.type)
}

if (entityData === undefined) {
entity.mobType = 'unknown'
entity.displayName = 'unknown'
entity.entityType = packet.type
entity.name = 'unknown'
entity.kind = 'unknown'
} else {
entity.mobType = entityData.displayName
entity.displayName = entityData.displayName
entity.entityType = entityData.id
entity.name = entityData.name
entity.kind = entityData.category
entity.height = entityData.height
entity.width = entityData.width
}
setEntityData(entity, packet.type, entityData)

if (bot.supportFeature('fixedPointPosition')) {
entity.position.set(packet.x / 32, packet.y / 32, packet.z / 32)
Expand Down

0 comments on commit 9f050d3

Please sign in to comment.