Class PacketUtil
java.lang.Object
me.desht.pneumaticcraft.common.network.PacketUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends net.minecraft.world.level.block.entity.BlockEntity>
Optional<T>getBlockEntity(net.minecraft.world.entity.player.Player player, Class<T> cls) Server-only variant ofgetBlockEntity(Player, BlockPos, Class)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.GlobalPosreadGlobalPos(net.minecraft.network.FriendlyByteBuf buf) static net.minecraft.world.level.block.state.BlockStatereadNullableBlockState(net.minecraft.network.FriendlyByteBuf buf) Read a (possibly null) blockstate from the networkstatic voidwriteGlobalPos(net.minecraft.network.FriendlyByteBuf buf, net.minecraft.core.GlobalPos gPos) static voidwriteNullableBlockState(net.minecraft.network.FriendlyByteBuf buf, net.minecraft.world.level.block.state.BlockState state) Write a blockstate, which may be null, to the network
-
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 clientpos- the blockpos, ignored if packet is being received on servercls- 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) Server-only variant ofgetBlockEntity(Player, BlockPos, Class)- Parameters:
player- the playercls- 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 bufferstate- 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
-