2022-07-13 19:27:27 -05:00
|
|
|
package noppes.npcs.client.controllers;
|
|
|
|
|
|
2024-05-14 17:52:19 -05:00
|
|
|
import net.minecraft.client.Minecraft;
|
2022-07-13 19:27:27 -05:00
|
|
|
import net.minecraft.client.audio.ITickableSound;
|
|
|
|
|
import net.minecraft.client.audio.MovingSound;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import noppes.npcs.scripted.ScriptSound;
|
|
|
|
|
|
|
|
|
|
public class ScriptClientSound extends MovingSound implements ITickableSound {
|
2024-05-14 17:52:19 -05:00
|
|
|
public final String sound;
|
2022-07-13 19:27:27 -05:00
|
|
|
private Entity entity;
|
|
|
|
|
public boolean paused;
|
|
|
|
|
|
2024-05-14 17:52:19 -05:00
|
|
|
public ScriptClientSound(String sound) {
|
|
|
|
|
super(new ResourceLocation(sound));
|
|
|
|
|
this.sound = sound;
|
2022-07-13 19:27:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ScriptClientSound fromScriptSound(NBTTagCompound compound, World world) {
|
|
|
|
|
ScriptSound sound = ScriptSound.fromNBT(compound);
|
2024-05-14 17:52:19 -05:00
|
|
|
ScriptClientSound clientSound = new ScriptClientSound(sound.directory);
|
2022-07-13 19:27:27 -05:00
|
|
|
clientSound.xPosF = sound.xPosF;
|
|
|
|
|
clientSound.yPosF = sound.yPosF;
|
|
|
|
|
clientSound.zPosF = sound.zPosF;
|
|
|
|
|
clientSound.volume = sound.volume;
|
|
|
|
|
clientSound.field_147663_c = sound.pitch;
|
|
|
|
|
clientSound.repeat = sound.repeat;
|
|
|
|
|
clientSound.field_147665_h = sound.repeatDelay;
|
|
|
|
|
if (compound.hasKey("EntityID")) {
|
2024-05-14 17:52:19 -05:00
|
|
|
clientSound.setEntity(world.getEntityByID(compound.getInteger("EntityID")));
|
2022-07-13 19:27:27 -05:00
|
|
|
clientSound.field_147666_i = AttenuationType.NONE;
|
|
|
|
|
}
|
|
|
|
|
return clientSound;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-14 17:52:19 -05:00
|
|
|
public void setEntity(Entity entity) {
|
|
|
|
|
this.entity = entity;
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
this.xPosF = (float) (this.entity.posX);
|
|
|
|
|
this.yPosF = (float) (this.entity.posY);
|
|
|
|
|
this.zPosF = (float) (this.entity.posZ);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Entity getEntity() {
|
|
|
|
|
return this.entity;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 19:27:27 -05:00
|
|
|
public void stopSound() {
|
|
|
|
|
this.repeat = false;
|
|
|
|
|
this.volume = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update() {
|
|
|
|
|
if (entity != null) {
|
|
|
|
|
if (this.entity.isDead) {
|
|
|
|
|
this.donePlaying = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.xPosF = (float) (this.entity.posX);
|
|
|
|
|
this.yPosF = (float) (this.entity.posY);
|
|
|
|
|
this.zPosF = (float) (this.entity.posZ);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-14 17:52:19 -05:00
|
|
|
|
|
|
|
|
public void setPos(float x, float y, float z) {
|
|
|
|
|
this.xPosF = x;
|
|
|
|
|
this.yPosF = y;
|
|
|
|
|
this.zPosF = z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double getDistanceSq() {
|
|
|
|
|
return Minecraft.getMinecraft().thePlayer.getDistanceSq(this.xPosF, this.yPosF, this.zPosF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setVolume(float volume) {
|
|
|
|
|
this.volume = volume;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAttenuationType(AttenuationType attenuationType) {
|
|
|
|
|
this.field_147666_i = attenuationType;
|
|
|
|
|
}
|
2022-07-13 19:27:27 -05:00
|
|
|
}
|