Class RadioRouter

java.lang.Object
com.codinglitch.simpleradio.radio.RadioRouter
All Implemented Interfaces:
Socket, Router
Direct Known Subclasses:
RadioListener, RadioReceiver, RadioSpeaker, RadioTransmitter

public class RadioRouter extends Object implements Socket, Router
Routes RadioSources to other routers.
  • Field Details

    • wires

      public List<Wiring> wires
    • routers

      public List<Router> routers
    • pending

      public Map<UUID,Queue<Message>> pending
    • routerAcceptor

      public Function<RadioMessage,Boolean> routerAcceptor
    • routeCriteria

      public BiPredicate<Message,Router> routeCriteria
    • acceptCriteria

      public Predicate<Message> acceptCriteria
    • active

      public boolean active
    • distributes

      public boolean distributes
    • valid

      public boolean valid
    • identifier

      public short identifier
    • reference

      public UUID reference
    • owner

      public net.minecraft.world.entity.Entity owner
    • position

      public WorldlyPosition position
    • activity

      public float activity
    • activityTime

      public int activityTime
    • compiledActivity

      public float compiledActivity
    • compiledSamples

      public int compiledSamples
    • rotation

      public org.joml.Quaternionf rotation
    • connectionOffset

      public net.minecraft.world.phys.Vec3 connectionOffset
  • Constructor Details

    • RadioRouter

      public RadioRouter(UUID reference)
    • RadioRouter

      public RadioRouter()
    • RadioRouter

      public RadioRouter(WorldlyPosition location)
    • RadioRouter

      public RadioRouter(WorldlyPosition location, UUID reference)
  • Method Details

    • getRouterFromReceivers

      @Nullable public static @Nullable Receiver getRouterFromReceivers(UUID reference)
    • getRouterFromTransmitters

      @Nullable public static @Nullable Transmitter getRouterFromTransmitters(UUID reference)
    • setRoutingCriteria

      public void setRoutingCriteria(BiPredicate<Message,Router> criteria)
      Specified by:
      setRoutingCriteria in interface Router
    • setAcceptingCriteria

      public void setAcceptingCriteria(Predicate<Message> criteria)
      Specified by:
      setAcceptingCriteria in interface Router
    • getRouter

      public RadioRouter getRouter()
      Description copied from interface: Socket
      Override this to expose a given router to wires.
      Allows blocks with more than one router to choose which of their routers wires will connect to.
      Specified by:
      getRouter in interface Socket
      Returns:
      The router to be exposed
    • getReference

      public UUID getReference()
      Description copied from interface: Router
      Retrieves the reference that refers to this router. This is not necessarily unique for each router, but will persist across reloads, and is the same across the server-client boundary.

      Routers that belong to the same purpose will share the same reference, but two unrelated routers will have a different reference. That is, a transceiver can have 4 different routers with the same reference differentiated by their class.
      Specified by:
      getReference in interface Router
      Specified by:
      getReference in interface Socket
      Returns:
      The reference of this router
    • getIdentifier

      public short getIdentifier()
      Description copied from interface: Router
      Retrieves the identifier that refers to this router. Identifiers are unique for every router, but are ephemeral, so they do not persist across reloads. You should not rely on this to be the same or stay the same.

      For a short-lived Message, this is used to keep a record of every router it has visited, to ensure that it cannot loop forever and cause a potential stack overflow or memory leak.
      Specified by:
      getIdentifier in interface Router
      Specified by:
      getIdentifier in interface Socket
      Returns:
      The identifier of this router
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface Router
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface Router
    • getConnectionOffset

      public net.minecraft.world.phys.Vec3 getConnectionOffset()
      Specified by:
      getConnectionOffset in interface Router
    • getLink

      public Class<?> getLink()
      Specified by:
      getLink in interface Router
    • getWires

      public List<Wiring> getWires()
      Specified by:
      getWires in interface Router
      Specified by:
      getWires in interface Socket
    • getDecoder

      public de.maxhenkel.voicechat.api.opus.OpusDecoder getDecoder(UUID sender)
    • getFrequency

      @Nullable public @Nullable Frequency getFrequency()
      Specified by:
      getFrequency in interface Router
    • isClientSide

      @Nullable public @Nullable Boolean isClientSide()
      Specified by:
      isClientSide in interface Router
    • getLocation

      public WorldlyPosition getLocation()
      Description copied from interface: Router
      Gets the effective location of this router. If position is provided, will use that, otherwise will infer the position from the entity owning this router.
      Specified by:
      getLocation in interface Router
    • getPosition

      @Nullable public @Nullable WorldlyPosition getPosition()
      Specified by:
      getPosition in interface Router
    • getOwner

      @Nullable public @Nullable net.minecraft.world.entity.Entity getOwner()
      Specified by:
      getOwner in interface Router
    • getRouter

      public Router getRouter(UUID id)
      Specified by:
      getRouter in interface Router
    • getRouters

      public List<Router> getRouters()
      Specified by:
      getRouters in interface Router
    • getConnectionPosition

      public net.minecraft.world.phys.Vec3 getConnectionPosition()
      Specified by:
      getConnectionPosition in interface Router
    • getPending

      public Map<UUID,Queue<Message>> getPending()
      Specified by:
      getPending in interface Router
    • getActivity

      public float getActivity()
      Specified by:
      getActivity in interface Router
    • getActivityTime

      public int getActivityTime()
      Specified by:
      getActivityTime in interface Router
    • getRedstoneMappedActivity

      public int getRedstoneMappedActivity()
      Specified by:
      getRedstoneMappedActivity in interface Router
    • getRotation

      public org.joml.Quaternionf getRotation()
      Specified by:
      getRotation in interface Router
    • allowDistribution

      public void allowDistribution()
      Description copied from interface: Router
      Marks that this router can distribute messages through wires.
      Specified by:
      allowDistribution in interface Router
    • setOwner

      public void setOwner(net.minecraft.world.entity.Entity owner)
      Specified by:
      setOwner in interface Router
    • setActive

      public void setActive(boolean active)
      Specified by:
      setActive in interface Router
    • setLink

      public void setLink(Class<?> link)
      Specified by:
      setLink in interface Router
    • setConnectionOffset

      public void setConnectionOffset(net.minecraft.world.phys.Vec3 connectionOffset)
      Specified by:
      setConnectionOffset in interface Router
    • setPosition

      public void setPosition(WorldlyPosition position)
      Specified by:
      setPosition in interface Router
    • setRotation

      public void setRotation(org.joml.Quaternionf rotation)
      Specified by:
      setRotation in interface Router
    • distanceTo

      public double distanceTo(Router other)
      Specified by:
      distanceTo in interface Router
    • distanceTo

      public double distanceTo(RadioRouter other)
    • tryAddRouter

      public Router tryAddRouter(Router router)
      Description copied from interface: Router
      Tries to link another router to this one if it doesn't already exist.
      Specified by:
      tryAddRouter in interface Router
    • tryAddRouter

      public Router tryAddRouter(RadioRouter router)
    • addRouter

      public Router addRouter(Router router)
      Description copied from interface: Router
      Links another router to this one.
      Specified by:
      addRouter in interface Router
    • accept

      public void accept(Message message)
      Description copied from interface: Router
      Accepts the message, notifying any integrations (such as CC:Tweaked) before taking the message.
      Specified by:
      accept in interface Router
      Parameters:
      message - The message to be accepted
    • dispatch

      public void dispatch()
      Description copied from interface: Router
      This method is called on the dispatcher thread, when every audio frame is meant to move at once. It is overridden by the speaker to stream audio data to clients.
      (Note that this is called after the router has received its message)
      Specified by:
      dispatch in interface Router
    • take

      public void take(Message message)
      Description copied from interface: Router
      Takes the message, and pushes it if this router is capable of doing so.
      Specified by:
      take in interface Router
      Parameters:
      message - The message to be taken
    • insert

      public void insert(Message message)
      Description copied from interface: Router
      Inserts a message into the buffer, where it will be extracted by the courier. This method does not make any checks and will forcefully insert the message.
      Specified by:
      insert in interface Router
      Parameters:
      message - The message to be inserted
    • push

      public void push(short[] audio)
      Description copied from interface: Router
      Pushes audio data into a separate buffer that dynamically splits it into the needed frame size. This method may leave leftover samples if the total amount is not a multiple of the frame size.
      Specified by:
      push in interface Router
      Parameters:
      audio - The PCM data to be pushed
    • extract

      public List<Message> extract()
    • send

      public void send(WorldlyPosition at, UUID sender, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> soundHolder, float volume, float pitch, long seed)
      Specified by:
      send in interface Router
    • send

      public void send(WorldlyPosition at, UUID sender, net.minecraft.core.Holder<net.minecraft.sounds.SoundEvent> soundHolder, float volume, float pitch, float offset, long seed)
      Specified by:
      send in interface Router
    • send

      public Message send(WorldlyPosition at, UUID sender, short[] data, float volume)
      Description copied from interface: Router
      Builds a Message and sends it to this router.
      Specified by:
      send in interface Router
      Parameters:
      at - The location to send it from.
      sender - The sender of the audio.
      data - The data to send, in raw PCM format.
      volume - The overall volume of the audio.
    • send

      public Message send(WorldlyPosition at, short[] data, float volume)
      Specified by:
      send in interface Router
    • send

      public Message send(UUID sender, short[] data, float volume)
      Specified by:
      send in interface Router
    • send

      public Message send(short[] data, float volume)
      Specified by:
      send in interface Router
    • send

      public Message send(WorldlyPosition at, UUID sender, byte[] data, float volume)
      Description copied from interface: Router
      Builds a Message and sends it to this router.
      Specified by:
      send in interface Router
      Parameters:
      at - The location to send it from.
      sender - The sender of the audio.
      data - The data to send, in Opus-encoded format.
      volume - The overall volume of the audio.
    • send

      public Message send(WorldlyPosition at, byte[] data, float volume)
      Specified by:
      send in interface Router
    • send

      public Message send(UUID sender, byte[] data, float volume)
      Specified by:
      send in interface Router
    • send

      public Message send(byte[] data, float volume)
      Specified by:
      send in interface Router
    • updateLocation

      public void updateLocation(WorldlyPosition location)
    • updateRotation

      public void updateRotation(org.joml.Quaternionf rotation)
    • tick

      public void tick(int tickCount)
    • prepareSource

      public RadioMessage prepareSource(RadioMessage message, RadioRouter destination)
    • shouldRouteTo

      public boolean shouldRouteTo(RadioMessage message, RadioRouter destination)
    • route

      public void route(Message message, @Nullable @Nullable Predicate<RadioRouter> criteria)
    • route

      public void route(Message message)
      Description copied from interface: Router
      Routes the given message to all the routers connected to this one.
      If the router allows distribution through wires, this will also relay it across those.
      Specified by:
      route in interface Router
      Parameters:
      message - The message to be routed
    • compileActivity

      public void compileActivity(Message message)
    • informActivity

      public void informActivity()
    • invalidate

      public void invalidate()
      Specified by:
      invalidate in interface Router
    • validate

      public boolean validate()
      Specified by:
      validate in interface Router
    • toString

      public String toString()
      Overrides:
      toString in class Object