@zardoy/flying-squid 0.0.126 → 0.0.128
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.
|
@@ -11,6 +11,28 @@ const materialToSound = {
|
|
|
11
11
|
web: 'cloth',
|
|
12
12
|
wood: 'wood'
|
|
13
13
|
};
|
|
14
|
+
/** sound group of a block for its place sound (1.8 materials, or the 1.13+ tool tags minecraft-data has as `material`) */
|
|
15
|
+
function soundGroupOf(block) {
|
|
16
|
+
const material = block.material ?? '';
|
|
17
|
+
if (materialToSound[material])
|
|
18
|
+
return materialToSound[material];
|
|
19
|
+
const { name } = block;
|
|
20
|
+
if (name.includes('glass'))
|
|
21
|
+
return 'glass';
|
|
22
|
+
if (name.includes('wool') || name.includes('carpet'))
|
|
23
|
+
return 'cloth';
|
|
24
|
+
if (name.includes('snow'))
|
|
25
|
+
return 'snow';
|
|
26
|
+
if (name.includes('sand'))
|
|
27
|
+
return 'sand';
|
|
28
|
+
if (material.includes('mineable/axe'))
|
|
29
|
+
return 'wood';
|
|
30
|
+
if (material.includes('leaves') || material.includes('plant') || name === 'grass_block' || name.endsWith('_grass'))
|
|
31
|
+
return 'grass';
|
|
32
|
+
if (material.includes('mineable/shovel'))
|
|
33
|
+
return 'gravel';
|
|
34
|
+
return 'stone';
|
|
35
|
+
}
|
|
14
36
|
const server = (serv, { version }) => {
|
|
15
37
|
const mcData = serv.mcData;
|
|
16
38
|
const itemPlaceHandlers = new Map();
|
|
@@ -216,7 +238,7 @@ const player = function (player, serv, { version }) {
|
|
|
216
238
|
return;
|
|
217
239
|
}
|
|
218
240
|
player.emit('blockPlaced', blocks[id]);
|
|
219
|
-
const sound = 'dig.' + (
|
|
241
|
+
const sound = 'dig.' + soundGroupOf(blocks[id]);
|
|
220
242
|
serv.playSound(sound, player.world, placedPosition.offset(0.5, 0.5, 0.5), {
|
|
221
243
|
pitch: 0.8
|
|
222
244
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Vec3 } from 'vec3';
|
|
2
2
|
import { CustomWorld } from './world';
|
|
3
|
+
/** `dig.stone` -> `block.stone.place`, `note.harp` -> `block.note_block.harp` (1.13+) / `block.note.harp`; resource names pass unchanged */
|
|
4
|
+
export declare function resourceSoundName(name: string, flattening: boolean): string;
|
|
3
5
|
export declare const server: (serv: Server) => void;
|
|
4
6
|
export declare const player: (player: Player, serv: Server) => void;
|
|
5
7
|
export declare const entity: (entity: Entity, serv: Server) => void;
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.entity = exports.player = exports.server = void 0;
|
|
4
|
+
exports.resourceSoundName = resourceSoundName;
|
|
4
5
|
const utils_1 = require("../utils");
|
|
5
6
|
const vec3_1 = require("vec3");
|
|
7
|
+
/** 1.8 sound names flying-squid uses, as resource names (1.9+) */
|
|
8
|
+
const LEGACY_SOUNDS = {
|
|
9
|
+
'random.pop': 'entity.item.pickup',
|
|
10
|
+
'game.player.hurt': 'entity.player.hurt',
|
|
11
|
+
'random.chestopen': 'block.chest.open',
|
|
12
|
+
'random.chestclosed': 'block.chest.close'
|
|
13
|
+
};
|
|
14
|
+
const DIG_GROUP = { cloth: 'wool', stone: 'stone', wood: 'wood', grass: 'grass', gravel: 'gravel', sand: 'sand', snow: 'snow', glass: 'glass' };
|
|
15
|
+
const NOTE_INSTRUMENT = { bd: 'basedrum', bassattack: 'bass' };
|
|
16
|
+
/** sound categories by number (1.19.3+ packets take the name) */
|
|
17
|
+
const SOUND_SOURCES = ['master', 'music', 'record', 'weather', 'block', 'hostile', 'neutral', 'player', 'ambient', 'voice'];
|
|
18
|
+
/** `dig.stone` -> `block.stone.place`, `note.harp` -> `block.note_block.harp` (1.13+) / `block.note.harp`; resource names pass unchanged */
|
|
19
|
+
function resourceSoundName(name, flattening) {
|
|
20
|
+
const legacy = LEGACY_SOUNDS[name];
|
|
21
|
+
if (legacy)
|
|
22
|
+
return legacy;
|
|
23
|
+
const dig = /^dig\.(\w+)$/.exec(name);
|
|
24
|
+
if (dig)
|
|
25
|
+
return `block.${DIG_GROUP[dig[1]] ?? 'stone'}.place`;
|
|
26
|
+
const note = /^note\.(\w+)$/.exec(name);
|
|
27
|
+
if (note)
|
|
28
|
+
return `block.${flattening ? 'note_block' : 'note'}.${NOTE_INSTRUMENT[note[1]] ?? note[1]}`;
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
6
31
|
const server = function (serv) {
|
|
32
|
+
// what the sound packets of this version look like (protocol schema of minecraft-data)
|
|
33
|
+
const toClient = serv.mcData?.protocol?.play?.toClient?.types ?? {};
|
|
34
|
+
const effectFields = toClient.packet_sound_effect?.[1] ?? [];
|
|
35
|
+
const namedFields = toClient.packet_named_sound_effect?.[1];
|
|
36
|
+
/** 1.19.3+: `sound` is an ItemSoundHolder ({ data: { soundName } } for a sound given by name) */
|
|
37
|
+
const soundHolder = effectFields.some(f => f.name === 'sound');
|
|
38
|
+
/** pitch is a float since 1.9 (a byte, pitch * 63, before) */
|
|
39
|
+
const floatPitch = (soundHolder ? effectFields : namedFields ?? effectFields).find(f => f.name === 'pitch')?.type === 'f32';
|
|
40
|
+
const resourceNames = serv.supportFeature('playsoundUsesResourceLocation');
|
|
41
|
+
const flattening = serv.supportFeature('theFlattening');
|
|
7
42
|
serv.playSound = (sound, world, position, { whitelist, blacklist = [], radius = 32, volume = 1.0, pitch = 1.0, soundCategory = 0, saveId, customClientOptions } = {}) => {
|
|
8
43
|
const players = (typeof whitelist !== 'undefined'
|
|
9
44
|
? (whitelist instanceof Array ? whitelist : [whitelist])
|
|
@@ -13,7 +48,7 @@ const server = function (serv) {
|
|
|
13
48
|
radius
|
|
14
49
|
}));
|
|
15
50
|
// Add custom options to sound name if provided
|
|
16
|
-
let finalSoundName = sound;
|
|
51
|
+
let finalSoundName = resourceNames ? resourceSoundName(sound, flattening) : sound;
|
|
17
52
|
if (customClientOptions) {
|
|
18
53
|
finalSoundName = `${sound}(${JSON.stringify(customClientOptions)})`;
|
|
19
54
|
}
|
|
@@ -29,21 +64,21 @@ const server = function (serv) {
|
|
|
29
64
|
}
|
|
30
65
|
players.filter(player => blacklist.indexOf(player) === -1)
|
|
31
66
|
.forEach(player => {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
67
|
+
// fixed point, 1/8 block (positions are in blocks; the old 1/32 scaling put every sound near 0 0 0)
|
|
68
|
+
const at = position ?? player.position;
|
|
69
|
+
const x = Math.floor(at.x * 8);
|
|
70
|
+
const y = Math.floor(at.y * 8);
|
|
71
|
+
const z = Math.floor(at.z * 8);
|
|
72
|
+
const packetPitch = floatPitch ? pitch : Math.round(pitch * 63);
|
|
73
|
+
if (soundHolder) {
|
|
35
74
|
player._client.write('sound_effect', {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
soundCategory,
|
|
42
|
-
x: pos.x,
|
|
43
|
-
y: pos.y,
|
|
44
|
-
z: pos.z,
|
|
75
|
+
sound: { data: { soundName: finalSoundName, fixedRange: undefined } },
|
|
76
|
+
soundCategory: typeof soundCategory === 'number' ? (SOUND_SOURCES[soundCategory] ?? 'master') : soundCategory,
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
z,
|
|
45
80
|
volume,
|
|
46
|
-
pitch:
|
|
81
|
+
pitch: packetPitch,
|
|
47
82
|
seed: 0
|
|
48
83
|
});
|
|
49
84
|
}
|
|
@@ -52,11 +87,11 @@ const server = function (serv) {
|
|
|
52
87
|
player._client.write('named_sound_effect', {
|
|
53
88
|
soundName: finalSoundName,
|
|
54
89
|
soundCategory,
|
|
55
|
-
x
|
|
56
|
-
y
|
|
57
|
-
z
|
|
90
|
+
x,
|
|
91
|
+
y,
|
|
92
|
+
z,
|
|
58
93
|
volume,
|
|
59
|
-
pitch:
|
|
94
|
+
pitch: packetPitch,
|
|
60
95
|
seed: 0
|
|
61
96
|
});
|
|
62
97
|
}
|
|
@@ -659,6 +659,26 @@ const player = function (player, serv, settings) {
|
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
661
|
};
|
|
662
|
+
/**
|
|
663
|
+
* Light arrays of the 1.18+ chunk packet in the vanilla byte order (nibbles, low nibble first). prismarine-chunk's dumpLight() writes every
|
|
664
|
+
* section with BitArray.writeBuffer (big-endian longs) while loadParsedLight() on the client reads vanilla bytes, so light reached the client
|
|
665
|
+
* scrambled inside every 16 cells along x (only 1/8 of the cells kept their value). The BitArray's Uint32Array already holds the vanilla layout
|
|
666
|
+
* on little-endian hosts: its bytes are copied as they are (also cheaper than the encoder).
|
|
667
|
+
*/
|
|
668
|
+
const LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
|
|
669
|
+
const packetLightArrays = (chunk, dumped) => {
|
|
670
|
+
if (!LITTLE_ENDIAN || !chunk.skyLightSections || !chunk.blockLightSections)
|
|
671
|
+
return { skyLight: dumped.skyLight, blockLight: dumped.blockLight };
|
|
672
|
+
const bytes = (sections, mask) => {
|
|
673
|
+
const out = [];
|
|
674
|
+
sections.forEach((section, index) => {
|
|
675
|
+
if (section !== null && mask.get(index))
|
|
676
|
+
out.push(new Uint8Array(section.data.buffer, section.data.byteOffset, section.data.byteLength).slice());
|
|
677
|
+
});
|
|
678
|
+
return out;
|
|
679
|
+
};
|
|
680
|
+
return { skyLight: bytes(chunk.skyLightSections, chunk.skyLightMask), blockLight: bytes(chunk.blockLightSections, chunk.blockLightMask) };
|
|
681
|
+
};
|
|
662
682
|
player.sendChunk = async (chunkX, chunkZ, column) => {
|
|
663
683
|
await player.behavior('sendChunk', {
|
|
664
684
|
x: chunkX,
|
|
@@ -668,7 +688,7 @@ const player = function (player, serv, settings) {
|
|
|
668
688
|
serv._finishPlayerChunkLoading(chunkX, chunkZ, player);
|
|
669
689
|
const newLightsFormat = serv.supportFeature('newLightingDataFormat');
|
|
670
690
|
const dumpedLights = chunk.dumpLight();
|
|
671
|
-
const newLightsData = newLightsFormat ?
|
|
691
|
+
const newLightsData = newLightsFormat ? packetLightArrays(chunk, dumpedLights) : undefined;
|
|
672
692
|
const chunkBuffer = chunk.dump();
|
|
673
693
|
const bitMap = chunk.getMask();
|
|
674
694
|
player._client.write('map_chunk', {
|