Class PacketUtil

java.lang.Object
me.desht.pneumaticcraft.common.network.PacketUtil

public class PacketUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends net.minecraft.world.level.block.entity.BlockEntity>
    Optional<T>
    getBlockEntity(net.minecraft.world.entity.player.Player player, Class<T> cls)
    static <T extends net.minecraft.world.level.block.entity.BlockEntity>
    Optional<T>
    getBlockEntity(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, Class<T> cls)
    Get the relevant target block entity for packet purposes.
    static net.minecraft.core.GlobalPos
    readGlobalPos(net.minecraft.network.FriendlyByteBuf buf)
     
    static net.minecraft.world.level.block.state.BlockState
    readNullableBlockState(net.minecraft.network.FriendlyByteBuf buf)
    Read a (possibly null) blockstate from the network
    static void
    writeGlobalPos(net.minecraft.network.FriendlyByteBuf buf, net.minecraft.core.GlobalPos gPos)
     
    static void
    writeNullableBlockState(net.minecraft.network.FriendlyByteBuf buf, net.minecraft.world.level.block.state.BlockState state)
    Write a blockstate, which may be null, to the network

    Methods inherited from class java.lang.Object

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

    • PacketUtil

      public PacketUtil()
  • Method Details

    • writeGlobalPos

      public static void writeGlobalPos(net.minecraft.network.FriendlyByteBuf buf, net.minecraft.core.GlobalPos gPos)
    • readGlobalPos

      public static net.minecraft.core.GlobalPos readGlobalPos(net.minecraft.network.FriendlyByteBuf buf)
    • getBlockEntity

      @Nonnull public static <T extends net.minecraft.world.level.block.entity.BlockEntity> Optional<T> getBlockEntity(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, Class<T> cls)
      Get the relevant target block entity for packet purposes. When the packet is being received on the server, the player's open container is used to determine the BE; don't trust a blockpos that the client sent, although we'll check the sent blockpos is the same as the BE's actual blockpos.

      Important: cannot be used to sync changes after the server-side container could be closed, i.e. don't use this in packets sent from a GUI onClose() method.

      Parameters:
      player - the player, will be null if packet is being received on client
      pos - the blockpos, ignored if packet is being received on server
      cls - the desired block entity class
      Returns:
      the relevant block entity, or Optional.empty() if none can be found
    • getBlockEntity

      @Nonnull public static <T extends net.minecraft.world.level.block.entity.BlockEntity> Optional<T> getBlockEntity(net.minecraft.world.entity.player.Player player, Class<T> cls)
      Parameters:
      player - the player
      cls - the desired block entity class
      Returns:
      the relevant block entity, or Optional.empty() if none can be found
    • writeNullableBlockState

      public static void writeNullableBlockState(net.minecraft.network.FriendlyByteBuf buf, @Nullable net.minecraft.world.level.block.state.BlockState state)
      Write a blockstate, which may be null, to the network
      Parameters:
      buf - the packet buffer
      state - the state to write
    • readNullableBlockState

      @Nullable public static net.minecraft.world.level.block.state.BlockState readNullableBlockState(net.minecraft.network.FriendlyByteBuf buf)
      Read a (possibly null) blockstate from the network
      Parameters:
      buf - the packet buffer
      Returns:
      the blockstate, may be null