diff --git a/packages/entity/packets/trait-alive.packet.js b/packages/entity/packets/trait-alive.packet.js deleted file mode 100644 index 9134acd..0000000 --- a/packages/entity/packets/trait-alive.packet.js +++ /dev/null @@ -1,12 +0,0 @@ -import {Packet} from '@avocado/net'; - -export class TraitAlivePacket extends Packet { - - static get schema() { - const schema = super.schema; - schema.data.life = 'uint16'; - schema.data.maxLife = 'uint16'; - return schema; - } - -} diff --git a/packages/entity/packets/trait-update-alive.packet.js b/packages/entity/packets/trait-update-alive.packet.js new file mode 100644 index 0000000..10defe2 --- /dev/null +++ b/packages/entity/packets/trait-update-alive.packet.js @@ -0,0 +1,15 @@ +import {Packet} from '@avocado/net'; + +export class TraitUpdateAlivePacket extends Packet { + + static get schema() { + return { + ...super.schema, + data: { + life: 'uint16', + maxLife: 'uint16', + } + }; + } + +} diff --git a/packages/entity/traits/alive.trait.js b/packages/entity/traits/alive.trait.js index f87b7f7..098f408 100644 --- a/packages/entity/traits/alive.trait.js +++ b/packages/entity/traits/alive.trait.js @@ -8,7 +8,7 @@ import { import {compose} from '@avocado/core'; import {StateProperty, Trait} from '../trait'; -import {TraitAlivePacket} from '../packets/trait-alive.packet'; +import {TraitUpdateAlivePacket} from '../packets/trait-update-alive.packet'; const decorate = compose( StateProperty('life', { @@ -79,7 +79,7 @@ export class Alive extends decorate(Trait) { } acceptPacket(packet) { - if (packet instanceof TraitAlivePacket) { + if (packet instanceof TraitUpdateAlivePacket) { this.entity.life = packet.data.life; this.entity.maxLife = packet.data.maxLife; } @@ -89,8 +89,11 @@ export class Alive extends decorate(Trait) { return this._deathSound; } - packetsForUpdate() { - return this.createTraitPacketUpdates(TraitAlivePacket); + packets(informed) { + const {life, maxLife} = this.stateDifferences(); + if (life || maxLife) { + return new TraitUpdateAlivePacket(this.state); + } } listeners() {