Skip to content

Commit 4694438

Browse files
authored
use getter for .heldItem (#73)
1 parent 8d7e0e1 commit 4694438

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare module 'prismarine-entity' {
3535
width: number;
3636
onGround: boolean;
3737
equipment: Array<Item>;
38-
heldItem: Item;
38+
get heldItem(): Item;
3939
metadata: Array<object>;
4040
isValid: boolean;
4141
health?: number;

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = (registryOrVersion) => {
1919
this.effects = {}
2020
// 0 = held item, 1-4 = armor slot
2121
this.equipment = new Array(5)
22-
this.heldItem = this.equipment[0] // shortcut to equipment[0]
2322
this.isValid = true
2423
this.metadata = []
2524
}
@@ -44,9 +43,12 @@ module.exports = (registryOrVersion) => {
4443
this.displayName = name
4544
}
4645

46+
get heldItem () {
47+
return this.equipment[0]
48+
}
49+
4750
setEquipment (index, item) {
4851
this.equipment[index] = item
49-
this.heldItem = this.equipment[0]
5052
}
5153

5254
getCustomName () {

0 commit comments

Comments
 (0)