Package etithespirit.orimod.client.audio
Class LoopingLightEnergyBlockSound
java.lang.Object
net.minecraft.client.resources.sounds.AbstractSoundInstance
net.minecraft.client.resources.sounds.AbstractTickableSoundInstance
etithespirit.orimod.client.audio.LoopingLightEnergyBlockSound
- All Implemented Interfaces:
net.minecraft.client.resources.sounds.SoundInstance
,net.minecraft.client.resources.sounds.TickableSoundInstance
public class LoopingLightEnergyBlockSound
extends net.minecraft.client.resources.sounds.AbstractTickableSoundInstance
This class serves as the housing for a Light tech device's ambient loop sound. It is intended for use where there is a startup, loop, and shutdown sound.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.minecraft.client.resources.sounds.SoundInstance
net.minecraft.client.resources.sounds.SoundInstance.Attenuation
-
Field Summary
FieldsModifier and TypeFieldDescriptionfloat
The baseline volume that is used when playing any of the sounds involved.final net.minecraft.world.level.block.entity.BlockEntity
The block this exists for.final ILightEnergyStorage
Identical toblock
with the exception that it is stored as anILightEnergyStorage
.double
Because some devices may gain and spend energy at different intervals, it is possible for start/stop calls to be spammed.protected boolean
Whether or not the startup sound has played.protected double
The last tracked ratio of energy.This action executes when the sound ends due to energy going from nonzero to zeroThis action executes when the sound begins due to energy going from zero to nonzeroThis action executes when the sound ends due to its removalboolean
If true, the startup action will be called when this instance is enqueued.protected float
The "warmth" of the audio is used for a brief fade-in period to make the transition from the start sound to the loop sound less jarring.Fields inherited from class net.minecraft.client.resources.sounds.AbstractSoundInstance
attenuation, delay, location, looping, pitch, random, relative, sound, source, volume, x, y, z
-
Constructor Summary
ConstructorsConstructorDescriptionLoopingLightEnergyBlockSound
(net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.sounds.SoundEvent loop) Create a new looping energy sound for the given block entity. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
protected double
getVolumeForDistance
(double maxDistance, double max) Returns the volume for the given distance via a linear falloff.void
reset()
Resets the audio data associated with this sound, intended for use once it has stopped for whatever reason.void
tick()
Methods inherited from class net.minecraft.client.resources.sounds.AbstractTickableSoundInstance
isStopped, stop
Methods inherited from class net.minecraft.client.resources.sounds.AbstractSoundInstance
getAttenuation, getDelay, getLocation, getPitch, getSound, getSource, getVolume, getX, getY, getZ, isLooping, isRelative, resolve, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.minecraft.client.resources.sounds.SoundInstance
getAttenuation, getDelay, getLocation, getPitch, getSound, getSource, getStream, getVolume, getX, getY, getZ, isLooping, isRelative, resolve
-
Field Details
-
block
public final net.minecraft.world.level.block.entity.BlockEntity blockThe block this exists for. -
energy
Identical toblock
with the exception that it is stored as anILightEnergyStorage
. -
onStartup
This action executes when the sound begins due to energy going from zero to nonzero -
onShutdown
This action executes when the sound ends due to energy going from nonzero to zero -
onTermination
This action executes when the sound ends due to its removal -
energyPercentThreshold
public double energyPercentThresholdBecause some devices may gain and spend energy at different intervals, it is possible for start/stop calls to be spammed. This value is a threshold for how full the energy device must be (as a percentage) to trigger a start/stop. -
baseVolume
public float baseVolumeThe baseline volume that is used when playing any of the sounds involved. -
playStartupOnLoad
public boolean playStartupOnLoadIf true, the startup action will be called when this instance is enqueued. -
lastRatio
protected double lastRatioThe last tracked ratio of energy. -
hasPlayedStartup
protected boolean hasPlayedStartupWhether or not the startup sound has played. -
warmth
protected float warmthThe "warmth" of the audio is used for a brief fade-in period to make the transition from the start sound to the loop sound less jarring.
-
-
Constructor Details
-
LoopingLightEnergyBlockSound
public LoopingLightEnergyBlockSound(net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.sounds.SoundEvent loop) throws IllegalArgumentException Create a new looping energy sound for the given block entity.- Parameters:
blockEntity
- The block entity to play for.loop
- The loop sound.- Throws:
IllegalArgumentException
- If the given input block entity does not implementILightEnergyStorage
-
-
Method Details
-
canPlaySound
public boolean canPlaySound() -
canStartSilent
public boolean canStartSilent() -
tick
public void tick() -
reset
public void reset()Resets the audio data associated with this sound, intended for use once it has stopped for whatever reason. -
getVolumeForDistance
protected double getVolumeForDistance(double maxDistance, double max) Returns the volume for the given distance via a linear falloff.- Parameters:
maxDistance
- The distance from which the volume will be 0.max
- The maximum volume (at distance=0)- Returns:
- A value between 0 and (max) based on the camera entity's distance.
-