Add cool sounds, remove some debugging

This commit is contained in:
DemiPixel 2015-11-08 09:06:37 -08:00
parent 0684ff481f
commit cc072e2464
2 changed files with 16 additions and 9 deletions

View file

@ -1,5 +1,16 @@
var blocks=require("minecraft-data")(require("../version")).blocks;
var vec3 = require("vec3");
var materialToSound = {
undefined: 'stone',
'rock': 'stone',
'dirt': 'grass',
'plant': 'grass',
'wool': 'cloth',
'web': 'cloth',
'wood': 'wood'
}
module.exports=inject;
function inject(serv,player)
@ -11,7 +22,10 @@ function inject(serv,player)
var placedPosition=referencePosition.plus(directionVector);
player.world.getBlockType(referencePosition).then((id) => {
if([25].indexOf(id) != -1) return;
serv.playSound('random.click', player.world, placedPosition.clone().add(vec3(0.5, 0.5, 0.5)));
var sound = 'dig.' + (materialToSound[blocks[heldItem.blockId].material] || 'stone');
serv.playSound(sound, player.world, placedPosition.clone().add(vec3(0.5, 0.5, 0.5)), {
pitch: 0.8
});
if(heldItem.blockId!=323){
player.changeBlock(placedPosition,heldItem.blockId,heldItem.itemDamage);
}else if(direction==1){

View file

@ -44,9 +44,6 @@ function inject(serv) {
var yVec = entity.position.offset(0, entity.velocity.y*delta + sizeSigned.y/2, 0).scaled(1/32).floored();
var zVec = entity.position.offset(0, 0, entity.velocity.z*delta + sizeSigned.z/2).scaled(1/32).floored();
//console.log(xVec, yVec, zVec);
//console.log(entity.velocity);
// Get block for each (x/y/z)Vec, check to avoid duplicate getBlockTypes
var xBlock = blocks[await entity.world.getBlockType(xVec)].boundingBox == 'block';
var yBlock = yVec.equals(xVec) ? xBlock : blocks[await entity.world.getBlockType(yVec)].boundingBox == 'block';
@ -59,17 +56,13 @@ function inject(serv) {
entity.velocity.z = getFriction(entity.velocity.x, entity.friction.x, delta);
}
//console.log('afterfric',entity.velocity);
var oldPos = entity.position.clone();
entity.position.x += getMoveAmount('x', xBlock, entity, delta, sizeSigned.x);
entity.position.y += getMoveAmount('y', yBlock, entity, delta, sizeSigned.y);
entity.position.z += getMoveAmount('z', zBlock, entity, delta, sizeSigned.z);
//console.log(entity.position, old);
serv.emitParticle(30, serv.overworld, entity.position.scaled(1/32), { size: vec3(0, 0, 0) });
//serv.emitParticle(30, serv.overworld, entity.position.scaled(1/32), { size: vec3(0, 0, 0) });
return { oldPos: oldPos, onGround: yBlock}
}