Skip to content

Commit

Permalink
use getter for .heldItem (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
szdytom committed Dec 30, 2023
1 parent 8d7e0e1 commit 4694438
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -35,7 +35,7 @@ declare module 'prismarine-entity' {
width: number;
onGround: boolean;
equipment: Array<Item>;
heldItem: Item;
get heldItem(): Item;
metadata: Array<object>;
isValid: boolean;
health?: number;
Expand Down
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -19,7 +19,6 @@ module.exports = (registryOrVersion) => {
this.effects = {}
// 0 = held item, 1-4 = armor slot
this.equipment = new Array(5)
this.heldItem = this.equipment[0] // shortcut to equipment[0]
this.isValid = true
this.metadata = []
}
Expand All @@ -44,9 +43,12 @@ module.exports = (registryOrVersion) => {
this.displayName = name
}

get heldItem () {
return this.equipment[0]
}

setEquipment (index, item) {
this.equipment[index] = item
this.heldItem = this.equipment[0]
}

getCustomName () {
Expand Down

0 comments on commit 4694438

Please sign in to comment.