@vaitosoi/minejs 0.2.2 → 0.4.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.
Files changed (149) hide show
  1. package/README.md +1 -1
  2. package/assets/minecraft/26.2/packets.json +4758 -0
  3. package/dist/base/buffer.d.ts +2 -0
  4. package/dist/base/buffer.d.ts.map +1 -0
  5. package/dist/base/buffer.js +12 -0
  6. package/dist/base/buffer.js.map +1 -0
  7. package/dist/base/error.d.ts +59 -3
  8. package/dist/base/error.d.ts.map +1 -1
  9. package/dist/base/error.js +123 -7
  10. package/dist/base/error.js.map +1 -1
  11. package/dist/base/http.d.ts +2 -0
  12. package/dist/base/http.d.ts.map +1 -0
  13. package/dist/base/http.js +14 -0
  14. package/dist/base/http.js.map +1 -0
  15. package/dist/base/math.d.ts +22 -1
  16. package/dist/base/math.d.ts.map +1 -1
  17. package/dist/base/math.js +49 -2
  18. package/dist/base/math.js.map +1 -1
  19. package/dist/base/typing.d.ts +7 -1
  20. package/dist/base/typing.d.ts.map +1 -1
  21. package/dist/client/auth.d.ts +41 -7
  22. package/dist/client/auth.d.ts.map +1 -1
  23. package/dist/client/auth.js +96 -39
  24. package/dist/client/auth.js.map +1 -1
  25. package/dist/client/client.d.ts +73 -17
  26. package/dist/client/client.d.ts.map +1 -1
  27. package/dist/client/client.js +111 -44
  28. package/dist/client/client.js.map +1 -1
  29. package/dist/client/tcp.d.ts +17 -206
  30. package/dist/client/tcp.d.ts.map +1 -1
  31. package/dist/client/tcp.js +37 -715
  32. package/dist/client/tcp.js.map +1 -1
  33. package/dist/index.d.ts +12 -12
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +12 -12
  36. package/dist/index.js.map +1 -1
  37. package/dist/message/link.d.ts +10 -0
  38. package/dist/message/link.d.ts.map +1 -0
  39. package/dist/message/link.js +22 -0
  40. package/dist/message/link.js.map +1 -0
  41. package/dist/message/sigCache.d.ts +13 -0
  42. package/dist/message/sigCache.d.ts.map +1 -0
  43. package/dist/message/sigCache.js +26 -0
  44. package/dist/message/sigCache.js.map +1 -0
  45. package/dist/{translator → packet}/decoder.d.ts +14 -1
  46. package/dist/packet/decoder.d.ts.map +1 -0
  47. package/dist/{translator → packet}/decoder.js +24 -3
  48. package/dist/packet/decoder.js.map +1 -0
  49. package/dist/packet/dispatcher.d.ts +53 -0
  50. package/dist/packet/dispatcher.d.ts.map +1 -0
  51. package/dist/packet/dispatcher.js +738 -0
  52. package/dist/packet/dispatcher.js.map +1 -0
  53. package/dist/{translator → packet}/encoder.d.ts +4 -3
  54. package/dist/packet/encoder.d.ts.map +1 -0
  55. package/dist/{translator → packet}/encoder.js +18 -7
  56. package/dist/packet/encoder.js.map +1 -0
  57. package/dist/packet/static.d.ts.map +1 -0
  58. package/dist/packet/static.js.map +1 -0
  59. package/dist/{base → physics}/aabb.d.ts +2 -2
  60. package/dist/physics/aabb.d.ts.map +1 -0
  61. package/dist/{base → physics}/aabb.js +5 -5
  62. package/dist/physics/aabb.js.map +1 -0
  63. package/dist/physics/direction.d.ts.map +1 -0
  64. package/dist/physics/direction.js.map +1 -0
  65. package/dist/{base → physics}/player.d.ts +25 -28
  66. package/dist/physics/player.d.ts.map +1 -0
  67. package/dist/{base → physics}/player.js +81 -68
  68. package/dist/physics/player.js.map +1 -0
  69. package/dist/version/codec.d.ts +18 -0
  70. package/dist/version/codec.d.ts.map +1 -0
  71. package/dist/version/codec.js +235 -0
  72. package/dist/version/codec.js.map +1 -0
  73. package/dist/version/registry.d.ts +236 -0
  74. package/dist/version/registry.d.ts.map +1 -0
  75. package/dist/version/registry.js +284 -0
  76. package/dist/version/registry.js.map +1 -0
  77. package/dist/{base → world}/block.d.ts +5 -5
  78. package/dist/world/block.d.ts.map +1 -0
  79. package/dist/{base → world}/block.js +13 -13
  80. package/dist/world/block.js.map +1 -0
  81. package/dist/{base → world}/entity.d.ts +4 -4
  82. package/dist/world/entity.d.ts.map +1 -0
  83. package/dist/{base → world}/entity.js +6 -6
  84. package/dist/world/entity.js.map +1 -0
  85. package/dist/world/state.d.ts +175 -0
  86. package/dist/world/state.d.ts.map +1 -0
  87. package/dist/world/state.js +163 -0
  88. package/dist/world/state.js.map +1 -0
  89. package/dist/world/tick.d.ts.map +1 -0
  90. package/dist/world/tick.js.map +1 -0
  91. package/package.json +7 -2
  92. package/src/base/buffer.ts +12 -0
  93. package/src/base/error.ts +93 -4
  94. package/src/base/http.ts +10 -0
  95. package/src/base/math.ts +55 -3
  96. package/src/base/typing.ts +9 -1
  97. package/src/client/auth.ts +130 -52
  98. package/src/client/client.ts +182 -50
  99. package/src/client/tcp.ts +45 -967
  100. package/src/index.ts +12 -12
  101. package/src/message/link.ts +17 -0
  102. package/src/message/sigCache.ts +25 -0
  103. package/src/{translator → packet}/decoder.ts +24 -3
  104. package/src/packet/dispatcher.ts +919 -0
  105. package/src/{translator → packet}/encoder.ts +20 -9
  106. package/src/{base → physics}/aabb.ts +5 -5
  107. package/src/{base → physics}/player.ts +106 -65
  108. package/src/version/codec.ts +248 -0
  109. package/src/version/registry.ts +328 -0
  110. package/src/{base → world}/block.ts +12 -11
  111. package/src/{base → world}/entity.ts +5 -5
  112. package/src/world/state.ts +300 -0
  113. package/test/adapter/index.ts +14 -0
  114. package/test/client/index.ts +28 -21
  115. package/test/json/index.ts +3 -0
  116. package/dist/base/aabb.d.ts.map +0 -1
  117. package/dist/base/aabb.js.map +0 -1
  118. package/dist/base/block.d.ts.map +0 -1
  119. package/dist/base/block.js.map +0 -1
  120. package/dist/base/direction.d.ts.map +0 -1
  121. package/dist/base/direction.js.map +0 -1
  122. package/dist/base/entity.d.ts.map +0 -1
  123. package/dist/base/entity.js.map +0 -1
  124. package/dist/base/player.d.ts.map +0 -1
  125. package/dist/base/player.js.map +0 -1
  126. package/dist/base/registry.d.ts +0 -50
  127. package/dist/base/registry.d.ts.map +0 -1
  128. package/dist/base/registry.js +0 -89
  129. package/dist/base/registry.js.map +0 -1
  130. package/dist/base/tick.d.ts.map +0 -1
  131. package/dist/base/tick.js.map +0 -1
  132. package/dist/translator/decoder.d.ts.map +0 -1
  133. package/dist/translator/decoder.js.map +0 -1
  134. package/dist/translator/encoder.d.ts.map +0 -1
  135. package/dist/translator/encoder.js.map +0 -1
  136. package/dist/translator/static.d.ts.map +0 -1
  137. package/dist/translator/static.js.map +0 -1
  138. package/src/base/registry.ts +0 -87
  139. /package/assets/minecraft/{blocks.json → 26.2/blocks.json} +0 -0
  140. /package/assets/minecraft/{entities.json → 26.2/entities.json} +0 -0
  141. /package/dist/{translator → packet}/static.d.ts +0 -0
  142. /package/dist/{translator → packet}/static.js +0 -0
  143. /package/dist/{base → physics}/direction.d.ts +0 -0
  144. /package/dist/{base → physics}/direction.js +0 -0
  145. /package/dist/{base → world}/tick.d.ts +0 -0
  146. /package/dist/{base → world}/tick.js +0 -0
  147. /package/src/{translator → packet}/static.ts +0 -0
  148. /package/src/{base → physics}/direction.ts +0 -0
  149. /package/src/{base → world}/tick.ts +0 -0
@@ -1,8 +1,17 @@
1
- import { Vec3 } from "../base/direction";
1
+ import { Vec3 } from "../physics/direction";
2
2
  import { CONTINUATION_FLAG, CONTINUE_BIT, isFixedSizeTag, isTag, MAX_QUANTIZED_VALUE, SCALE_BITS, SEGMENT_BITS } from "./static";
3
3
  import { InvalidValue, NumberTooBig, UnexpectedValue } from "../base/error";
4
4
  import { FixedSizeTag, Tag } from "./static";
5
5
 
6
+ export function makeMovementFlag(onGround: boolean, pushingWall: boolean) {
7
+ let flag = 0;
8
+ if (onGround)
9
+ flag &= 1;
10
+ if (pushingWall)
11
+ flag |= 1 << 2;
12
+ return flag;
13
+ }
14
+
6
15
  export class BinaryEncoder {
7
16
  private buffer = Buffer.alloc(0);
8
17
 
@@ -14,8 +23,9 @@ export class BinaryEncoder {
14
23
  this.buffer = Buffer.alloc(0);
15
24
  }
16
25
 
17
- public concat(buf: Buffer) {
26
+ public writeRaw(buf: Buffer) {
18
27
  this.buffer = Buffer.concat([this.buffer, buf]);
28
+ return this;
19
29
  }
20
30
 
21
31
 
@@ -27,7 +37,7 @@ export class BinaryEncoder {
27
37
  public write(size: number, val: any, writeFunc: (buf: Buffer) => ((val: any) => void)) {
28
38
  const buf = Buffer.alloc(size);
29
39
  writeFunc(buf).bind(buf)(val);
30
- this.concat(buf);
40
+ this.writeRaw(buf);
31
41
  return this;
32
42
  }
33
43
 
@@ -129,7 +139,7 @@ export class BinaryEncoder {
129
139
  */
130
140
  public writeString(str: string) {
131
141
  this.writeVarInt(str.length);
132
- this.concat(Buffer.from(str));
142
+ this.writeRaw(Buffer.from(str));
133
143
  return this;
134
144
  }
135
145
 
@@ -171,7 +181,7 @@ export class BinaryEncoder {
171
181
  else return val;
172
182
  });
173
183
  this.writeVarInt(length);
174
- this.concat(Buffer.concat(array));
184
+ this.writeRaw(Buffer.concat(array));
175
185
  return this;
176
186
  }
177
187
 
@@ -187,7 +197,7 @@ export class BinaryEncoder {
187
197
  public writeRawPrefixedArray(data: Buffer, size: number) {
188
198
  const length = Math.ceil(data.length / size);
189
199
  this.writeVarInt(length);
190
- this.concat(data);
200
+ this.writeRaw(data);
191
201
  return this;
192
202
  }
193
203
 
@@ -224,8 +234,9 @@ export class BinaryEncoder {
224
234
  this.writeVarInt(Number(scaleFactor >> 2n));
225
235
  }
226
236
  }
227
- }
228
237
 
238
+ return this;
239
+ }
229
240
  }
230
241
 
231
242
  type CompoundField = any | {
@@ -306,7 +317,7 @@ export class NBTEncoder extends BinaryEncoder {
306
317
  public writeString(str: string) {
307
318
  this.writeUShort(str.length);
308
319
  if (str.length === 0) return this;
309
- this.concat(Buffer.from(str));
320
+ this.writeRaw(Buffer.from(str));
310
321
  return this;
311
322
  }
312
323
 
@@ -322,7 +333,7 @@ export class NBTEncoder extends BinaryEncoder {
322
333
  for (const item of arr)
323
334
  this.writeString(item);
324
335
  else
325
- this.concat(Buffer.from(arr));
336
+ this.writeRaw(Buffer.from(arr));
326
337
  return this;
327
338
  }
328
339
 
@@ -1,9 +1,9 @@
1
- import { BitSet } from "./bitset";
1
+ import { BitSet } from "../base/bitset";
2
2
  import { Axis, AxisCycle, BaseAxis, BaseVec3, Direction, Vec3 } from "./direction";
3
- import { RegistryItemNotFound } from "./error";
4
- import { EntityRegistry } from "./registry";
5
- import { Epsilon, lowerBoundBinarySearch } from "./math";
6
- import { BlockHitResult } from "./block";
3
+ import { RegistryItemNotFound } from "../base/error";
4
+ import { EntityRegistry } from "../version/registry";
5
+ import { Epsilon, lowerBoundBinarySearch } from "../base/math";
6
+ import { BlockHitResult } from "../world/block";
7
7
 
8
8
  export interface BaseAABB {
9
9
  minX: number;
@@ -1,24 +1,33 @@
1
- import { EntitiesManager } from "./entity";
1
+ import { EntitiesManager } from "../world/entity";
2
2
  import { Angle, Axis, BaseAxis, BaseVec3, Vec3 } from "./direction";
3
3
  import { AABB, Shapes, VoxelShape } from "./aabb";
4
- import { BlockGetter, BlockManager, BlockState } from "./block";
5
- import { clamp, Epsilon, equal, lerp } from "./math";
6
- import { TCPClient } from "../client/tcp";
7
- import { ClientNotReady } from "./error";
4
+ import { BlockGetter, BlockManager, BlockState } from "../world/block";
5
+ import { clamp, Epsilon, equal, lerp } from "../base/math";
6
+ import { ClientNotReady, NotImplemented } from "../base/error";
8
7
  import { LevelHeightLimit } from "../client/static";
8
+ import { SharedState } from "../world/state";
9
+ import { TypedEmmiter } from "../base/event";
10
+ import { ClientEvents } from "../client/client";
11
+ import { makeMovementFlag } from "../packet/encoder";
9
12
 
10
- export enum MoveDirection {
13
+ export enum Input {
11
14
  Forward = "W",
12
15
  Backward = "S",
13
16
  Left = "A",
14
17
  Right = "D",
18
+ Crouching = "shift",
19
+ Jump = "space",
20
+ Sprint = "cttl"
15
21
  }
16
22
 
17
- const VectorMovement: Record<MoveDirection, Vec3> = {
18
- [MoveDirection.Forward]: new Vec3(0, 0, 1),
19
- [MoveDirection.Backward]: new Vec3(0, 0, -1),
20
- [MoveDirection.Left]: new Vec3(1, 0, 0),
21
- [MoveDirection.Right]: new Vec3(-1, 0, 0),
23
+ const VectorMovement: Record<Input, Vec3> = {
24
+ [Input.Forward]: new Vec3(0, 0, 1),
25
+ [Input.Backward]: new Vec3(0, 0, -1),
26
+ [Input.Left]: new Vec3(1, 0, 0),
27
+ [Input.Right]: new Vec3(-1, 0, 0),
28
+ [Input.Crouching]: Vec3.Zero,
29
+ [Input.Jump]: Vec3.Zero,
30
+ [Input.Sprint]: Vec3.Zero,
22
31
  };
23
32
 
24
33
  /**
@@ -39,12 +48,11 @@ export class Player {
39
48
 
40
49
  // Moving state
41
50
  // TODO: need is sprinting
42
- private heldInputs: Set<MoveDirection> = new Set();
43
- private isCrouncing: boolean = false;
44
- private isJumping: boolean = false;
51
+ private heldInputs: Set<Input> = new Set();
45
52
  private lastPos: BaseVec3 | null = null;
46
53
  private lastAngle: Angle | null = null;
47
54
  private positionReminder: number = 0;
55
+ private noJumpDelay: number = 0;
48
56
 
49
57
  // Collision
50
58
  private horizontalCollision: boolean = false;
@@ -54,18 +62,45 @@ export class Player {
54
62
  private lastOnGround: boolean = true;
55
63
 
56
64
  constructor(
65
+ private state: SharedState,
66
+ private on: TypedEmmiter<ClientEvents>["on"],
57
67
  private entities: EntitiesManager,
58
68
  private blocks: BlockManager,
59
- private tcp: TCPClient
60
69
  ) {
61
- this.tcp.on("playerPosition", () => {
70
+ this.on("playerPosition", () => {
62
71
  this.onGround = true;
63
72
  this.horizontalCollision = false;
64
73
  this.fallDistance = 0;
65
- this.deltaMovement = new Vec3(this.tcp.player!.velocity);
74
+ this.deltaMovement = new Vec3(this.state.player!.velocity);
75
+ this.setInitialVal();
66
76
  });
67
77
  }
68
78
 
79
+
80
+ public sendPlayerPos: (
81
+ position: BaseVec3,
82
+ onGround: boolean,
83
+ horizontalCollision: boolean
84
+ ) => void = () => { throw new NotImplemented(); };
85
+
86
+ public sendPlayerPosRot: (
87
+ position: BaseVec3,
88
+ angle: Angle,
89
+ onGround: boolean,
90
+ horizontalCollision: boolean
91
+ ) => void = () => { throw new NotImplemented(); };
92
+
93
+ public sendPlayerRot: (
94
+ angle: Angle,
95
+ onGround: boolean,
96
+ horizontalCollision: boolean
97
+ ) => void = () => { throw new NotImplemented(); };
98
+
99
+ public sendPlayerStatus: (
100
+ onGround: boolean,
101
+ horizontalCollision: boolean
102
+ ) => void = () => { throw new NotImplemented(); };
103
+
69
104
  /**
70
105
  * Set initial value
71
106
  */
@@ -81,8 +116,6 @@ export class Player {
81
116
  this.deltaMovement = Vec3.Zero;
82
117
  this.supportBlockPos = null;
83
118
  this.heldInputs = new Set();
84
- this.isCrouncing = false;
85
- this.isJumping = false;
86
119
  this.lastPos = null;
87
120
  this.lastAngle = null;
88
121
  this.positionReminder = 0;
@@ -97,31 +130,19 @@ export class Player {
97
130
  /**
98
131
  * Press and hold a key
99
132
  */
100
- public input(input: MoveDirection) { this.heldInputs.add(input); }
133
+ public input(input: Input) { this.heldInputs.add(input); }
101
134
  /**
102
135
  * Release a key
103
136
  */
104
- public releaseInput(input: MoveDirection) { this.heldInputs.delete(input); }
137
+ public releaseInput(input: Input) { this.heldInputs.delete(input); }
105
138
  /**
106
139
  * Release all key
107
140
  */
108
141
  public releaseAllInputs() { this.heldInputs.clear(); }
109
- /**
110
- * Press and hold shift. Do nothing for now
111
- */
112
- public pressShift() { this.isCrouncing = true; }
113
- /**
114
- * Release shift
115
- */
116
- public releaseShift() { this.isCrouncing = false; }
117
- /**
118
- * Press and hold space. Do nothing for now
119
- */
120
- public pressSpace() { this.isJumping = true; }
121
- /**
122
- * Release shift
123
- */
124
- public releaseSpace() { this.isJumping = false; }
142
+
143
+ private get isCrouncing() { return this.heldInputs.has(Input.Crouching); };
144
+ private get isJumping() { return this.heldInputs.has(Input.Jump); };
145
+ private get isSprinting() { return this.heldInputs.has(Input.Sprint); }
125
146
 
126
147
  private getInputVector(): Vec3 {
127
148
  let vec = Vec3.Zero;
@@ -132,20 +153,27 @@ export class Player {
132
153
 
133
154
  /* Getting helper, from TCP client */
134
155
  private getPos() {
135
- this.tcp.checkReady();
136
- return new Vec3(this.tcp.player!.position);
156
+ this.state.checkReady();
157
+ return new Vec3(this.state.player!.position);
137
158
  }
138
159
  private setPos(pos: Vec3) {
139
- this.tcp.checkReady();
140
- this.tcp.player!.position = pos.copyBase();
160
+ this.state.checkReady();
161
+ this.state.enqueueMutation((state) => state.player!.position = pos.copyBase());
141
162
  }
142
163
  private getAngle() {
143
- this.tcp.checkReady();
144
- return this.tcp.player!.angle;
164
+ this.state.checkReady();
165
+ return this.state.player!.angle;
166
+ }
167
+ public setAngle(yaw: number, pitch: number) {
168
+ this.state.checkReady();
169
+ this.state.enqueueMutation((state) => state.player!.angle = {
170
+ yaw: yaw % 360,
171
+ pitch: pitch % 360
172
+ });
145
173
  }
146
174
  private getDimension() {
147
- this.tcp.checkReady();
148
- return this.tcp.player!.dimension;
175
+ this.state.checkReady();
176
+ return this.state.player!.dimension;
149
177
  }
150
178
 
151
179
  private setDeltaMovement(x: number, y: number, z: number): void;
@@ -217,7 +245,7 @@ export class Player {
217
245
  * Ticking
218
246
  */
219
247
  public tick() {
220
- if (!this.tcp.isReady()) return;
248
+ if (!this.state.isReady()) return;
221
249
  if (!this.lastPos || !this.lastAngle) throw new ClientNotReady();
222
250
 
223
251
  // console.log("tick");
@@ -226,7 +254,7 @@ export class Player {
226
254
  this.aiStep();
227
255
  const { x, y, z } = this.getPos(),
228
256
  { x: xLast, y: yLast, z: zLast } = this.lastPos,
229
- { yaw: xRot, pitch: yRot } = this.getAngle(),
257
+ { yaw, yaw: xRot, pitch, pitch: yRot } = this.getAngle(),
230
258
  { yaw: xRotLast, pitch: yRotLast } = this.lastAngle;
231
259
  const deltaX = x - xLast,
232
260
  deltaY = y - yLast,
@@ -237,16 +265,16 @@ export class Player {
237
265
  const move = new Vec3(deltaX, deltaY, deltaZ).lengthSqr() > (2e-4 * 2e-4) || this.positionReminder > 20,
238
266
  rot = deltaXRot !== 0 || deltaYRot !== 0;
239
267
  if (move && rot)
240
- this.tcp.sendPlayerPosRot(this.getPos(), this.getAngle(), this.onGround, this.horizontalCollision);
268
+ this.sendPlayerPosRot(this.getPos(), this.getAngle(), this.onGround, this.horizontalCollision);
241
269
  else if (move)
242
- this.tcp.sendPlayerPos(this.getPos(), this.onGround, this.horizontalCollision);
270
+ this.sendPlayerPos(this.getPos(), this.onGround, this.horizontalCollision);
243
271
  else if (rot)
244
- this.tcp.sendPlayerRot(this.getAngle(), this.onGround, this.horizontalCollision);
272
+ this.sendPlayerRot(this.getAngle(), this.onGround, this.horizontalCollision);
245
273
  else if (
246
274
  this.onGround !== this.lastOnGround ||
247
275
  this.horizontalCollision !== this.lastHorizontalCollision
248
276
  )
249
- this.tcp.sendPlayerStatus(this.onGround, this.horizontalCollision);
277
+ this.sendPlayerStatus(this.onGround, this.horizontalCollision);
250
278
 
251
279
  if (move) {
252
280
  this.lastPos = this.getPos();
@@ -260,6 +288,10 @@ export class Player {
260
288
  }
261
289
 
262
290
  private aiStep() {
291
+ if (this.noJumpDelay > 0) {
292
+ this.noJumpDelay--;
293
+ }
294
+
263
295
  // eslint-disable-next-line prefer-const
264
296
  let { x, y, z } = this.deltaMovement;
265
297
  if (this.deltaMovement.horizontalDistanceSqr() < 9e-6) {
@@ -268,13 +300,23 @@ export class Player {
268
300
  }
269
301
  this.setDeltaMovement(x, y, z);
270
302
 
271
- if (this.isJumping) {
303
+ if (this.isJumping && this.noJumpDelay === 0) {
272
304
  const jumpPower = this.getJumpFactor();
273
305
 
274
306
  if (jumpPower > 1e-5) {
275
307
  const { x: dx, y: dy, z: dz } = this.deltaMovement;
276
308
  this.setDeltaMovement(dx, Math.max(dy, jumpPower), dz);
309
+ if (this.isSprinting) {
310
+ const yawInRad = this.getAngle().yaw * (Math.PI / 180.0);
311
+ this.setDeltaMovement(
312
+ this.deltaMovement.add(
313
+ new Vec3(-Math.sin(yawInRad) * 0.2, 0.0, Math.cos(yawInRad) * 0.2)
314
+ )
315
+ );
316
+ }
277
317
  }
318
+
319
+ this.noJumpDelay = 15; // Original value to 10
278
320
  }
279
321
  // TODO: Handle in fluid
280
322
 
@@ -296,14 +338,15 @@ export class Player {
296
338
  const { x, y, z } = this.getPos();
297
339
  const inBlock = this.blocks.at(x, y, z)!;
298
340
  const belowBlock = this.blocks.at(x, y - 0.5, z)!;
299
- return inBlock.owner.getJumpFactor() === 1 ? belowBlock.owner.getJumpFactor() : inBlock.owner.getJumpFactor();
341
+ // 0.42F is the default jump strength, which will apply for player here
342
+ return (inBlock.owner.getJumpFactor() === 1 ? belowBlock.owner.getJumpFactor() : inBlock.owner.getJumpFactor()) * 0.42;
300
343
  }
301
344
 
302
345
  /*
303
346
  * Invoking flow
304
347
  *
305
348
  * |-> travelInAir ---|
306
- * travel -|-> travelInFluid -|--> move -> colision
349
+ * travel -|-> travelInFluid -+--> move -> colision
307
350
  * |-> flying? -------|
308
351
  */
309
352
 
@@ -318,8 +361,8 @@ export class Player {
318
361
  private travelInAir(input: Vec3) {
319
362
  const posBelow = this.getOnPos(0.50001);
320
363
  if (!this.blocks.hasChunkAt(posBelow))
321
- return; // // console.log(`no chunk at ${Math.floor(posBelow.x / 16)} ${Math.floor(posBelow.y / 16)} ${Math.floor(posBelow.z / 16)}`);
322
- // // console.log('posBelow', posBelow, 'block', this.blocks.at(posBelow)?.owner.getType());
364
+ return; // console.log(`no chunk at ${Math.floor(posBelow.x / 16)} ${Math.floor(posBelow.y / 16)} ${Math.floor(posBelow.z / 16)}`);
365
+ // console.log('posBelow', posBelow, 'block', this.blocks.at(posBelow)?.owner.getType());
323
366
  const blockFriction = this.onGround ? this.blocks.at(posBelow)!.owner.getFriction() : 1;
324
367
  const movement = this.handleFrictionAndCalculateMovement(input, blockFriction);
325
368
  let movementY = movement.y;
@@ -373,7 +416,7 @@ export class Player {
373
416
  private getSpeed() {
374
417
  // return the base for now
375
418
  // TODO: Handle other cases: sprinting, speed-enchanted gear and potion
376
- return 0.1;
419
+ return this.isSprinting ? 0.13 : 0.1;
377
420
  }
378
421
 
379
422
  private moveRelative(input: Vec3, speed: number) {
@@ -417,14 +460,12 @@ export class Player {
417
460
  to: checkTo,
418
461
  getBlockState: (position) => this.blocks.at(position)!.shape
419
462
  });
420
- if (hitResult?.miss !== false) {
463
+ if (hitResult?.miss !== false)
421
464
  this.fallDistance = 0;
422
- }
423
465
  }
424
466
 
425
467
  const pos = this.getPos();
426
468
  const newPosition = pos.add(movement);
427
- // addMovementThisTick(new Movement(pos, newPosition, delta2));
428
469
  this.setPos(newPosition);
429
470
  }
430
471
 
@@ -503,7 +544,7 @@ export class Player {
503
544
 
504
545
  private collide(movement: Vec3): Vec3 {
505
546
  // Get player's bounding box
506
- const { x: playerX, y: playerY, z: playerZ } = this.tcp.player!.position;
547
+ const { x: playerX, y: playerY, z: playerZ } = this.state.player!.position;
507
548
  const playerBB = AABB.fromEntityType("minecraft:player")
508
549
  .move(playerX, playerY, playerZ);
509
550
  const expandedBB = playerBB.expandTowards(movement);
@@ -515,7 +556,7 @@ export class Player {
515
556
  // });
516
557
 
517
558
  // Collect all colliders
518
- const colliders = this.collectColliders(expandedBB, [this.tcp.player!.entityId]);
559
+ const colliders = this.collectColliders(expandedBB, [this.state.player!.entityId]);
519
560
  // // console.log('nonEmptyColliders', colliders.filter(c => !c.isEmpty()).length);
520
561
 
521
562
  // Get the farest distance can move
@@ -535,7 +576,7 @@ export class Player {
535
576
  if (!onGroundAfterCollision)
536
577
  stepUpAABB = stepUpAABB.expandTowards(0, -1e-5, 0);
537
578
 
538
- const colliders = this.collectColliders(stepUpAABB, [this.tcp.player!.entityId]);
579
+ const colliders = this.collectColliders(stepUpAABB, [this.state.player!.entityId]);
539
580
  const stepHeightToSkip = movementStep.y;
540
581
  const stepUpCandidateSet: Set<number> = new Set();
541
582
  for (const collider of colliders) {
@@ -584,8 +625,8 @@ export class Player {
584
625
  }
585
626
  }
586
627
 
587
- // // console.log('expandedBB', expandedBB, 'colliderCount', colliders.length);
588
- // // console.log('movement.y', movement.y, 'movementStep.y', movementStep.y);
628
+ // console.log('expandedBB', expandedBB, 'colliderCount', colliders.length);
629
+ // console.log('movement.y', movement.y, 'movementStep.y', movementStep.y);
589
630
 
590
631
  return movementStep;
591
632
  }