@zardoy/flying-squid 0.0.133 → 0.0.134
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/lib/modules/bed.d.ts +16 -0
- package/dist/lib/modules/bed.js +63 -0
- package/dist/lib/modules/index.js +1 -0
- package/dist/lib/modules/playerLogin.js +5 -10
- package/dist/lib/modules/respawn.js +3 -3
- package/dist/lib/modules/world.d.ts +2 -0
- package/dist/lib/modules/world.js +34 -11
- package/dist/lib/playerDat.js +18 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
2
|
+
/**
|
|
3
|
+
* Beds set the respawn point (Java: right click, "Respawn point set"). Simplified sleeping: at night the click also skips to the morning, there is no lying-in-bed animation
|
|
4
|
+
* and no wait for the other players. In the Nether and the End beds do nothing here (vanilla: they explode). A respawn goes to the bed while it is still there with free space
|
|
5
|
+
* above it, else to the world spawn (vanilla "Your home bed was missing or obstructed"). The bed is saved in the player data (`SpawnX/Y/Z`, `SpawnDimension`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const server: (serv: Server) => void;
|
|
8
|
+
export declare const player: (player: Player, serv: Server) => void;
|
|
9
|
+
declare global {
|
|
10
|
+
interface Player {
|
|
11
|
+
/** position of the bed that sets the respawn point (overworld), saved in the player data */
|
|
12
|
+
bedSpawn?: Vec3;
|
|
13
|
+
/** position a respawn puts the player at: the bed while it exists, else the spawn point */
|
|
14
|
+
respawnPosition: () => Promise<Vec3>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.player = exports.server = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Beds set the respawn point (Java: right click, "Respawn point set"). Simplified sleeping: at night the click also skips to the morning, there is no lying-in-bed animation
|
|
6
|
+
* and no wait for the other players. In the Nether and the End beds do nothing here (vanilla: they explode). A respawn goes to the bed while it is still there with free space
|
|
7
|
+
* above it, else to the world spawn (vanilla "Your home bed was missing or obstructed"). The bed is saved in the player data (`SpawnX/Y/Z`, `SpawnDimension`).
|
|
8
|
+
*/
|
|
9
|
+
const server = function (serv) {
|
|
10
|
+
const mcData = serv.mcData;
|
|
11
|
+
const isBedName = (name) => name === 'bed' || name.endsWith('_bed');
|
|
12
|
+
serv.once('asap', () => {
|
|
13
|
+
for (const name of mcData.blocksArray.map(b => b.name).filter(isBedName)) {
|
|
14
|
+
serv.onBlockInteraction(name, async ({ block, player }) => {
|
|
15
|
+
const world = player.world;
|
|
16
|
+
if (world.environment !== 'normal') {
|
|
17
|
+
player.chat('§cBeds only work in the overworld');
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
player.bedSpawn = block.position.clone();
|
|
21
|
+
player.chat('Respawn point set');
|
|
22
|
+
const night = serv.time >= 12542 && serv.time <= 23459;
|
|
23
|
+
if (night) {
|
|
24
|
+
serv.setTime(0);
|
|
25
|
+
serv.broadcast?.(`${player.username} slept through the night`, { whitelist: serv.players });
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.server = server;
|
|
33
|
+
const player = function (player, serv) {
|
|
34
|
+
const free = async (world, p) => (await world.getBlock(p)).boundingBox !== 'block' && (await world.getBlock(p.offset(0, 1, 0))).boundingBox !== 'block';
|
|
35
|
+
/** where a respawn puts the player: next to the bed (or on it) when it is still there, else the spawn point of the world */
|
|
36
|
+
player.respawnPosition = async () => {
|
|
37
|
+
const bed = player.bedSpawn;
|
|
38
|
+
if (bed) {
|
|
39
|
+
const world = serv.overworld;
|
|
40
|
+
try {
|
|
41
|
+
await world.getColumnAt(bed);
|
|
42
|
+
const block = await world.getBlock(bed);
|
|
43
|
+
if (isBed(block.name)) {
|
|
44
|
+
for (const [dx, dz] of [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, 1], [1, -1], [-1, -1]]) {
|
|
45
|
+
const p = bed.offset(dx, 0, dz);
|
|
46
|
+
const below = await world.getBlock(p.offset(0, -1, 0));
|
|
47
|
+
if (below.boundingBox === 'block' && await free(world, p))
|
|
48
|
+
return p.offset(0.5, 0, 0.5);
|
|
49
|
+
}
|
|
50
|
+
if (await free(world, bed.offset(0, 1, 0)))
|
|
51
|
+
return bed.offset(0.5, 0.5625, 0.5);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
player.bedSpawn = undefined;
|
|
56
|
+
player.chat('§cYour home bed was missing or obstructed');
|
|
57
|
+
}
|
|
58
|
+
await player.findSpawnPoint();
|
|
59
|
+
return player.spawnPoint;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.player = player;
|
|
63
|
+
const isBed = (name) => name === 'bed' || name.endsWith('_bed');
|
|
@@ -286,18 +286,13 @@ const player = async function (player, serv, settings) {
|
|
|
286
286
|
const viewDistance = (settings['view-distance'] ??= 8);
|
|
287
287
|
const dimensionCodec = (0, dimensionCodec_1.getDimensionCodec)(MAX_HEIGHT, serv.supportFeature('dimensionDataIsAvailable'), settings.version);
|
|
288
288
|
// const dimensionCodec = serv.mcData.loginPacket.dimensionCodec
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
worldState.
|
|
292
|
-
|
|
293
|
-
1: 'creative',
|
|
294
|
-
2: 'adventure',
|
|
295
|
-
3: 'spectator'
|
|
296
|
-
}[player.gameMode];
|
|
297
|
-
worldState.previousGamemode = player.prevGameMode;
|
|
298
|
-
}
|
|
289
|
+
// 1.20.2+: dimension, level name and game mode of the world the player is in (a player saved in the nether joins the nether)
|
|
290
|
+
const worldState = serv.mcData.loginPacket.worldState
|
|
291
|
+
? serv.worldState(player.world ?? serv.overworld, player.gameMode, player.prevGameMode)
|
|
292
|
+
: undefined;
|
|
299
293
|
player._client.write('login', {
|
|
300
294
|
...serv.mcData.loginPacket, // for new fields
|
|
295
|
+
...(worldState ? { worldState } : {}),
|
|
301
296
|
entityId: player.id,
|
|
302
297
|
isHardcore: player.gameMode === 0,
|
|
303
298
|
gameMode: player.gameMode,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.player = void 0;
|
|
4
4
|
const player = function (player, serv) {
|
|
5
|
-
player._client.on('client_command', (data) => {
|
|
5
|
+
player._client.on('client_command', async (data) => {
|
|
6
6
|
let actionId;
|
|
7
7
|
if (serv.supportFeature('respawnIsPayload')) {
|
|
8
8
|
actionId = data.payload;
|
|
@@ -11,7 +11,7 @@ const player = function (player, serv) {
|
|
|
11
11
|
actionId = data.actionId;
|
|
12
12
|
}
|
|
13
13
|
if (actionId === 0) {
|
|
14
|
-
player.position = player.
|
|
14
|
+
player.position = await player.respawnPosition();
|
|
15
15
|
player.behavior('requestRespawn', {}, () => {
|
|
16
16
|
// the respawn point is in the overworld: a player who died in another world (nether, end, /mv world) really changes the world, not only the client's dimension
|
|
17
17
|
const switchingWorld = player.world !== serv.overworld;
|
|
@@ -19,7 +19,7 @@ const player = function (player, serv) {
|
|
|
19
19
|
player._unloadAllChunks();
|
|
20
20
|
player.world = serv.overworld;
|
|
21
21
|
}
|
|
22
|
-
player._client.write('respawn', {
|
|
22
|
+
player._client.write('respawn', serv.supportFeature('spawnRespawnWorldDataField') ? { worldState: serv.worldState(serv.overworld, player.gameMode, player.prevGameMode, 0), copyMetadata: 0 } : {
|
|
23
23
|
previousGameMode: player.prevGameMode,
|
|
24
24
|
dimension: serv.supportFeature('dimensionIsAWorld') ? {
|
|
25
25
|
type: 'compound',
|
|
@@ -68,6 +68,8 @@ declare global {
|
|
|
68
68
|
dimension: any;
|
|
69
69
|
worldName: string;
|
|
70
70
|
};
|
|
71
|
+
/** `worldState` (SpawnInfo) of the login / respawn packet of 1.20.2+ */
|
|
72
|
+
worldState: (world: any, gameMode: number, previousGameMode: number | undefined, dimension?: number) => any;
|
|
71
73
|
/** Saves block in world and sends block update to all players of the same world. */
|
|
72
74
|
"setBlock": (world: CustomWorld, position: Vec3, stateId: number) => Promise<void>;
|
|
73
75
|
/** Sends a block action to all players of the same world. */
|
|
@@ -398,6 +398,27 @@ const server = async function (serv, options) {
|
|
|
398
398
|
dimension: serv.supportFeature('dimensionIsAString') ? serv.dimensionNames[dimension || 0] : serv.supportFeature('dimensionIsAnInt') ? dimension || 0 : (0, dimensionCodec_1.dimensionNbt)(dimension || 0),
|
|
399
399
|
worldName: ['overworld', 'nether', 'end'].includes(world?.worldName) || !world?.worldName ? serv.dimensionNames[dimension || 0] : `flyingsquid:${world.worldName.toLowerCase()}`
|
|
400
400
|
});
|
|
401
|
+
/**
|
|
402
|
+
* `worldState` (protocol `SpawnInfo`) of the login and respawn packets since 1.20.2: the dimension is an index into the `minecraft:dimension_type` registry the client has,
|
|
403
|
+
* the name is the level identifier. Without it the client never switches dimension (the respawn packet cannot even be written) and then fails on the chunks of the new one.
|
|
404
|
+
*/
|
|
405
|
+
serv.worldState = (world, gameMode, previousGameMode, dimension = world?.dimensionId ?? 0) => {
|
|
406
|
+
const typeName = dimension === -1 ? 'minecraft:the_nether' : dimension === 1 ? 'minecraft:the_end' : 'minecraft:overworld';
|
|
407
|
+
const entries = serv.mcData.loginPacket?.dimensionCodec?.['minecraft:dimension_type']?.entries;
|
|
408
|
+
const index = Math.max(0, entries?.findIndex(e => e.key === typeName) ?? 0);
|
|
409
|
+
return {
|
|
410
|
+
dimension: index,
|
|
411
|
+
name: serv.worldClientInfo(world, dimension).worldName,
|
|
412
|
+
hashedSeed: serv.hashedSeed,
|
|
413
|
+
gamemode: { 0: 'survival', 1: 'creative', 2: 'adventure', 3: 'spectator' }[gameMode] ?? 'survival',
|
|
414
|
+
previousGamemode: previousGameMode ?? 255,
|
|
415
|
+
isDebug: false,
|
|
416
|
+
isFlat: false,
|
|
417
|
+
death: undefined,
|
|
418
|
+
portalCooldown: 0,
|
|
419
|
+
seaLevel: dimension === -1 ? 32 : dimension === 1 ? 0 : 63
|
|
420
|
+
};
|
|
421
|
+
};
|
|
401
422
|
serv.overworld.blockEntityData = {};
|
|
402
423
|
serv.overworld.portals = [];
|
|
403
424
|
serv.pregenWorld = (world, size = 3) => {
|
|
@@ -879,17 +900,19 @@ const player = function (player, serv, settings) {
|
|
|
879
900
|
player.prevGameMode = player.gameMode;
|
|
880
901
|
player.gameMode = opt.gamemode;
|
|
881
902
|
}
|
|
882
|
-
player._client.write('respawn',
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
903
|
+
player._client.write('respawn', serv.supportFeature('spawnRespawnWorldDataField')
|
|
904
|
+
? { worldState: serv.worldState(world, opt.gamemode || player.gameMode, player.prevGameMode, opt.dimension), copyMetadata: 1 }
|
|
905
|
+
: {
|
|
906
|
+
previousGameMode: player.prevGameMode,
|
|
907
|
+
...serv.worldClientInfo(world, opt.dimension),
|
|
908
|
+
difficulty: opt.difficulty || serv.difficulty,
|
|
909
|
+
hashedSeed: serv.hashedSeed,
|
|
910
|
+
gamemode: opt.gamemode || player.gameMode,
|
|
911
|
+
levelType: 'default',
|
|
912
|
+
isDebug: false,
|
|
913
|
+
isFlat: false,
|
|
914
|
+
copyMetadata: true
|
|
915
|
+
});
|
|
893
916
|
await player.findSpawnPoint();
|
|
894
917
|
// `player.spawnPoint` is the respawn point in the overworld: another world has its own standable entry point
|
|
895
918
|
player.position = opt.position ?? (world === serv.overworld || !serv.worldEntryPoint ? player.spawnPoint : await serv.worldEntryPoint(world, from, player.position));
|
package/dist/lib/playerDat.js
CHANGED
|
@@ -64,6 +64,10 @@ async function read(uuid, getSpawnPoint, worldFolder, useInMemoryStorage) {
|
|
|
64
64
|
pitch: playerData.Rotation.value.value[1],
|
|
65
65
|
onGround: Boolean(playerData.OnGround.value),
|
|
66
66
|
flying: Boolean(playerData.abilities.value.flying.value),
|
|
67
|
+
// bed (Java: SpawnX/Y/Z + SpawnDimension) set in the overworld
|
|
68
|
+
...(playerData.SpawnX && playerData.SpawnY && playerData.SpawnZ && (!playerData.SpawnDimension || /overworld$/.test(playerData.SpawnDimension.value))
|
|
69
|
+
? { bedSpawn: new vec3_1.Vec3(playerData.SpawnX.value, playerData.SpawnY.value, playerData.SpawnZ.value) }
|
|
70
|
+
: {})
|
|
67
71
|
},
|
|
68
72
|
inventory: playerData.Inventory.value.value.map(nbtItem => {
|
|
69
73
|
if (nbtItem?.tag && !nbtItem.tag.name)
|
|
@@ -147,7 +151,8 @@ async function save(player, worldFolder, snakeCase, theFlattening, useInMemorySt
|
|
|
147
151
|
yaw: player.yaw,
|
|
148
152
|
pitch: player.pitch,
|
|
149
153
|
onGround: player.onGround,
|
|
150
|
-
flying: player.flying ?? 0
|
|
154
|
+
flying: player.flying ?? 0,
|
|
155
|
+
...(player.bedSpawn ? { bedSpawn: player.bedSpawn.clone() } : {})
|
|
151
156
|
},
|
|
152
157
|
inventory: playerInventoryToNBT(player.inventory, theFlattening),
|
|
153
158
|
enderItems: player.enderChestToNbt?.() ?? []
|
|
@@ -174,6 +179,18 @@ async function save(player, worldFolder, snakeCase, theFlattening, useInMemorySt
|
|
|
174
179
|
const ender = player.enderChestToNbt?.() ?? [];
|
|
175
180
|
newUncompressedData.value.EnderItems = ender.length ? { type: 'list', value: { type: 'compound', value: ender } } : { type: 'list', value: { type: 'end', value: [] } };
|
|
176
181
|
newUncompressedData.value.abilities.value.flying.value = player.flying ?? 0;
|
|
182
|
+
if (player.bedSpawn) {
|
|
183
|
+
newUncompressedData.value.SpawnX = { type: 'int', value: player.bedSpawn.x };
|
|
184
|
+
newUncompressedData.value.SpawnY = { type: 'int', value: player.bedSpawn.y };
|
|
185
|
+
newUncompressedData.value.SpawnZ = { type: 'int', value: player.bedSpawn.z };
|
|
186
|
+
newUncompressedData.value.SpawnDimension = { type: 'string', value: 'minecraft:overworld' };
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
delete newUncompressedData.value.SpawnX;
|
|
190
|
+
delete newUncompressedData.value.SpawnY;
|
|
191
|
+
delete newUncompressedData.value.SpawnZ;
|
|
192
|
+
delete newUncompressedData.value.SpawnDimension;
|
|
193
|
+
}
|
|
177
194
|
const newDataCompressed = await (0, node_gzip_1.gzip)((0, prismarine_nbt_1.writeUncompressed)(newUncompressedData));
|
|
178
195
|
await fs_1.promises.writeFile(`${worldFolder}/playerdata/${player.uuid}.dat`, newDataCompressed);
|
|
179
196
|
return newUncompressedData;
|
package/dist/types.d.ts
CHANGED