@zardoy/flying-squid 0.0.74 → 0.0.75
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/dist/index.js +11 -1
- package/dist/lib/modules/customBlockBreakTime.d.ts +21 -0
- package/dist/lib/modules/customBlockBreakTime.js +60 -0
- package/dist/lib/modules/digging.js +10 -5
- package/dist/lib/modules/index.js +1 -0
- package/dist/lib/modules/login.d.ts +5 -0
- package/dist/lib/modules/login.js +10 -3
- package/dist/lib/modules/world.d.ts +1 -1
- package/dist/lib/modules/world.js +2 -4
- package/dist/lib/playerDat.d.ts +4 -27
- package/dist/lib/playerDat.js +34 -3
- package/dist/types.d.ts +1 -0
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -100,7 +100,17 @@ class MCServer extends events_1.EventEmitter {
|
|
|
100
100
|
server.commands = new command_1.default({});
|
|
101
101
|
// pass version, motd, port, max-players, online-mode
|
|
102
102
|
const oldServer = options.oldServerData;
|
|
103
|
-
server._server = oldServer?._server ?? (0, minecraft_protocol_1.createServer)(
|
|
103
|
+
server._server = oldServer?._server ?? (0, minecraft_protocol_1.createServer)({
|
|
104
|
+
...options,
|
|
105
|
+
beforeLogin(client) {
|
|
106
|
+
const existingPlayer = Object.values(server._server.clients)
|
|
107
|
+
.find(c => c.username.toLowerCase() === client.username.toLowerCase());
|
|
108
|
+
if (existingPlayer) {
|
|
109
|
+
client.end('A player with this username is already connected');
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
});
|
|
104
114
|
patchServerSocket(server._server['socketServer'], server);
|
|
105
115
|
if (oldServer) {
|
|
106
116
|
server.players = oldServer.players;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Block } from 'prismarine-block';
|
|
2
|
+
export declare const server: (serv: Server) => void;
|
|
3
|
+
export declare const player: (player: Player, serv: Server) => Promise<void>;
|
|
4
|
+
export type BreakTimeConfig = {
|
|
5
|
+
toolNames: string[];
|
|
6
|
+
blocks: {
|
|
7
|
+
[stateId: number]: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare global {
|
|
11
|
+
interface Server {
|
|
12
|
+
customPlayersBreakTime: {
|
|
13
|
+
[uuid: string]: BreakTimeConfig;
|
|
14
|
+
};
|
|
15
|
+
customSetPlayerBreakTime: (uuid: string, config: Partial<BreakTimeConfig>) => void;
|
|
16
|
+
customRemovePlayerBreakTime: (uuid: string) => void;
|
|
17
|
+
}
|
|
18
|
+
interface Player {
|
|
19
|
+
customGetBreakTime: (block: Block) => number | undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.player = exports.server = void 0;
|
|
4
|
+
// related to custom channels, everything starts with 'custom'
|
|
5
|
+
const CHANNEL_NAME = 'minecraft-web-client:block-interactions-customization';
|
|
6
|
+
const server = (serv) => {
|
|
7
|
+
serv.customPlayersBreakTime ??= {};
|
|
8
|
+
serv.customSetPlayerBreakTime = (uuid, config) => {
|
|
9
|
+
serv.customPlayersBreakTime[uuid] = {
|
|
10
|
+
...serv.customPlayersBreakTime[uuid],
|
|
11
|
+
...config
|
|
12
|
+
};
|
|
13
|
+
// Send update to the player if they're online
|
|
14
|
+
const player = serv.uuidToPlayer[uuid];
|
|
15
|
+
if (player) {
|
|
16
|
+
sendBreakTimeConfig(player, serv);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
serv.customRemovePlayerBreakTime = (uuid) => {
|
|
20
|
+
delete serv.customPlayersBreakTime[uuid];
|
|
21
|
+
// Send empty config to the player if they're online
|
|
22
|
+
const player = serv.uuidToPlayer[uuid];
|
|
23
|
+
if (player) {
|
|
24
|
+
sendBreakTimeConfig(player, serv);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.server = server;
|
|
29
|
+
function sendBreakTimeConfig(player, serv) {
|
|
30
|
+
const config = serv.customPlayersBreakTime[player.uuid];
|
|
31
|
+
const data = {
|
|
32
|
+
customBreakTime: config?.blocks ?? {},
|
|
33
|
+
customBreakTimeToolAllowance: config?.toolNames ?? []
|
|
34
|
+
};
|
|
35
|
+
player._client.writeChannel(CHANNEL_NAME, {
|
|
36
|
+
newConfiguration: JSON.stringify(data)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const player = async (player, serv) => {
|
|
40
|
+
player.customGetBreakTime = (block) => {
|
|
41
|
+
const config = serv.customPlayersBreakTime[player.uuid];
|
|
42
|
+
if (!config)
|
|
43
|
+
return undefined;
|
|
44
|
+
const heldItemName = player.inventory.slots[36 + player.heldItemSlot]?.name;
|
|
45
|
+
if (config.toolNames.length > 0 && !config.toolNames.includes(heldItemName ?? '')) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return config.blocks?.[block.type] ?? config.blocks?.['*'];
|
|
49
|
+
};
|
|
50
|
+
// Register the channel
|
|
51
|
+
player._client.registerChannel(CHANNEL_NAME, ['container', [
|
|
52
|
+
{
|
|
53
|
+
name: 'newConfiguration',
|
|
54
|
+
type: ['pstring', { countType: 'i16' }]
|
|
55
|
+
}
|
|
56
|
+
]]);
|
|
57
|
+
// Send initial configuration if it exists
|
|
58
|
+
sendBreakTimeConfig(player, serv);
|
|
59
|
+
};
|
|
60
|
+
exports.player = player;
|
|
@@ -71,8 +71,11 @@ const player = function (player, serv, { version }) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
-
function diggingTime(
|
|
74
|
+
function diggingTime() {
|
|
75
75
|
// assume holding nothing and usual conditions
|
|
76
|
+
const customBreakTime = player.customGetBreakTime(currentlyDugBlock);
|
|
77
|
+
if (customBreakTime !== undefined)
|
|
78
|
+
return customBreakTime * 1000;
|
|
76
79
|
return currentlyDugBlock.digTime(null, false, false, false);
|
|
77
80
|
}
|
|
78
81
|
let currentlyDugBlock;
|
|
@@ -84,9 +87,9 @@ const player = function (player, serv, { version }) {
|
|
|
84
87
|
function startDigging(location) {
|
|
85
88
|
serv.entityMaxId++;
|
|
86
89
|
currentAnimationId = serv.entityMaxId;
|
|
87
|
-
expectedDiggingTime = diggingTime(
|
|
90
|
+
expectedDiggingTime = diggingTime();
|
|
88
91
|
lastDestroyState = 0;
|
|
89
|
-
startDiggingTime =
|
|
92
|
+
startDiggingTime = Date.now();
|
|
90
93
|
updateAnimation();
|
|
91
94
|
animationInterval = player.setInterval(updateAnimation, 100);
|
|
92
95
|
function updateAnimation() {
|
|
@@ -139,7 +142,9 @@ const player = function (player, serv, { version }) {
|
|
|
139
142
|
clearInterval(animationInterval);
|
|
140
143
|
const diggingTime = Date.now() - startDiggingTime;
|
|
141
144
|
let stop = false;
|
|
142
|
-
|
|
145
|
+
// const MAX_DIG_DISTANCE = 7
|
|
146
|
+
const MAX_DIG_DISTANCE = 8;
|
|
147
|
+
if (expectedDiggingTime - diggingTime < 100 && player.position.distanceTo(location) > MAX_DIG_DISTANCE) {
|
|
143
148
|
stop = player.behavior('forceCancelDig', {
|
|
144
149
|
stop: true,
|
|
145
150
|
start: startDiggingTime,
|
|
@@ -160,7 +165,7 @@ const player = function (player, serv, { version }) {
|
|
|
160
165
|
drops.push({
|
|
161
166
|
...dropBase,
|
|
162
167
|
blockDropVelocity: new vec3_1.Vec3(Math.random() * 4 - 2, Math.random() * 2 + 2, Math.random() * 4 - 2),
|
|
163
|
-
blockDropId: serv.supportFeature('theFlattening') ? currentlyDugBlock.drops[0] : currentlyDugBlock.type
|
|
168
|
+
blockDropId: serv.supportFeature('theFlattening') ? currentlyDugBlock.drops?.[0] : currentlyDugBlock.type
|
|
164
169
|
});
|
|
165
170
|
}
|
|
166
171
|
else {
|
|
@@ -14,6 +14,7 @@ module.exports = {
|
|
|
14
14
|
'commands': require('./commands'),
|
|
15
15
|
'communication': require('./communication'),
|
|
16
16
|
'crafting': require('./crafting'),
|
|
17
|
+
'customBlockBreakTime': require('./customBlockBreakTime'),
|
|
17
18
|
'daycycle': require('./daycycle'),
|
|
18
19
|
'digging': require('./digging'),
|
|
19
20
|
'dimensionCodec': require('./dimensionCodec'),
|
|
@@ -11,5 +11,10 @@ declare global {
|
|
|
11
11
|
/** login */
|
|
12
12
|
"login": () => Promise<void>;
|
|
13
13
|
stopChunkUpdates: boolean;
|
|
14
|
+
serv: Server;
|
|
15
|
+
}
|
|
16
|
+
interface Options {
|
|
17
|
+
/** Whether to use in-memory storage when worldFolder is falsey. Defaults to true. */
|
|
18
|
+
useInMemoryStorage?: boolean;
|
|
14
19
|
}
|
|
15
20
|
}
|
|
@@ -77,6 +77,7 @@ const server = function (serv, options) {
|
|
|
77
77
|
client.addListener = client.patchedAddListener;
|
|
78
78
|
};
|
|
79
79
|
const addPlayerShared = async (player) => {
|
|
80
|
+
player.serv = serv;
|
|
80
81
|
patchClient(player._client);
|
|
81
82
|
for (const plugin of Object.values({ ...serv.modules, ...serv.plugins }))
|
|
82
83
|
plugin.player?.(player, serv, options);
|
|
@@ -95,7 +96,7 @@ const server = function (serv, options) {
|
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
// #endregion
|
|
98
|
-
|
|
99
|
+
const playerJoined = async (client) => {
|
|
99
100
|
if (client.socket?.listeners('end').length === 0)
|
|
100
101
|
return; // TODO: should be fixed properly in nmp instead
|
|
101
102
|
if (!serv.pluginsReady) {
|
|
@@ -120,7 +121,13 @@ const server = function (serv, options) {
|
|
|
120
121
|
catch (err) {
|
|
121
122
|
setTimeout(() => { throw err; }, 0);
|
|
122
123
|
}
|
|
123
|
-
}
|
|
124
|
+
};
|
|
125
|
+
if (serv.supportFeature('hasConfigurationState')) {
|
|
126
|
+
serv._server.on('playerJoin', playerJoined);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
serv._server.on('login', playerJoined);
|
|
130
|
+
}
|
|
124
131
|
serv.hashedSeed = [0, 0];
|
|
125
132
|
serv.on('seed', (seed) => {
|
|
126
133
|
const seedBuf = Buffer.allocUnsafe(8);
|
|
@@ -153,7 +160,7 @@ const player = async function (player, serv, settings) {
|
|
|
153
160
|
player.world = serv.overworld;
|
|
154
161
|
await player.findSpawnPoint();
|
|
155
162
|
return player.spawnPoint;
|
|
156
|
-
}, settings.worldFolder ?? false);
|
|
163
|
+
}, settings.worldFolder ?? false, settings.useInMemoryStorage ?? true);
|
|
157
164
|
Object.keys(playerData.player).forEach(k => { player[k] = playerData.player[k]; });
|
|
158
165
|
await player.findSpawnPoint();
|
|
159
166
|
// Set world based on saved dimension data, fallback to overworld
|
|
@@ -29,7 +29,7 @@ declare global {
|
|
|
29
29
|
seed: number;
|
|
30
30
|
writeLevelDat: () => Promise<void>;
|
|
31
31
|
"overworldOriginalGenerator": (chunkX: number, chunkZ: number) => any;
|
|
32
|
-
"overworldGeneratorOverride"?: (chunkX: number, chunkZ: number) => any;
|
|
32
|
+
"overworldGeneratorOverride"?: (chunkX: number, chunkZ: number, generationOptions: any) => any;
|
|
33
33
|
}
|
|
34
34
|
interface Player {
|
|
35
35
|
sendingChunksAbortController?: AbortController;
|
|
@@ -153,7 +153,7 @@ const server = async function (serv, options) {
|
|
|
153
153
|
const originalGenerator = generationModule(generationOptions);
|
|
154
154
|
serv.overworldOriginalGenerator = originalGenerator;
|
|
155
155
|
serv.overworld = new World((chunkX, chunkZ) => {
|
|
156
|
-
return serv.overworldGeneratorOverride ? serv.overworldGeneratorOverride(chunkX, chunkZ) : originalGenerator(chunkX, chunkZ);
|
|
156
|
+
return serv.overworldGeneratorOverride ? serv.overworldGeneratorOverride(chunkX, chunkZ, generationOptions) : originalGenerator(chunkX, chunkZ, generationOptions);
|
|
157
157
|
}, regionFolder === undefined || !Anvil ? null : new Anvil(regionFolder), options.savingInterval);
|
|
158
158
|
serv.overworld.seed = serv.seed = generationOptions.seed;
|
|
159
159
|
serv.overworld.generatorName = generation.name;
|
|
@@ -396,9 +396,7 @@ const player = function (player, serv, settings) {
|
|
|
396
396
|
player.flying = flags & 2;
|
|
397
397
|
});
|
|
398
398
|
player.save = async () => {
|
|
399
|
-
|
|
400
|
-
return;
|
|
401
|
-
return await playerDat.save(player, settings.worldFolder, serv.supportFeature('attributeSnakeCase'), serv.supportFeature('theFlattening'));
|
|
399
|
+
return await playerDat.save(player, settings.worldFolder || undefined, serv.supportFeature('attributeSnakeCase'), serv.supportFeature('theFlattening'), settings.useInMemoryStorage ?? true);
|
|
402
400
|
};
|
|
403
401
|
player._unloadChunk = (chunkX, chunkZ) => {
|
|
404
402
|
serv._unloadPlayerChunk(chunkX, chunkZ, player);
|
package/dist/lib/playerDat.d.ts
CHANGED
|
@@ -2,40 +2,17 @@
|
|
|
2
2
|
* @param {string} uuid
|
|
3
3
|
* @param {() => Promise<Vec3>} getSpawnPoint
|
|
4
4
|
* @param {string | false} worldFolder
|
|
5
|
+
* @param {boolean} useInMemoryStorage
|
|
5
6
|
*/
|
|
6
|
-
export function read(uuid: string, getSpawnPoint: () => Promise<Vec3>, worldFolder: string | false): Promise<
|
|
7
|
-
player: {
|
|
8
|
-
position: Vec3;
|
|
9
|
-
health: number;
|
|
10
|
-
food: number;
|
|
11
|
-
heldItemSlot: number;
|
|
12
|
-
};
|
|
13
|
-
inventory: never[];
|
|
14
|
-
new: boolean;
|
|
15
|
-
} | {
|
|
16
|
-
player: {
|
|
17
|
-
health: any;
|
|
18
|
-
food: any;
|
|
19
|
-
gameMode: any;
|
|
20
|
-
xp: any;
|
|
21
|
-
heldItemSlot: any;
|
|
22
|
-
dimension: any;
|
|
23
|
-
position: Vec3;
|
|
24
|
-
yaw: any;
|
|
25
|
-
pitch: any;
|
|
26
|
-
onGround: boolean;
|
|
27
|
-
flying: boolean;
|
|
28
|
-
};
|
|
29
|
-
inventory: any;
|
|
30
|
-
new: boolean;
|
|
31
|
-
}>;
|
|
7
|
+
export function read(uuid: string, getSpawnPoint: () => Promise<Vec3>, worldFolder: string | false, useInMemoryStorage: boolean): Promise<any>;
|
|
32
8
|
/**
|
|
33
9
|
* @param {Player} player
|
|
34
10
|
* @param {string | undefined} worldFolder
|
|
35
11
|
* @param {boolean} snakeCase
|
|
36
12
|
* @param {boolean} theFlattening
|
|
13
|
+
* @param {boolean} useInMemoryStorage
|
|
37
14
|
*/
|
|
38
|
-
export function save(player: Player, worldFolder: string | undefined, snakeCase: boolean, theFlattening: boolean): Promise<any>;
|
|
15
|
+
export function save(player: Player, worldFolder: string | undefined, snakeCase: boolean, theFlattening: boolean, useInMemoryStorage: boolean): Promise<any>;
|
|
39
16
|
export namespace playerDefaults {
|
|
40
17
|
let health: number;
|
|
41
18
|
let food: number;
|
package/dist/lib/playerDat.js
CHANGED
|
@@ -14,6 +14,8 @@ const long_1 = __importDefault(require("long"));
|
|
|
14
14
|
const node_gzip_1 = require("node-gzip");
|
|
15
15
|
const util_1 = require("util");
|
|
16
16
|
const convertInventorySlotId_1 = require("./convertInventorySlotId");
|
|
17
|
+
// In-memory storage for player data when worldFolder is falsey
|
|
18
|
+
const inMemoryStorage = new Map();
|
|
17
19
|
const nbtParse = (0, util_1.promisify)(prismarine_nbt_1.parse);
|
|
18
20
|
const playerDefaults = {
|
|
19
21
|
health: 20,
|
|
@@ -25,8 +27,9 @@ exports.playerDefaults = playerDefaults;
|
|
|
25
27
|
* @param {string} uuid
|
|
26
28
|
* @param {() => Promise<Vec3>} getSpawnPoint
|
|
27
29
|
* @param {string | false} worldFolder
|
|
30
|
+
* @param {boolean} useInMemoryStorage
|
|
28
31
|
*/
|
|
29
|
-
async function read(uuid, getSpawnPoint, worldFolder) {
|
|
32
|
+
async function read(uuid, getSpawnPoint, worldFolder, useInMemoryStorage) {
|
|
30
33
|
const newPlayerData = async () => {
|
|
31
34
|
return {
|
|
32
35
|
player: { ...playerDefaults, ...{ position: (await getSpawnPoint()).clone() } },
|
|
@@ -34,8 +37,16 @@ async function read(uuid, getSpawnPoint, worldFolder) {
|
|
|
34
37
|
new: true
|
|
35
38
|
};
|
|
36
39
|
};
|
|
37
|
-
if (!worldFolder)
|
|
40
|
+
if (!worldFolder) {
|
|
41
|
+
const storedData = inMemoryStorage.get(uuid);
|
|
42
|
+
if (storedData) {
|
|
43
|
+
return {
|
|
44
|
+
...storedData,
|
|
45
|
+
new: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
38
48
|
return await newPlayerData();
|
|
49
|
+
}
|
|
39
50
|
try {
|
|
40
51
|
const playerDataFile = await fs_1.promises.readFile(`${worldFolder}/playerdata/${uuid}.dat`);
|
|
41
52
|
/** @type {any} */
|
|
@@ -107,9 +118,29 @@ function playerInventoryToNBT(playerInventory, theFlattening) {
|
|
|
107
118
|
* @param {string | undefined} worldFolder
|
|
108
119
|
* @param {boolean} snakeCase
|
|
109
120
|
* @param {boolean} theFlattening
|
|
121
|
+
* @param {boolean} useInMemoryStorage
|
|
110
122
|
*/
|
|
111
|
-
async function save(player, worldFolder, snakeCase, theFlattening) {
|
|
123
|
+
async function save(player, worldFolder, snakeCase, theFlattening, useInMemoryStorage) {
|
|
112
124
|
if (worldFolder === undefined) {
|
|
125
|
+
if (useInMemoryStorage) {
|
|
126
|
+
const playerData = {
|
|
127
|
+
player: {
|
|
128
|
+
health: player.health,
|
|
129
|
+
food: player.food,
|
|
130
|
+
gameMode: player.gameMode,
|
|
131
|
+
xp: player.xp,
|
|
132
|
+
heldItemSlot: player.heldItemSlot,
|
|
133
|
+
dimension: player.dimension ?? 0,
|
|
134
|
+
position: player.position,
|
|
135
|
+
yaw: player.yaw,
|
|
136
|
+
pitch: player.pitch,
|
|
137
|
+
onGround: player.onGround,
|
|
138
|
+
flying: player.flying ?? 0
|
|
139
|
+
},
|
|
140
|
+
inventory: playerInventoryToNBT(player.inventory, theFlattening)
|
|
141
|
+
};
|
|
142
|
+
inMemoryStorage.set(player.uuid, playerData);
|
|
143
|
+
}
|
|
113
144
|
return;
|
|
114
145
|
}
|
|
115
146
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import "./lib/modules/commandBlocks.d.ts"
|
|
|
11
11
|
import "./lib/modules/commands.d.ts"
|
|
12
12
|
import "./lib/modules/communication.d.ts"
|
|
13
13
|
import "./lib/modules/crafting.d.ts"
|
|
14
|
+
import "./lib/modules/customBlockBreakTime.d.ts"
|
|
14
15
|
import "./lib/modules/daycycle.d.ts"
|
|
15
16
|
import "./lib/modules/digging.d.ts"
|
|
16
17
|
import "./lib/modules/dimensionCodec.d.ts"
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zardoy/flying-squid",
|
|
3
3
|
"description": "A minecraft server written in TS",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.75",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"bin": "dist/app.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"mkdirp": "^2.1.3",
|
|
36
36
|
"node-gzip": "^1.1.2",
|
|
37
37
|
"node-rsa": "^1.1.1",
|
|
38
|
-
"prismarine-chunk": "^1.
|
|
39
|
-
"prismarine-entity": "^2.
|
|
40
|
-
"prismarine-item": "^1.
|
|
41
|
-
"prismarine-nbt": "^2.
|
|
38
|
+
"prismarine-chunk": "^1.39.0",
|
|
39
|
+
"prismarine-entity": "^2.5.0",
|
|
40
|
+
"prismarine-item": "^1.17.0",
|
|
41
|
+
"prismarine-nbt": "^2.7.0",
|
|
42
42
|
"prismarine-provider-anvil": "github:zardoy/prismarine-provider-anvil#everything",
|
|
43
43
|
"prismarine-windows": "^2.8.0",
|
|
44
|
-
"prismarine-world": "^3.6.
|
|
44
|
+
"prismarine-world": "^3.6.3",
|
|
45
45
|
"rambda": "^9.2.0",
|
|
46
46
|
"random-seed": "^0.3.0",
|
|
47
47
|
"range": "^0.0.3",
|