prismarine-entity 1.2.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -4
- package/example.js +1 -1
- package/index.d.ts +4 -0
- package/index.js +43 -24
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -7,11 +7,10 @@ Represent a minecraft entity
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
|
|
10
|
+
const Entity = require("prismarine-entity")('1.8.9')
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.log(entity);
|
|
12
|
+
const entity = new Entity(0)
|
|
13
|
+
console.log(entity)
|
|
15
14
|
```
|
|
16
15
|
|
|
17
16
|
## API
|
|
@@ -97,6 +96,16 @@ Equivalent to `entity.equipment[0]`.
|
|
|
97
96
|
|
|
98
97
|
See http://wiki.vg/Entities#Entity_Metadata_Format for more details.
|
|
99
98
|
|
|
99
|
+
#### entity.noClip
|
|
100
|
+
|
|
101
|
+
#### entity.vehicle
|
|
102
|
+
|
|
103
|
+
Entity that this entity is riding on
|
|
104
|
+
|
|
105
|
+
#### entity.passenger
|
|
106
|
+
|
|
107
|
+
Entity that is riding on this entity
|
|
108
|
+
|
|
100
109
|
#### entity.health
|
|
101
110
|
|
|
102
111
|
The health of the player, default: 20
|
|
@@ -109,8 +118,30 @@ The food of the player, default: 20
|
|
|
109
118
|
|
|
110
119
|
The player
|
|
111
120
|
|
|
121
|
+
#### entity.getCustomName()
|
|
122
|
+
|
|
123
|
+
returns a `prismarine-chat` ChatMessage object for the name of the entity or null if there isn't one
|
|
124
|
+
|
|
125
|
+
#### entity.getDroppedItem()
|
|
126
|
+
|
|
127
|
+
returns a `prismarine-item` Item object for the dropped item, if this is a dropped item, or it will return null
|
|
128
|
+
|
|
112
129
|
## History
|
|
113
130
|
|
|
131
|
+
### 2.1.1
|
|
132
|
+
|
|
133
|
+
* Update mcdata
|
|
134
|
+
|
|
135
|
+
### 2.1.0
|
|
136
|
+
|
|
137
|
+
* Adds Entity#getDroppedItem
|
|
138
|
+
|
|
139
|
+
### 2.0.0
|
|
140
|
+
|
|
141
|
+
* require mcversion in constructor
|
|
142
|
+
* add Entity#getCustomName()
|
|
143
|
+
* Add attributes for entity entity collision calculation (thanks @O-of)
|
|
144
|
+
|
|
114
145
|
### 1.2.0
|
|
115
146
|
|
|
116
147
|
* Add food saturation to typings
|
package/example.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import {EventEmitter} from 'events';
|
|
6
6
|
import { Vec3 } from 'vec3';
|
|
7
7
|
import { Item } from 'prismarine-item';
|
|
8
|
+
import { ChatMessage } from 'prismarine-chat';
|
|
8
9
|
|
|
9
10
|
declare module 'prismarine-entity' {
|
|
10
11
|
export interface Effect {
|
|
@@ -17,6 +18,7 @@ declare module 'prismarine-entity' {
|
|
|
17
18
|
constructor(id: number);
|
|
18
19
|
id: number;
|
|
19
20
|
type: EntityType;
|
|
21
|
+
uuid?: string;
|
|
20
22
|
username?: string;
|
|
21
23
|
mobType?: string;
|
|
22
24
|
displayName?: string;
|
|
@@ -42,6 +44,8 @@ declare module 'prismarine-entity' {
|
|
|
42
44
|
player?: object;
|
|
43
45
|
effects: Effect[];
|
|
44
46
|
setEquipment(index: number, item: Item): void;
|
|
47
|
+
getCustomName(): ChatMessage | null;
|
|
48
|
+
getDroppedItem(): Item | null;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
export type EntityType = 'player' | 'mob' | 'object' | 'global' | 'orb' | 'other';
|
package/index.js
CHANGED
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
const Vec3 = require('vec3').Vec3
|
|
2
|
-
const util = require('util')
|
|
3
2
|
const EventEmitter = require('events').EventEmitter
|
|
4
3
|
|
|
5
|
-
module.exports =
|
|
4
|
+
module.exports = (version) => {
|
|
5
|
+
const ChatMessage = require('prismarine-chat')(version)
|
|
6
|
+
const Item = require('prismarine-item')(version)
|
|
7
|
+
const mcData = require('minecraft-data')(version)
|
|
8
|
+
class Entity extends EventEmitter {
|
|
9
|
+
constructor (id) {
|
|
10
|
+
super()
|
|
11
|
+
this.id = id
|
|
12
|
+
this.position = new Vec3(0, 0, 0)
|
|
13
|
+
this.velocity = new Vec3(0, 0, 0)
|
|
14
|
+
this.yaw = 0
|
|
15
|
+
this.pitch = 0
|
|
16
|
+
this.onGround = true
|
|
17
|
+
this.height = 0
|
|
18
|
+
this.width = 0
|
|
19
|
+
this.effects = {}
|
|
20
|
+
// 0 = held item, 1-4 = armor slot
|
|
21
|
+
this.equipment = new Array(5)
|
|
22
|
+
this.heldItem = this.equipment[0] // shortcut to equipment[0]
|
|
23
|
+
this.isValid = true
|
|
24
|
+
this.metadata = []
|
|
25
|
+
}
|
|
6
26
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
setEquipment (index, item) {
|
|
28
|
+
this.equipment[index] = item
|
|
29
|
+
this.heldItem = this.equipment[0]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getCustomName () {
|
|
33
|
+
const name = this.metadata[2]
|
|
34
|
+
if (name === undefined) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
return ChatMessage.fromNotch(name)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getDroppedItem () {
|
|
41
|
+
if (this.name !== 'item' && this.name !== 'Item' && this.name !== 'item_stack') {
|
|
42
|
+
return null // not a dropped item
|
|
43
|
+
}
|
|
44
|
+
return Item.fromNotch(this.metadata[mcData.supportFeature('metadataIxOfItem')])
|
|
45
|
+
}
|
|
46
|
+
}
|
|
26
47
|
|
|
27
|
-
Entity
|
|
28
|
-
this.equipment[index] = item
|
|
29
|
-
this.heldItem = this.equipment[0]
|
|
48
|
+
return Entity
|
|
30
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prismarine-entity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Represent a minecraft entity",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"url": "https://github.com/PrismarineJS/prismarine-entity.git"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"minecraft-data": "^3.0.0",
|
|
17
|
+
"prismarine-chat": "^1.4.1",
|
|
18
|
+
"prismarine-item": "^1.11.2",
|
|
16
19
|
"vec3": "^0.1.4"
|
|
17
20
|
},
|
|
18
21
|
"keywords": [
|
|
@@ -26,8 +29,8 @@
|
|
|
26
29
|
"url": "https://github.com/PrismarineJS/prismarine-entity/issues"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"prismarine-
|
|
32
|
+
"@types/node": "^17.0.4",
|
|
33
|
+
"prismarine-entity": "file:.",
|
|
31
34
|
"standard": "^16.0.1"
|
|
32
35
|
}
|
|
33
36
|
}
|