pw-js-world 0.0.1 → 0.0.3-dev.337233b
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/LICENSE +20 -20
- package/dist/Helper.d.ts +5 -3
- package/dist/Helper.js +9 -1
- package/dist/types/index.d.ts +18 -18
- package/esm.mjs +18 -18
- package/lib/Block.ts +216 -216
- package/lib/BufferReader.ts +769 -769
- package/lib/Constants.ts +3 -3
- package/lib/Helper.ts +608 -602
- package/lib/Player.ts +316 -316
- package/lib/index.ts +7 -7
- package/lib/types/index.d.ts +18 -18
- package/package.json +1 -1
- package/bun.lockb +0 -0
- package/test/index.ts +0 -96
package/package.json
CHANGED
package/bun.lockb
DELETED
|
Binary file
|
package/test/index.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { LayerType } from "../lib/Constants";
|
|
2
|
-
import { PWGameWorldHelper } from "../lib/index";
|
|
3
|
-
import { BlockNames, PWApiClient } from "pw-js-api";
|
|
4
|
-
|
|
5
|
-
const api = new PWApiClient("doomester@duck.com", "D!wr%Jy&z!uPSJ3m%5TG");
|
|
6
|
-
const helper = new PWGameWorldHelper();
|
|
7
|
-
|
|
8
|
-
await api.authenticate();
|
|
9
|
-
|
|
10
|
-
const con = await api.joinWorld("rfdeeb8d9d94f76", {
|
|
11
|
-
gameSettings: {
|
|
12
|
-
handlePackets: ["PING", "INIT"]
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
con
|
|
17
|
-
// .addHook<{ playerInitPacket: { def: string } }>(() => {})
|
|
18
|
-
.addHook(helper.receiveHook)
|
|
19
|
-
.addCallback("playerInitPacket", (data, states) => {
|
|
20
|
-
// console.log(states?.player?.isMe);
|
|
21
|
-
|
|
22
|
-
states?.player?.username
|
|
23
|
-
|
|
24
|
-
con.send("worldBlockPlacedPacket",
|
|
25
|
-
|
|
26
|
-
helper.createBlockPacket(BlockNames.BASIC_GREEN, LayerType.Foreground, [{
|
|
27
|
-
x: 18,
|
|
28
|
-
y: 93
|
|
29
|
-
}, {
|
|
30
|
-
x: 19,
|
|
31
|
-
y: 94
|
|
32
|
-
}, {
|
|
33
|
-
x: 20,
|
|
34
|
-
y: 95
|
|
35
|
-
}]));
|
|
36
|
-
|
|
37
|
-
const signPack = helper.createBlockPacket(BlockNames.SIGN_BLUE, LayerType.Foreground, {
|
|
38
|
-
x: 19,
|
|
39
|
-
y: 98
|
|
40
|
-
}, new Date().toString());
|
|
41
|
-
|
|
42
|
-
console.log(signPack);
|
|
43
|
-
con.send("worldBlockPlacedPacket", signPack);
|
|
44
|
-
|
|
45
|
-
// console.log(data.globalSwitchState);
|
|
46
|
-
})
|
|
47
|
-
.addCallback("debug", egg => {
|
|
48
|
-
if (!egg.includes("ping")) console.log(egg)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
.addCallback("worldBlockPlacedPacket", (data, states) => {
|
|
52
|
-
console.log("Prev Block Id: " + states?.oldBlocks[0].bId);
|
|
53
|
-
console.log("Prev Block Args: " + states?.oldBlocks[0].args);
|
|
54
|
-
console.log("New Block Id: " + states?.newBlocks[0].bId);
|
|
55
|
-
console.log("New Block Args: " + states?.newBlocks[0].args);
|
|
56
|
-
})
|
|
57
|
-
.addCallback("playerChatPacket", (data, states) => {
|
|
58
|
-
const msg = data.message;
|
|
59
|
-
const args = msg.split(" ");
|
|
60
|
-
|
|
61
|
-
switch (args[0]) {
|
|
62
|
-
case "!at":
|
|
63
|
-
if (args.length > 2) {
|
|
64
|
-
const nums = [parseInt(args[1]), parseInt(args[2])];
|
|
65
|
-
|
|
66
|
-
if (!nums.some(v => isNaN(v))) {
|
|
67
|
-
const block = helper.getBlockAt(nums[0], nums[1], 1);
|
|
68
|
-
|
|
69
|
-
return con.send("playerChatPacket", {
|
|
70
|
-
message: "Block at (X: " + nums[0] + ", Y: " + nums[1] + ") - " + block.name + " (ID: " + block.bId + ", Args: " + block.hasArgs() + ")"
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "stat":
|
|
76
|
-
{
|
|
77
|
-
const player = states?.player;
|
|
78
|
-
|
|
79
|
-
console.log({
|
|
80
|
-
isMe: player?.isMe,
|
|
81
|
-
id: player?.playerId,
|
|
82
|
-
effects: player?.effects,
|
|
83
|
-
face: player?.face,
|
|
84
|
-
states: {
|
|
85
|
-
coins: [player?.states.coinsGold, player?.states.coinsBlue],
|
|
86
|
-
deaths: player?.states.deaths,
|
|
87
|
-
collected: player?.states.collectedItems.length,
|
|
88
|
-
modes: [player?.states.godmode, player?.states.modmode],
|
|
89
|
-
teamId: player?.states.teamId
|
|
90
|
-
},
|
|
91
|
-
name: player?.username
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
})
|