mc-beta-server/server/TrackedProperty.ts
Holly 797cd5db62
add TrackedProperty
This will be used for updating inventory slots when ItemStack properties change
2023-12-18 11:19:51 +00:00

23 lines
No EOL
440 B
TypeScript

export class TrackedProperty<T> {
private trackedValue?:T;
private updateCallback?:(value:T) => void;
constructor(initialValue?:T) {
this.trackedValue = initialValue;
}
public set OnChange(value:() => void) {
this.updateCallback = value;
}
public get Value() {
return this.trackedValue;
}
public set Value(value) {
this.trackedValue = value;
if (this.updateCallback && value) {
this.updateCallback(value);
}
}
}