Search in sources :

Example 11 with WorldClient

use of io.xol.chunkstories.api.world.WorldClient 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);
    }
}
Also used : Vector3d(org.joml.Vector3d) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) VoxelMaterial(io.xol.chunkstories.api.voxel.materials.VoxelMaterial) WorldClient(io.xol.chunkstories.api.world.WorldClient)

Aggregations

WorldClient (io.xol.chunkstories.api.world.WorldClient)11 Vector3d (org.joml.Vector3d)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)6 Location (io.xol.chunkstories.api.Location)4 Vector3dc (org.joml.Vector3dc)4 Entity (io.xol.chunkstories.api.entity.Entity)3 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 Controller (io.xol.chunkstories.api.entity.Controller)2 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)2 RemotePlayer (io.xol.chunkstories.api.server.RemotePlayer)2 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)2 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)1 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)1 EntityComponentRotation (io.xol.chunkstories.api.entity.components.EntityComponentRotation)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1 EntityFlying (io.xol.chunkstories.api.entity.interfaces.EntityFlying)1 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)1