Class NetworkX

java.lang.Object
org.moddingx.libx.network.NetworkX

public abstract class NetworkX extends Object
A class implementing network logic. You can use the register methods in you constructor to register network packets.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canSend(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type)
    Checks whether a packet of a given type can currently be sent.
    boolean
    canSend(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type)
    Checks whether a packet of a given type can currently be sent to the given player.
    protected abstract String
    Gets the network version for this network.
    protected final <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
    void
    register(PacketHandler<T> handler)
    Registers a new packet handler to the system.
    protected final <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
    void
    Registers a new optional packet handler to the system.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NetworkX

      protected NetworkX(ModX mod)
  • Method Details

    • getVersion

      protected abstract String getVersion()
      Gets the network version for this network.
    • register

      protected final <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void register(PacketHandler<T> handler)
      Registers a new packet handler to the system. This should be called in the constructor.
    • registerOptional

      protected final <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void registerOptional(PacketHandler<T> handler)
      Registers a new optional packet handler to the system. An optional packet handler is not required to be present on the remote side for the connection negotiation to be successful. This should be called in the constructor.
    • canSend

      public boolean canSend(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type)
      Checks whether a packet of a given type can currently be sent. On the physical client this checks that the current connection supports the given packet type. On a dedicated server, this always returns true.
    • canSend

      public boolean canSend(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> type)
      Checks whether a packet of a given type can currently be sent to the given player. This check that the given players connection supports the given packet type.