use of io.xol.chunkstories.api.voxel.materials.VoxelMaterial in project chunkstories-core by Hugobros3.
the class EntityHumanoid method handleWalkingEtcSounds.
protected void handleWalkingEtcSounds() {
// This is strictly a clientside hack
if (!(getWorld() instanceof WorldClient))
return;
// When the entities are too far from the player, don't play any sounds
if (((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity() != null)
if (((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity().getLocation().distance(this.getLocation()) > 25f)
return;
// Sound stuff
if (isOnGround() && !lastTickOnGround) {
justLanded = true;
metersWalked = 0.0;
}
// Used to trigger landing sound
lastTickOnGround = this.isOnGround();
// Bobbing
Vector3d horizontalSpeed = new Vector3d(this.getVelocityComponent().getVelocity());
horizontalSpeed.y = 0d;
if (isOnGround())
metersWalked += Math.abs(horizontalSpeed.length());
boolean inWater = isInWater();
Voxel voxelStandingOn = world.peekSafely(new Vector3d(this.getLocation()).add(0.0, -0.01, 0.0)).getVoxel();
if (voxelStandingOn == null || !voxelStandingOn.getDefinition().isSolid() && !voxelStandingOn.getDefinition().isLiquid())
return;
VoxelMaterial material = voxelStandingOn.getMaterial();
if (justJumped && !inWater) {
justJumped = false;
getWorld().getSoundManager().playSoundEffect(material.resolveProperty("jumpingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
}
if (justLanded) {
justLanded = false;
getWorld().getSoundManager().playSoundEffect(material.resolveProperty("landingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
}
if (metersWalked > 0.2 * Math.PI * 2) {
metersWalked %= 0.2 * Math.PI * 2;
if (horizontalSpeed.length() <= 0.06)
getWorld().getSoundManager().playSoundEffect(material.resolveProperty("walkingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
else
getWorld().getSoundManager().playSoundEffect(material.resolveProperty("runningSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
}
}
Aggregations