prismarine-entity 1.2.0 → 2.0.0

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 CHANGED
@@ -7,11 +7,10 @@ Represent a minecraft entity
7
7
  ## Usage
8
8
 
9
9
  ```js
10
- var Entity=require("prismarine-entity");
10
+ const Entity = require("prismarine-entity")
11
11
 
12
- var entity=new Entity(0);
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
package/example.js CHANGED
@@ -1,4 +1,4 @@
1
- const Entity = require('./')
1
+ const Entity = require('prismarine-entity')('1.8.9')
2
2
 
3
3
  const entity = new Entity(0)
4
4
 
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 {
@@ -42,6 +43,7 @@ declare module 'prismarine-entity' {
42
43
  player?: object;
43
44
  effects: Effect[];
44
45
  setEquipment(index: number, item: Item): void;
46
+ getCustomName(): ChatMessage | null;
45
47
  }
46
48
 
47
49
  export type EntityType = 'player' | 'mob' | 'object' | 'global' | 'orb' | 'other';
package/index.js CHANGED
@@ -1,30 +1,40 @@
1
1
  const Vec3 = require('vec3').Vec3
2
- const util = require('util')
3
2
  const EventEmitter = require('events').EventEmitter
4
3
 
5
- module.exports = Entity
4
+ module.exports = (version) => {
5
+ const ChatMessage = require('prismarine-chat')(version)
6
+ class Entity extends EventEmitter {
7
+ constructor (id) {
8
+ super()
9
+ this.id = id
10
+ this.position = new Vec3(0, 0, 0)
11
+ this.velocity = new Vec3(0, 0, 0)
12
+ this.yaw = 0
13
+ this.pitch = 0
14
+ this.onGround = true
15
+ this.height = 0
16
+ this.width = 0
17
+ this.effects = {}
18
+ // 0 = held item, 1-4 = armor slot
19
+ this.equipment = new Array(5)
20
+ this.heldItem = this.equipment[0] // shortcut to equipment[0]
21
+ this.isValid = true
22
+ this.metadata = []
23
+ }
6
24
 
7
- function Entity (id) {
8
- EventEmitter.call(this)
9
- this.id = id
10
- this.type = null
11
- this.position = new Vec3(0, 0, 0)
12
- this.velocity = new Vec3(0, 0, 0)
13
- this.yaw = 0
14
- this.pitch = 0
15
- this.onGround = true
16
- this.height = 0
17
- this.width = 0
18
- this.effects = {}
19
- // 0 = held item, 1-4 = armor slot
20
- this.equipment = new Array(5)
21
- this.heldItem = this.equipment[0] // shortcut to equipment[0]
22
- this.isValid = true
23
- this.metadata = []
24
- }
25
- util.inherits(Entity, EventEmitter)
25
+ setEquipment (index, item) {
26
+ this.equipment[index] = item
27
+ this.heldItem = this.equipment[0]
28
+ }
29
+
30
+ getCustomName () {
31
+ const name = this.metadata[2]
32
+ if (name === undefined) {
33
+ return null
34
+ }
35
+ return ChatMessage.fromNotch(name)
36
+ }
37
+ }
26
38
 
27
- Entity.prototype.setEquipment = function (index, item) {
28
- this.equipment[index] = item
29
- this.heldItem = this.equipment[0]
39
+ return Entity
30
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prismarine-entity",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "Represent a minecraft entity",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -13,7 +13,8 @@
13
13
  "url": "https://github.com/PrismarineJS/prismarine-entity.git"
14
14
  },
15
15
  "dependencies": {
16
- "vec3": "^0.1.4"
16
+ "vec3": "^0.1.4",
17
+ "prismarine-chat": "^1.4.1"
17
18
  },
18
19
  "keywords": [
19
20
  "minecraft",
@@ -26,8 +27,9 @@
26
27
  "url": "https://github.com/PrismarineJS/prismarine-entity/issues"
27
28
  },
28
29
  "devDependencies": {
29
- "@types/node": "^15.0.1",
30
+ "@types/node": "^17.0.4",
30
31
  "prismarine-item": "^1.4.0",
31
- "standard": "^16.0.1"
32
+ "standard": "^16.0.1",
33
+ "prismarine-entity": "file:."
32
34
  }
33
35
  }