feat: add visuals for entities damaging (#186)
This commit is contained in:
parent
ee966395c6
commit
66d26ad2e6
3 changed files with 35 additions and 1 deletions
|
|
@ -32,8 +32,8 @@
|
|||
❌ world_border_warning_reach
|
||||
❌ simulation_distance
|
||||
❌ chunk_biomes
|
||||
❌ damage_event
|
||||
❌ hurt_animation
|
||||
✅ damage_event
|
||||
✅ spawn_entity
|
||||
✅ spawn_entity_experience_orb
|
||||
✅ named_entity_spawn
|
||||
|
|
|
|||
|
|
@ -496,4 +496,22 @@ export class Entities extends EventEmitter {
|
|||
new TWEEN.Tween(e.rotation).to({ y: e.rotation.y + dy }, TWEEN_DURATION).start()
|
||||
}
|
||||
}
|
||||
|
||||
handleDamageEvent(entityId, damageAmount) {
|
||||
const entityMesh = this.entities[entityId]?.children.find(c => c.name === 'mesh')
|
||||
if (entityMesh) {
|
||||
entityMesh.traverse((child) => {
|
||||
if (child instanceof THREE.Mesh) {
|
||||
const clonedMaterial = child.material.clone()
|
||||
clonedMaterial.dispose()
|
||||
child.material = child.material.clone()
|
||||
const originalColor = child.material.color.clone()
|
||||
child.material.color.set(0xff_00_00)
|
||||
new TWEEN.Tween(child.material.color)
|
||||
.to(originalColor, 500)
|
||||
.start()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Entity } from 'prismarine-entity'
|
||||
import { versionToNumber } from 'prismarine-viewer/viewer/prepare/utils'
|
||||
import tracker from '@nxg-org/mineflayer-tracker'
|
||||
import { loader as autoJumpPlugin } from '@nxg-org/mineflayer-auto-jump'
|
||||
import { subscribeKey } from 'valtio/utils'
|
||||
|
|
@ -88,6 +89,21 @@ customEvents.on('gameLoaded', () => {
|
|||
}
|
||||
})
|
||||
|
||||
bot._client.on('damage_event', (data) => {
|
||||
const { entityId, sourceTypeId: damage } = data
|
||||
if (viewer.entities.entities[entityId]) {
|
||||
viewer.entities.handleDamageEvent(entityId, damage)
|
||||
}
|
||||
})
|
||||
|
||||
bot._client.on('entity_status', (data) => {
|
||||
if (versionToNumber(bot.version) >= versionToNumber('1.19.4')) return
|
||||
const { entityId, entityStatus } = data
|
||||
if (entityStatus === 2 && viewer.entities.entities[entityId]) {
|
||||
viewer.entities.handleDamageEvent(entityId, entityStatus)
|
||||
}
|
||||
})
|
||||
|
||||
const loadedSkinEntityIds = new Set<number>()
|
||||
|
||||
const playerRenderSkin = (e: Entity) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue