@zardoy/flying-squid 0.0.89 → 0.0.91
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/blocks.d.ts +6 -5
- package/dist/lib/modules/blocks.js +9 -4
- package/dist/lib/modules/digging.js +13 -6
- package/dist/lib/modules/particle.d.ts +2 -1
- package/dist/lib/modules/playerLogin.js +4 -2
- package/dist/lib/modules/safeZones.js +4 -1
- package/dist/lib/modules/sound.d.ts +37 -14
- package/dist/lib/modules/sound.js +65 -3
- package/dist/modules.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
1
2
|
export declare const player: (player: Player, serv: Server) => void;
|
|
2
3
|
export declare const server: (serv: Server, { version }: Options) => void;
|
|
3
4
|
declare global {
|
|
@@ -7,14 +8,14 @@ declare global {
|
|
|
7
8
|
* this will not change the block for the user himself. It is mainly useful when a user places a block
|
|
8
9
|
* and only needs to send it to other players on the server
|
|
9
10
|
*/
|
|
10
|
-
'changeBlock': (position:
|
|
11
|
+
'changeBlock': (position: Vec3, blockType: number, blockData: any) => Promise<void>;
|
|
11
12
|
/** change the block at position `position` to `blockType` and `blockData`
|
|
12
13
|
*
|
|
13
14
|
* this will not make any changes on the server's world and only sends it to the user as a "fake" or "local" block
|
|
14
15
|
*/
|
|
15
|
-
'sendBlock': (position:
|
|
16
|
+
'sendBlock': (position: Vec3, blockStateId: number) => any;
|
|
16
17
|
/** Saves block in world and sends block update to all players of the same world. */
|
|
17
|
-
'setBlock': (position:
|
|
18
|
+
'setBlock': (position: Vec3, stateId: number) => any;
|
|
18
19
|
/** Set the block action at position `position` to `actionId` and `actionParam`.
|
|
19
20
|
*
|
|
20
21
|
* ``blockType`` is only required when the block at the location is a fake block.
|
|
@@ -22,11 +23,11 @@ declare global {
|
|
|
22
23
|
*
|
|
23
24
|
* This will not make any changes to the server's world and only sends it to the user as a local action.
|
|
24
25
|
*/
|
|
25
|
-
'sendBlockAction': (position:
|
|
26
|
+
'sendBlockAction': (position: Vec3, actionId: number, actionParam: number, blockType: number) => Promise<void>;
|
|
26
27
|
/** Sets a block action and sends the block action to all players in the same world.
|
|
27
28
|
*
|
|
28
29
|
* This will not make any changes to the server's world
|
|
29
30
|
*/
|
|
30
|
-
'setBlockAction': (position:
|
|
31
|
+
'setBlockAction': (position: Vec3, actionId: number, actionParam: number) => any;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -97,9 +97,9 @@ const server = function (serv, { version }) {
|
|
|
97
97
|
},
|
|
98
98
|
action(params, ctx) {
|
|
99
99
|
if (ctx.player)
|
|
100
|
-
ctx.player.setBlockAction(new vec3_1.Vec3(+params[1], +params[2], +params[3]).floored(), +params[4], params[5]);
|
|
100
|
+
ctx.player.setBlockAction(new vec3_1.Vec3(+params[1], +params[2], +params[3]).floored(), +params[4], Number(params[5]));
|
|
101
101
|
else
|
|
102
|
-
serv.setBlockAction(serv.overworld, new vec3_1.Vec3(+params[1], +params[2], +params[3]).floored(), +params[4], params[5]);
|
|
102
|
+
serv.setBlockAction(serv.overworld, new vec3_1.Vec3(+params[1], +params[2], +params[3]).floored(), +params[4], Number(params[5]));
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
serv.commands.add({
|
|
@@ -113,11 +113,16 @@ const server = function (serv, { version }) {
|
|
|
113
113
|
action([_sX, _sY, _sZ, _tX, _tY, _tZ, blockArg], ctx) {
|
|
114
114
|
const [sX, sY, sZ, tX, tY, tZ] = [_sX, _sY, _sZ, _tX, _tY, _tZ].map(x => +x);
|
|
115
115
|
const block = []; // todo resolve block
|
|
116
|
+
let changes = 0;
|
|
116
117
|
for (let x = Math.min(sX, tX); x <= Math.max(sX, tX); x++) {
|
|
117
118
|
for (let y = Math.min(sY, tY); y <= Math.max(sY, tY); y++) {
|
|
118
119
|
for (let z = Math.min(sZ, tZ); z <= Math.max(sZ, tZ); z++) {
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
ctx.player.setBlock(new vec3_1.Vec3(x, y, z), 0);
|
|
121
|
+
changes++;
|
|
122
|
+
if (changes > 1000) {
|
|
123
|
+
ctx.player.chat(`[Fill] Made ${changes} changes`);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
128
|
}
|
|
@@ -7,7 +7,7 @@ const player = function (player, serv, { version }) {
|
|
|
7
7
|
function cancelDig({ position, block }) {
|
|
8
8
|
player.sendBlock(position, block.type);
|
|
9
9
|
}
|
|
10
|
-
player._client.on('block_dig',
|
|
10
|
+
player._client.on('block_dig', ({ location, status, face }) => {
|
|
11
11
|
if (status === 3 || status === 4) {
|
|
12
12
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot];
|
|
13
13
|
if (!heldItem || heldItem.type === -1)
|
|
@@ -47,14 +47,20 @@ const player = function (player, serv, { version }) {
|
|
|
47
47
|
directionVector = new vec3_1.Vec3(0, 0, 0);
|
|
48
48
|
}
|
|
49
49
|
const facedPos = pos.plus(directionVector);
|
|
50
|
-
const
|
|
50
|
+
const columnFaced = player.world.getLoadedColumnAt(facedPos);
|
|
51
|
+
const columnBlock = player.world.getLoadedColumnAt(pos);
|
|
52
|
+
if (!columnFaced || !columnBlock) {
|
|
53
|
+
console.warn(`[Digging] Column not loaded for player ${player.username} at ${pos}`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const facedBlock = columnFaced.getBlock(new vec3_1.Vec3(facedPos.x & 15, 0, facedPos.z & 15));
|
|
51
57
|
let block;
|
|
52
58
|
if (facedBlock.name === 'fire') {
|
|
53
59
|
block = facedBlock;
|
|
54
60
|
pos = facedPos;
|
|
55
61
|
}
|
|
56
62
|
else {
|
|
57
|
-
block =
|
|
63
|
+
block = columnBlock.getBlock(new vec3_1.Vec3(pos.x & 15, 0, pos.z & 15));
|
|
58
64
|
}
|
|
59
65
|
currentlyDugBlock = block;
|
|
60
66
|
if (currentlyDugBlock.type === 0)
|
|
@@ -71,7 +77,7 @@ const player = function (player, serv, { version }) {
|
|
|
71
77
|
cancelDigging(pos);
|
|
72
78
|
}
|
|
73
79
|
else if (status === 2) {
|
|
74
|
-
completeDigging(pos);
|
|
80
|
+
completeDigging(pos, directionVector);
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
});
|
|
@@ -143,7 +149,7 @@ const player = function (player, serv, { version }) {
|
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
151
|
const blockDropVelocity = new vec3_1.Vec3(Math.random() * 4 - 2, Math.random() * 2 + 2, Math.random() * 4 - 2);
|
|
146
|
-
async function completeDigging(location) {
|
|
152
|
+
async function completeDigging(location, directionVector) {
|
|
147
153
|
clearInterval(animationInterval);
|
|
148
154
|
const diggingTime = Date.now() - startDiggingTime;
|
|
149
155
|
let stop = false;
|
|
@@ -195,7 +201,8 @@ const player = function (player, serv, { version }) {
|
|
|
195
201
|
position: location,
|
|
196
202
|
block: currentlyDugBlock,
|
|
197
203
|
dropBlock: true,
|
|
198
|
-
drops
|
|
204
|
+
drops,
|
|
205
|
+
directionVector
|
|
199
206
|
}, async (data) => {
|
|
200
207
|
player.changeBlock(data.position, 0, 0);
|
|
201
208
|
const aboveBlock = await player.world.getBlock(data.position.offset(0, 1, 0));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
1
2
|
export declare const server: (serv: Server) => void;
|
|
2
3
|
declare global {
|
|
3
4
|
interface Server {
|
|
@@ -11,7 +12,7 @@ declare global {
|
|
|
11
12
|
* - size: vec3 of the size. (0,0,0) will be at an exact position, (10,10,10) will be very spread out (particles less dense)
|
|
12
13
|
* - count: Number of particles. 100,000,000+ will crash the client. Try not to go over 100,000 (sincerely, minecraft clients)
|
|
13
14
|
*/
|
|
14
|
-
'emitParticle': (particle: any, world: any, position:
|
|
15
|
+
'emitParticle': (particle: any, world: any, position: Vec3, { whitelist, blacklist, radius, longDistance, size, count }?: {
|
|
15
16
|
whitelist?: any;
|
|
16
17
|
blacklist?: any[] | undefined;
|
|
17
18
|
radius?: number | undefined;
|
|
@@ -126,8 +126,9 @@ const server = function (serv, options) {
|
|
|
126
126
|
client.end('Server is still starting! Please wait before reconnecting.');
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
+
let player;
|
|
129
130
|
try {
|
|
130
|
-
|
|
131
|
+
player = serv.initEntity('player', null, serv.overworld, new vec3_1.Vec3(0, 0, 0));
|
|
131
132
|
Object.assign(player, assignProps);
|
|
132
133
|
Object.defineProperty(player, 'position', {
|
|
133
134
|
get() {
|
|
@@ -144,7 +145,8 @@ const server = function (serv, options) {
|
|
|
144
145
|
return player;
|
|
145
146
|
}
|
|
146
147
|
catch (err) {
|
|
147
|
-
|
|
148
|
+
serv.emit('error', err, { type: 'playerLogin', player: player });
|
|
149
|
+
client.end(`Internal server error during login phase: ${err.message}`);
|
|
148
150
|
}
|
|
149
151
|
};
|
|
150
152
|
serv._addPlayer = playerJoined;
|
|
@@ -23,7 +23,10 @@ const server = (serv) => {
|
|
|
23
23
|
exports.server = server;
|
|
24
24
|
const player = (player, serv, { basePositionAntiCheat = false, logToChatPositionAntiCheat = false }) => {
|
|
25
25
|
let lastMovementTime = Date.now();
|
|
26
|
-
let lastPosition
|
|
26
|
+
let lastPosition;
|
|
27
|
+
player.onReady.then(() => {
|
|
28
|
+
lastPosition = player.position.clone();
|
|
29
|
+
});
|
|
27
30
|
// Enforce safe areas on client-provided movement
|
|
28
31
|
player.on('move_cancel', ({ position, onGround, teleport }, cancel) => {
|
|
29
32
|
// Allow server teleports/moves to pass through
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
2
|
+
import { CustomWorld } from './world';
|
|
1
3
|
export declare const server: (serv: Server) => void;
|
|
2
4
|
export declare const player: (player: Player, serv: Server) => void;
|
|
3
5
|
export declare const entity: (entity: Entity, serv: Server) => void;
|
|
6
|
+
interface SavedSound {
|
|
7
|
+
soundName: string;
|
|
8
|
+
soundCategory: number;
|
|
9
|
+
}
|
|
10
|
+
interface PlaySoundOptions {
|
|
11
|
+
whitelist?: any;
|
|
12
|
+
blacklist?: any[];
|
|
13
|
+
radius?: number;
|
|
14
|
+
volume?: number;
|
|
15
|
+
pitch?: number;
|
|
16
|
+
soundCategory?: number;
|
|
17
|
+
/** Optional ID to save the sound for later stopping */
|
|
18
|
+
saveId?: string;
|
|
19
|
+
/** Custom options to be added to sound name in parentheses as JSON */
|
|
20
|
+
customClientOptions?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
interface PlayNoteBlockOptions {
|
|
23
|
+
instrument?: string;
|
|
24
|
+
particle?: boolean;
|
|
25
|
+
}
|
|
4
26
|
declare global {
|
|
27
|
+
interface Player {
|
|
28
|
+
/** Stores saved sounds by ID for later stopping */
|
|
29
|
+
savedSounds: Record<string, SavedSound>;
|
|
30
|
+
}
|
|
5
31
|
interface Server {
|
|
6
32
|
/** Plays `sound` (string, google "minecraft sound list") to all players in `opt.radius`.
|
|
7
33
|
* If position is null, will play at the location of every player (taking into account whitelist and blacklist).
|
|
@@ -12,27 +38,24 @@ declare global {
|
|
|
12
38
|
* - radius: Radius that sound can be heard (in fixed position so remember to multiply by 32, default 32*32)
|
|
13
39
|
* - volume: float from 0-1 (default 1.0)
|
|
14
40
|
* - pitch: float from 0.5 to 2 (default 1.0)
|
|
41
|
+
* - saveId: Optional ID to save the sound for later stopping
|
|
42
|
+
* - customClientOptions: Custom options to be added to sound name in parentheses as JSON
|
|
15
43
|
*/
|
|
16
|
-
'playSound': (sound:
|
|
17
|
-
whitelist?: any;
|
|
18
|
-
blacklist?: any[] | undefined;
|
|
19
|
-
radius?: number | undefined;
|
|
20
|
-
volume?: number | undefined;
|
|
21
|
-
pitch?: number | undefined;
|
|
22
|
-
soundCategory?: number | undefined;
|
|
23
|
-
}) => void;
|
|
44
|
+
'playSound': (sound: string, world: CustomWorld, position: Vec3 | null, opts?: PlaySoundOptions) => void;
|
|
24
45
|
/** Plays noteblock in world at position. `pitch` is from 0-24 */
|
|
25
|
-
"playNoteBlock": (pitch:
|
|
26
|
-
instrument?: string | undefined;
|
|
27
|
-
particle?: boolean | undefined;
|
|
28
|
-
}) => void;
|
|
46
|
+
"playNoteBlock": (pitch: number, world: CustomWorld, position: Vec3, opts?: PlayNoteBlockOptions) => void;
|
|
29
47
|
/** Get pitch. `note` should be between 0-24 and your output is from 0.5 to 2.0 */
|
|
30
|
-
"getNote": (note:
|
|
48
|
+
"getNote": (note: number) => number;
|
|
49
|
+
/** Stop a previously saved sound by its ID */
|
|
50
|
+
"stopSound": (soundId: string) => void;
|
|
31
51
|
}
|
|
32
52
|
interface Player {
|
|
33
53
|
/** Easy way to only play a sound for one player. Same opt as serv.playSound except no `whitelist`. */
|
|
34
|
-
"playSound": (sound:
|
|
54
|
+
"playSound": (sound: string, opt?: PlaySoundOptions) => void;
|
|
55
|
+
/** Stop a specific sound by ID or all sounds if no ID provided */
|
|
56
|
+
"stopSound": (soundId?: string) => void;
|
|
35
57
|
}
|
|
36
58
|
interface Entity {
|
|
37
59
|
}
|
|
38
60
|
}
|
|
61
|
+
export {};
|
|
@@ -4,21 +4,36 @@ exports.entity = exports.player = exports.server = void 0;
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const vec3_1 = require("vec3");
|
|
6
6
|
const server = function (serv) {
|
|
7
|
-
serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0 } = {}) => {
|
|
7
|
+
serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0, saveId, customClientOptions } = {}) => {
|
|
8
8
|
const players = (typeof whitelist !== 'undefined'
|
|
9
9
|
? (whitelist instanceof Array ? whitelist : [whitelist])
|
|
10
10
|
: serv.getNearby({
|
|
11
11
|
world,
|
|
12
|
-
position,
|
|
12
|
+
position: position,
|
|
13
13
|
radius
|
|
14
14
|
}));
|
|
15
|
+
// Add custom options to sound name if provided
|
|
16
|
+
let finalSoundName = sound;
|
|
17
|
+
if (customClientOptions) {
|
|
18
|
+
finalSoundName = `${sound}(${JSON.stringify(customClientOptions)})`;
|
|
19
|
+
}
|
|
20
|
+
// Save sound info if saveId provided for each player
|
|
21
|
+
if (saveId) {
|
|
22
|
+
const targetPlayers = players.filter(player => blacklist.indexOf(player) === -1);
|
|
23
|
+
targetPlayers.forEach(player => {
|
|
24
|
+
player.savedSounds[saveId] = {
|
|
25
|
+
soundName: sound,
|
|
26
|
+
soundCategory
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
15
30
|
players.filter(player => blacklist.indexOf(player) === -1)
|
|
16
31
|
.forEach(player => {
|
|
17
32
|
const iniPos = position ? position.scaled(1 / 32) : player.position.scaled(1 / 32);
|
|
18
33
|
const pos = iniPos.scaled(8).floored();
|
|
19
34
|
// only packet still in fixed position in all versions
|
|
20
35
|
player._client.write('named_sound_effect', {
|
|
21
|
-
soundName:
|
|
36
|
+
soundName: finalSoundName,
|
|
22
37
|
soundCategory,
|
|
23
38
|
x: pos.x,
|
|
24
39
|
y: pos.y,
|
|
@@ -38,6 +53,22 @@ const server = function (serv) {
|
|
|
38
53
|
serv.playSound('note.' + instrument, world, position, { pitch: serv.getNote(pitch) });
|
|
39
54
|
};
|
|
40
55
|
serv.getNote = note => 0.5 * Math.pow(Math.pow(2, 1 / 12), note);
|
|
56
|
+
serv.stopSound = (soundId, targetPlayers) => {
|
|
57
|
+
// If targetPlayers provided, stop sound only for them
|
|
58
|
+
// Otherwise stop for all players who have this sound saved
|
|
59
|
+
const players = targetPlayers || serv.players;
|
|
60
|
+
players.forEach(player => {
|
|
61
|
+
const soundInfo = player.savedSounds[soundId];
|
|
62
|
+
if (soundInfo) {
|
|
63
|
+
player._client.write('stop_sound', {
|
|
64
|
+
flags: 3, // Both source and sound
|
|
65
|
+
source: soundInfo.soundCategory,
|
|
66
|
+
sound: soundInfo.soundName
|
|
67
|
+
});
|
|
68
|
+
delete player.savedSounds[soundId];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
41
72
|
serv.commands.add({
|
|
42
73
|
base: 'playsoundforall',
|
|
43
74
|
info: 'to play sound for everyone',
|
|
@@ -83,9 +114,40 @@ const server = function (serv) {
|
|
|
83
114
|
};
|
|
84
115
|
exports.server = server;
|
|
85
116
|
const player = function (player, serv) {
|
|
117
|
+
// Initialize player's saved sounds storage
|
|
118
|
+
player.savedSounds = {};
|
|
86
119
|
player.playSound = (sound, opt = {}) => {
|
|
120
|
+
// If saveId is provided, store the sound in player's storage
|
|
121
|
+
if (opt.saveId) {
|
|
122
|
+
player.savedSounds[opt.saveId] = {
|
|
123
|
+
soundName: sound,
|
|
124
|
+
soundCategory: opt.soundCategory || 0
|
|
125
|
+
};
|
|
126
|
+
}
|
|
87
127
|
serv.playSound(sound, player.world, null, { ...opt, whitelist: player });
|
|
88
128
|
};
|
|
129
|
+
player.stopSound = (soundId) => {
|
|
130
|
+
if (soundId) {
|
|
131
|
+
// Stop specific sound if it exists in player's saved sounds
|
|
132
|
+
const soundInfo = player.savedSounds[soundId];
|
|
133
|
+
if (soundInfo) {
|
|
134
|
+
player._client.write('stop_sound', {
|
|
135
|
+
flags: 3, // Both source and sound
|
|
136
|
+
source: soundInfo.soundCategory,
|
|
137
|
+
sound: soundInfo.soundName
|
|
138
|
+
});
|
|
139
|
+
delete player.savedSounds[soundId];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// Stop all sounds
|
|
144
|
+
player._client.write('stop_sound', {
|
|
145
|
+
flags: 0 // Stop all sounds
|
|
146
|
+
});
|
|
147
|
+
// Clear saved sounds storage
|
|
148
|
+
player.savedSounds = {};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
89
151
|
// player.on('placeBlock_cancel', async ({ reference }, cancel) => {
|
|
90
152
|
// if (player.crouching) return
|
|
91
153
|
// const id = await player.world.getBlockType(reference)
|
package/dist/modules.d.ts
CHANGED