42 lines
1.4 KiB
Java
42 lines
1.4 KiB
Java
package ru.octol1ttle.knockdowns.client.util;
|
|
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.audio.MovingSound;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.util.SoundCategory;
|
|
import net.minecraft.util.SoundEvent;
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public class DirectionalCallSound extends MovingSound {
|
|
private final @Nullable Entity entity;
|
|
private final Vec3d position;
|
|
private int time;
|
|
|
|
public DirectionalCallSound(SoundEvent event, @Nullable Entity entity, Vec3d position) {
|
|
super(event, SoundCategory.PLAYERS);
|
|
this.entity = entity;
|
|
this.position = position;
|
|
}
|
|
|
|
@Override
|
|
public void update() {
|
|
this.time++;
|
|
if (this.time > 40 || this.entity != null && this.entity.isDead) {
|
|
this.donePlaying = true;
|
|
return;
|
|
}
|
|
|
|
Minecraft client = Minecraft.getMinecraft();
|
|
Vec3d calloutPos = this.entity != null ? this.entity.getPositionVector() : this.position;
|
|
Vec3d directionVec = calloutPos.subtract(client.player.getPositionVector()).normalize();
|
|
Vec3d finalPos = client.player.getPositionVector().add(directionVec);
|
|
|
|
this.xPosF = (float) finalPos.x;
|
|
this.yPosF = (float) finalPos.y;
|
|
this.zPosF = (float) finalPos.z;
|
|
}
|
|
}
|