Support sound basics

This commit is contained in:
DemiPixel 2015-11-02 19:04:09 -08:00
parent 20ff77bc1d
commit 2955c5bcfd
4 changed files with 54 additions and 0 deletions

View file

@ -273,6 +273,26 @@ function inject(serv, player) {
}
});
base.add({
base: 'playsound',
info: 'to play sound for yourself',
usage: '/playsound <sound_name> [volume] [pitch]',
parse(str) {
return str.match(/([^ ]+)(?: ([^ ]+))?(?: ([^ ]+))?/);
},
action(sound) {
if (!sound) {
player.chat('Usage: /playsound <sound_name> [volume] [pitch]');
return;
}
player.chat('Playing "'+sound[1]+'" (volume: ' + parseFloat((sound[2] || 1.0)) + ', pitch: ' + parseFloat((sound[3] || 1.0)) + ')');
player.playSound(sound[1], {
volume: parseFloat(sound[2]) || 1.0,
pitch: parseFloat(sound[3]) || 1.0
});
}
})
serv.commands = base;
player.handleCommand = (str) => {

View file

@ -9,6 +9,7 @@ function inject(serv,player)
var referencePosition=new vec3(location.x,location.y,location.z);
var directionVector=directionToVector[direction];
var placedPosition=referencePosition.plus(directionVector);
serv.playSound('random.click', player.world, placedPosition.clone().add(vec3(0.5, 0.5, 0.5)));
if(heldItem.blockId!=323){
player.changeBlock(placedPosition,heldItem.blockId,heldItem.itemDamage);
}else if(direction==1){

View file

@ -0,0 +1,9 @@
module.exports = inject;
function inject(serv, player) {
player.playSound = (sound, opt={}) => {
console.log(sound, opt);
opt.whitelist = player;
serv.playSound(sound, player.world, null, opt);
}
}

View file

@ -0,0 +1,24 @@
module.exports = inject;
function inject(serv) {
serv.playSound = (sound, world, position, {whitelist,blacklist=[],radius=32*32,volume=1.0,pitch=1.0}={}) => {
var players = (typeof whitelist != 'undefined' ? (typeof whitelist == 'array' ? whitelist : [whitelist]) : serv.getNearby({
world: world,
position: position.scaled(32).floored(),
radius: radius // 32 blocks, fixed position
}));
players.filter(player => blacklist.indexOf(player) == -1)
.forEach(player => {
var pos = (position || player.entity.position.scaled(1/32)).scaled(8).floored();
console.log('Data',sound, pos, volume, Math.round(pitch*63));
player._client.write('named_sound_effect', {
soundName: sound,
x: pos.x,
y: pos.y,
z: pos.z,
volume: volume,
pitch: Math.round(pitch*63)
});
});
}
}