-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
49 lines (44 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const Vec3 = require('vec3').Vec3
const EventEmitter = require('events').EventEmitter
module.exports = (registryOrVersion) => {
const registry = typeof registryOrVersion === 'string' ? require('prismarine-registry')(registryOrVersion) : registryOrVersion
const ChatMessage = require('prismarine-chat')(registry)
const Item = require('prismarine-item')(registry)
class Entity extends EventEmitter {
constructor (id) {
super()
this.id = id
this.position = new Vec3(0, 0, 0)
this.velocity = new Vec3(0, 0, 0)
this.yaw = 0
this.pitch = 0
this.onGround = true
this.height = 0
this.width = 0
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 = []
}
setEquipment (index, item) {
this.equipment[index] = item
this.heldItem = this.equipment[0]
}
getCustomName () {
const name = this.metadata[2]
if (name === undefined) {
return null
}
return ChatMessage.fromNotch(name)
}
getDroppedItem () {
if (this.name !== 'item' && this.name !== 'Item' && this.name !== 'item_stack') {
return null // not a dropped item
}
return Item.fromNotch(this.metadata[registry.supportFeature('metadataIxOfItem')])
}
}
return Entity
}