package net.minecraft.network.protocol.game; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.PacketType; import net.minecraft.world.Difficulty; public class ServerboundChangeDifficultyPacket implements Packet { public static final StreamCodec STREAM_CODEC = Packet.codec( ServerboundChangeDifficultyPacket::write, ServerboundChangeDifficultyPacket::new ); private final Difficulty difficulty; public ServerboundChangeDifficultyPacket(Difficulty difficulty) { this.difficulty = difficulty; } private ServerboundChangeDifficultyPacket(FriendlyByteBuf buffer) { this.difficulty = Difficulty.byId(buffer.readUnsignedByte()); } /** * Writes the raw packet data to the data stream. */ private void write(FriendlyByteBuf buffer) { buffer.writeByte(this.difficulty.getId()); } @Override public PacketType type() { return GamePacketTypes.SERVERBOUND_CHANGE_DIFFICULTY; } /** * Passes this Packet on to the NetHandler for processing. */ public void handle(ServerGamePacketListener handler) { handler.handleChangeDifficulty(this); } public Difficulty getDifficulty() { return this.difficulty; } }