Class NetworkChannel

java.lang.Object
com.ldtteam.structurize.network.NetworkChannel

public class NetworkChannel extends Object
Our wrapper for Forge network layer
  • Constructor Details

    • NetworkChannel

      public NetworkChannel(String channelName)
      Creates a new instance of network channel.
      Parameters:
      channelName - unique channel name
      Throws:
      IllegalArgumentException - if channelName already exists
  • Method Details

    • registerCommonMessages

      public void registerCommonMessages()
      Registers all common messages.
    • sendToServer

      public void sendToServer(IMessage msg)
      Sends to server.
      Parameters:
      msg - message to send
    • sendToPlayer

      public void sendToPlayer(IMessage msg, net.minecraft.server.level.ServerPlayer player)
      Sends to player.
      Parameters:
      msg - message to send
      player - target player
    • sendToOrigin

      public void sendToOrigin(IMessage msg, net.minecraftforge.network.NetworkEvent.Context ctx)
      Sends to origin client.
      Parameters:
      msg - message to send
      ctx - network context
    • sendToDimension

      public void sendToDimension(IMessage msg, net.minecraft.resources.ResourceKey<net.minecraft.world.level.Level> dim)
      Sends to everyone in dimension.
      Parameters:
      msg - message to send
      dim - target dimension
    • sendToPosition

      public void sendToPosition(IMessage msg, net.minecraftforge.network.PacketDistributor.TargetPoint pos)
      Sends to everyone in circle made using given target point.
      Parameters:
      msg - message to send
      pos - target position and radius
      See Also:
      • PacketDistributor.TargetPoint
    • sendToEveryone

      public void sendToEveryone(IMessage msg)
      Sends to everyone.
      Parameters:
      msg - message to send
    • sendToTrackingEntity

      public void sendToTrackingEntity(IMessage msg, net.minecraft.world.entity.Entity entity)
      Sends to everyone who is in range from entity's pos using formula below.
       Math.min(Entity.getType().getTrackingRange(), ChunkManager.this.viewDistance - 1) * 16;
       
      as of 24-06-2019
      Parameters:
      msg - message to send
      entity - target entity to look at
    • sendToTrackingEntityAndSelf

      public void sendToTrackingEntityAndSelf(IMessage msg, net.minecraft.world.entity.Entity entity)
      Sends to everyone (including given entity) who is in range from entity's pos using formula below.
       Math.min(Entity.getType().getTrackingRange(), ChunkManager.this.viewDistance - 1) * 16;
       
      as of 24-06-2019
      Parameters:
      msg - message to send
      entity - target entity to look at
    • sendToTrackingChunk

      public void sendToTrackingChunk(IMessage msg, net.minecraft.world.level.chunk.LevelChunk chunk)
      Sends to everyone in given chunk.
      Parameters:
      msg - message to send
      chunk - target chunk to look at
    • getMessageCache

      public com.google.common.cache.Cache<Integer,Map<Integer,byte[]>> getMessageCache()
      Gives access to the cache of messages that are being received.
      Returns:
      The message cache.
    • getMessagesTypes

      public Map<Integer,NetworkChannel.NetworkingMessageEntry<?>> getMessagesTypes()
      Gives access to the internal index codec.
      Returns:
      The internal index codec map.