@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.
- package/README.md +1 -1
- package/assets/minecraft/26.2/packets.json +4758 -0
- package/dist/base/buffer.d.ts +2 -0
- package/dist/base/buffer.d.ts.map +1 -0
- package/dist/base/buffer.js +12 -0
- package/dist/base/buffer.js.map +1 -0
- package/dist/base/error.d.ts +59 -3
- package/dist/base/error.d.ts.map +1 -1
- package/dist/base/error.js +123 -7
- package/dist/base/error.js.map +1 -1
- package/dist/base/http.d.ts +2 -0
- package/dist/base/http.d.ts.map +1 -0
- package/dist/base/http.js +14 -0
- package/dist/base/http.js.map +1 -0
- package/dist/base/math.d.ts +22 -1
- package/dist/base/math.d.ts.map +1 -1
- package/dist/base/math.js +49 -2
- package/dist/base/math.js.map +1 -1
- package/dist/base/typing.d.ts +7 -1
- package/dist/base/typing.d.ts.map +1 -1
- package/dist/client/auth.d.ts +41 -7
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/auth.js +96 -39
- package/dist/client/auth.js.map +1 -1
- package/dist/client/client.d.ts +73 -17
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +111 -44
- package/dist/client/client.js.map +1 -1
- package/dist/client/tcp.d.ts +17 -206
- package/dist/client/tcp.d.ts.map +1 -1
- package/dist/client/tcp.js +37 -715
- package/dist/client/tcp.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/message/link.d.ts +10 -0
- package/dist/message/link.d.ts.map +1 -0
- package/dist/message/link.js +22 -0
- package/dist/message/link.js.map +1 -0
- package/dist/message/sigCache.d.ts +13 -0
- package/dist/message/sigCache.d.ts.map +1 -0
- package/dist/message/sigCache.js +26 -0
- package/dist/message/sigCache.js.map +1 -0
- package/dist/{translator → packet}/decoder.d.ts +14 -1
- package/dist/packet/decoder.d.ts.map +1 -0
- package/dist/{translator → packet}/decoder.js +24 -3
- package/dist/packet/decoder.js.map +1 -0
- package/dist/packet/dispatcher.d.ts +53 -0
- package/dist/packet/dispatcher.d.ts.map +1 -0
- package/dist/packet/dispatcher.js +738 -0
- package/dist/packet/dispatcher.js.map +1 -0
- package/dist/{translator → packet}/encoder.d.ts +4 -3
- package/dist/packet/encoder.d.ts.map +1 -0
- package/dist/{translator → packet}/encoder.js +18 -7
- package/dist/packet/encoder.js.map +1 -0
- package/dist/packet/static.d.ts.map +1 -0
- package/dist/packet/static.js.map +1 -0
- package/dist/{base → physics}/aabb.d.ts +2 -2
- package/dist/physics/aabb.d.ts.map +1 -0
- package/dist/{base → physics}/aabb.js +5 -5
- package/dist/physics/aabb.js.map +1 -0
- package/dist/physics/direction.d.ts.map +1 -0
- package/dist/physics/direction.js.map +1 -0
- package/dist/{base → physics}/player.d.ts +25 -28
- package/dist/physics/player.d.ts.map +1 -0
- package/dist/{base → physics}/player.js +81 -68
- package/dist/physics/player.js.map +1 -0
- package/dist/version/codec.d.ts +18 -0
- package/dist/version/codec.d.ts.map +1 -0
- package/dist/version/codec.js +235 -0
- package/dist/version/codec.js.map +1 -0
- package/dist/version/registry.d.ts +236 -0
- package/dist/version/registry.d.ts.map +1 -0
- package/dist/version/registry.js +284 -0
- package/dist/version/registry.js.map +1 -0
- package/dist/{base → world}/block.d.ts +5 -5
- package/dist/world/block.d.ts.map +1 -0
- package/dist/{base → world}/block.js +13 -13
- package/dist/world/block.js.map +1 -0
- package/dist/{base → world}/entity.d.ts +4 -4
- package/dist/world/entity.d.ts.map +1 -0
- package/dist/{base → world}/entity.js +6 -6
- package/dist/world/entity.js.map +1 -0
- package/dist/world/state.d.ts +175 -0
- package/dist/world/state.d.ts.map +1 -0
- package/dist/world/state.js +163 -0
- package/dist/world/state.js.map +1 -0
- package/dist/world/tick.d.ts.map +1 -0
- package/dist/world/tick.js.map +1 -0
- package/package.json +7 -2
- package/src/base/buffer.ts +12 -0
- package/src/base/error.ts +93 -4
- package/src/base/http.ts +10 -0
- package/src/base/math.ts +55 -3
- package/src/base/typing.ts +9 -1
- package/src/client/auth.ts +130 -52
- package/src/client/client.ts +182 -50
- package/src/client/tcp.ts +45 -967
- package/src/index.ts +12 -12
- package/src/message/link.ts +17 -0
- package/src/message/sigCache.ts +25 -0
- package/src/{translator → packet}/decoder.ts +24 -3
- package/src/packet/dispatcher.ts +919 -0
- package/src/{translator → packet}/encoder.ts +20 -9
- package/src/{base → physics}/aabb.ts +5 -5
- package/src/{base → physics}/player.ts +106 -65
- package/src/version/codec.ts +248 -0
- package/src/version/registry.ts +328 -0
- package/src/{base → world}/block.ts +12 -11
- package/src/{base → world}/entity.ts +5 -5
- package/src/world/state.ts +300 -0
- package/test/adapter/index.ts +14 -0
- package/test/client/index.ts +28 -21
- package/test/json/index.ts +3 -0
- package/dist/base/aabb.d.ts.map +0 -1
- package/dist/base/aabb.js.map +0 -1
- package/dist/base/block.d.ts.map +0 -1
- package/dist/base/block.js.map +0 -1
- package/dist/base/direction.d.ts.map +0 -1
- package/dist/base/direction.js.map +0 -1
- package/dist/base/entity.d.ts.map +0 -1
- package/dist/base/entity.js.map +0 -1
- package/dist/base/player.d.ts.map +0 -1
- package/dist/base/player.js.map +0 -1
- package/dist/base/registry.d.ts +0 -50
- package/dist/base/registry.d.ts.map +0 -1
- package/dist/base/registry.js +0 -89
- package/dist/base/registry.js.map +0 -1
- package/dist/base/tick.d.ts.map +0 -1
- package/dist/base/tick.js.map +0 -1
- package/dist/translator/decoder.d.ts.map +0 -1
- package/dist/translator/decoder.js.map +0 -1
- package/dist/translator/encoder.d.ts.map +0 -1
- package/dist/translator/encoder.js.map +0 -1
- package/dist/translator/static.d.ts.map +0 -1
- package/dist/translator/static.js.map +0 -1
- package/src/base/registry.ts +0 -87
- /package/assets/minecraft/{blocks.json → 26.2/blocks.json} +0 -0
- /package/assets/minecraft/{entities.json → 26.2/entities.json} +0 -0
- /package/dist/{translator → packet}/static.d.ts +0 -0
- /package/dist/{translator → packet}/static.js +0 -0
- /package/dist/{base → physics}/direction.d.ts +0 -0
- /package/dist/{base → physics}/direction.js +0 -0
- /package/dist/{base → world}/tick.d.ts +0 -0
- /package/dist/{base → world}/tick.js +0 -0
- /package/src/{translator → packet}/static.ts +0 -0
- /package/src/{base → physics}/direction.ts +0 -0
- /package/src/{base → world}/tick.ts +0 -0
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { Vec3 } from "../
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
336
|
+
this.writeRaw(Buffer.from(arr));
|
|
326
337
|
return this;
|
|
327
338
|
}
|
|
328
339
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BitSet } from "
|
|
1
|
+
import { BitSet } from "../base/bitset";
|
|
2
2
|
import { Axis, AxisCycle, BaseAxis, BaseVec3, Direction, Vec3 } from "./direction";
|
|
3
|
-
import { RegistryItemNotFound } from "
|
|
4
|
-
import { EntityRegistry } from "
|
|
5
|
-
import { Epsilon, lowerBoundBinarySearch } from "
|
|
6
|
-
import { BlockHitResult } from "
|
|
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 "
|
|
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 "
|
|
5
|
-
import { clamp, Epsilon, equal, lerp } from "
|
|
6
|
-
import {
|
|
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
|
|
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<
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
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<
|
|
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.
|
|
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.
|
|
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:
|
|
133
|
+
public input(input: Input) { this.heldInputs.add(input); }
|
|
101
134
|
/**
|
|
102
135
|
* Release a key
|
|
103
136
|
*/
|
|
104
|
-
public releaseInput(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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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.
|
|
136
|
-
return new Vec3(this.
|
|
156
|
+
this.state.checkReady();
|
|
157
|
+
return new Vec3(this.state.player!.position);
|
|
137
158
|
}
|
|
138
159
|
private setPos(pos: Vec3) {
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
160
|
+
this.state.checkReady();
|
|
161
|
+
this.state.enqueueMutation((state) => state.player!.position = pos.copyBase());
|
|
141
162
|
}
|
|
142
163
|
private getAngle() {
|
|
143
|
-
this.
|
|
144
|
-
return this.
|
|
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.
|
|
148
|
-
return this.
|
|
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.
|
|
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.
|
|
268
|
+
this.sendPlayerPosRot(this.getPos(), this.getAngle(), this.onGround, this.horizontalCollision);
|
|
241
269
|
else if (move)
|
|
242
|
-
this.
|
|
270
|
+
this.sendPlayerPos(this.getPos(), this.onGround, this.horizontalCollision);
|
|
243
271
|
else if (rot)
|
|
244
|
-
this.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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; //
|
|
322
|
-
//
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
588
|
-
//
|
|
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
|
}
|