fix: alive trait sync
This commit is contained in:
parent
204907c27f
commit
0305d24c73
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
15
packages/entity/packets/trait-update-alive.packet.js
Normal file
15
packages/entity/packets/trait-update-alive.packet.js
Normal file
|
@ -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',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import {
|
||||||
import {compose} from '@avocado/core';
|
import {compose} from '@avocado/core';
|
||||||
|
|
||||||
import {StateProperty, Trait} from '../trait';
|
import {StateProperty, Trait} from '../trait';
|
||||||
import {TraitAlivePacket} from '../packets/trait-alive.packet';
|
import {TraitUpdateAlivePacket} from '../packets/trait-update-alive.packet';
|
||||||
|
|
||||||
const decorate = compose(
|
const decorate = compose(
|
||||||
StateProperty('life', {
|
StateProperty('life', {
|
||||||
|
@ -79,7 +79,7 @@ export class Alive extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
acceptPacket(packet) {
|
acceptPacket(packet) {
|
||||||
if (packet instanceof TraitAlivePacket) {
|
if (packet instanceof TraitUpdateAlivePacket) {
|
||||||
this.entity.life = packet.data.life;
|
this.entity.life = packet.data.life;
|
||||||
this.entity.maxLife = packet.data.maxLife;
|
this.entity.maxLife = packet.data.maxLife;
|
||||||
}
|
}
|
||||||
|
@ -89,8 +89,11 @@ export class Alive extends decorate(Trait) {
|
||||||
return this._deathSound;
|
return this._deathSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
packetsForUpdate() {
|
packets(informed) {
|
||||||
return this.createTraitPacketUpdates(TraitAlivePacket);
|
const {life, maxLife} = this.stateDifferences();
|
||||||
|
if (life || maxLife) {
|
||||||
|
return new TraitUpdateAlivePacket(this.state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listeners() {
|
listeners() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user