Last active
December 6, 2019 17:44
-
-
Save williambl/e3baaa76382a6c4aa251d33919f656bd to your computer and use it in GitHub Desktop.
MovingSound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A sound that follows an entity | |
* Up-to-date source: https://github.com/williambl/EssentialFeatures/blob/master/src/main/java/com/williambl/essentialfeatures/client/music/MovingSound.java | |
* @Author Willbl3pic | |
*/ | |
public class MovingSound extends TickableSound { | |
private final Entity entity; | |
private float distance = 0.0F; | |
public MovingSound(Entity entityIn, SoundEvent soundIn) { | |
super(soundIn, SoundCategory.NEUTRAL); | |
this.entity = entityIn; | |
this.repeat = false; | |
this.repeatDelay = 0; | |
this.volume = 1.0F; | |
} | |
public void tick() { | |
if (!this.entity.isAlive()) { | |
this.donePlaying = true; | |
} else { | |
this.x = (float) this.entity.posX; | |
this.y = (float) this.entity.posY; | |
this.z = (float) this.entity.posZ; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Play a moving sound | |
* Adapted from: https://github.com/williambl/EssentialFeatures/blob/e77a8cd31f80543c9210e9bfac2431d2b92a1cdf/src/main/java/com/williambl/essentialfeatures/client/DistHelper.java | |
* @Author Willbl3pic | |
*/ | |
public void playMovingSoundWithDisc(MusicDiscItem disc, PlayerEntity player) { | |
Minecraft.getInstance().getSoundHandler().play( | |
new MovingSound( | |
player, | |
disc.getSound() | |
) | |
); | |
} | |
/* | |
* Stop a moving sound | |
* Adapted from: https://github.com/williambl/EssentialFeatures/blob/e77a8cd31f80543c9210e9bfac2431d2b92a1cdf/src/main/java/com/williambl/essentialfeatures/client/DistHelper.java | |
* @Author Willbl3pic | |
*/ | |
public void stopMovingSound(MusicDisc disc) { | |
Minecraft.getInstance().getSoundHandler().stop(disc.getSound().getName(), SoundCategory.NEUTRAL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment